mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 04:55:22 +03:00
858b82da3b
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.
21 lines
530 B
Rust
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 };
|
|
}
|