Files
rust/compiler/rustc_interface/src/proc_macro_decls.rs
T
randomicon00 858b82da3b 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.
2026-03-11 20:31:34 -04:00

21 lines
530 B
Rust

use rustc_hir::def_id::LocalDefId;
use rustc_hir::find_attr;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
let mut decls = None;
for id in tcx.hir_free_items() {
if find_attr!(tcx, id.hir_id(), RustcProcMacroDecls) {
decls = Some(id.owner_id.def_id);
}
}
decls
}
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { proc_macro_decls_static, ..*providers };
}