From 6d800f1e68c7d65b3538a98130455b589519487c Mon Sep 17 00:00:00 2001 From: Mohammad Omidvar Date: Wed, 24 Jul 2024 20:16:59 +0000 Subject: [PATCH] Return an empty list when item is not present in attributes table --- compiler/rustc_metadata/src/rmeta/decoder.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index e5e430bc90dcd..b62a62e7581cd 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1397,19 +1397,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { .tables .attributes .get(self, id) - .unwrap_or_else(|| { + .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") + if 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) + } else { + None + } }) + .unwrap_or_default() .decode((self, sess)) }