Simplify find_attr! for HirId usage

Add a HasAttrs<'tcx, Tcx> trait to rustc_hir that allows find_attr! to
accept DefId, LocalDefId, OwnerId, and HirId directly, instead of
requiring callers to manually fetch the attribute slice first.

The trait is defined in rustc_hir with a generic Tcx parameter to avoid
a dependency cycle (rustc_hir cannot depend on rustc_middle). The four
concrete impls for TyCtxt are in rustc_middle.
This commit is contained in:
randomicon00
2026-03-08 22:37:03 -04:00
parent b41f22de2a
commit 858b82da3b
13 changed files with 67 additions and 25 deletions
@@ -7,7 +7,7 @@ fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
let mut decls = None;
for id in tcx.hir_free_items() {
if find_attr!(tcx.hir_attrs(id.hir_id()), RustcProcMacroDecls) {
if find_attr!(tcx, id.hir_id(), RustcProcMacroDecls) {
decls = Some(id.owner_id.def_id);
}
}