Fix decoding attributes of SyntheticCoroutineBody

This commit is contained in:
Jonathan Brouwer
2026-07-26 12:58:08 +02:00
parent 5d4886964b
commit 8bf37cecf6

View File

@@ -1432,17 +1432,26 @@ impl CrateMetadata {
.attributes
.get(self, id)
.unwrap_or_else(|| {
// Structure and variant constructors don't have any attributes encoded for them,
// but we assume that someone passing a constructor ID actually wants to look at
// the attributes on the corresponding struct or variant.
let def_key = self.def_key(id);
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
let parent_id = def_key.parent.expect("no parent for a constructor");
self.root
.tables
.attributes
.get(self, parent_id)
.expect("no encoded attributes for a structure or variant")
match def_key.disambiguated_data.data {
DefPathData::Ctor => {
// Structure and variant constructors don't have any attributes encoded for them,
// but we assume that someone passing a constructor ID actually wants to look at
// the attributes on the corresponding struct or variant.
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
let parent_id = def_key.parent.expect("no parent for a constructor");
self.root
.tables
.attributes
.get(self, parent_id)
.expect("no encoded attributes for a structure or variant")
}
DefPathData::SyntheticCoroutineBody => {
// SyntheticCoroutineBodies cannot have attributes
LazyArray::default()
}
_ => panic!("Definition key {def_key:?} of type `{:?}` did not have any attributes stored", def_key.disambiguated_data.data)
}
})
.decode((self, tcx))
}