Rollup merge of #100658 - chenyukang:100631-check-get-attr, r=lcnr

TyCtxt::get_attr should check that no duplicates are allowed

Fixes #100631
This commit is contained in:
Dylan DPC
2022-09-06 16:34:41 +05:30
committed by GitHub
7 changed files with 38 additions and 5 deletions

View File

@@ -2269,7 +2269,11 @@ impl<'tcx> TyCtxt<'tcx> {
}
pub fn get_attr(self, did: DefId, attr: Symbol) -> Option<&'tcx ast::Attribute> {
self.get_attrs(did, attr).next()
if cfg!(debug_assertions) && !rustc_feature::is_valid_for_get_attr(attr) {
bug!("get_attr: unexpected called with DefId `{:?}`, attr `{:?}`", did, attr);
} else {
self.get_attrs(did, attr).next()
}
}
/// Determines whether an item is annotated with an attribute.