c8c25ce5a1
spastorino noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone.
27 lines
724 B
Rust
27 lines
724 B
Rust
use rustc_hir::def_id::LocalDefId;
|
|
use rustc_middle::ty::query::Providers;
|
|
use rustc_middle::ty::TyCtxt;
|
|
use rustc_span::symbol::sym;
|
|
|
|
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
|
|
let mut finder = Finder { tcx, decls: None };
|
|
|
|
for id in tcx.hir().items() {
|
|
let attrs = finder.tcx.hir().attrs(id.hir_id());
|
|
if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
|
|
finder.decls = Some(id.owner_id.def_id);
|
|
}
|
|
}
|
|
|
|
finder.decls
|
|
}
|
|
|
|
struct Finder<'tcx> {
|
|
tcx: TyCtxt<'tcx>,
|
|
decls: Option<LocalDefId>,
|
|
}
|
|
|
|
pub(crate) fn provide(providers: &mut Providers) {
|
|
*providers = Providers { proc_macro_decls_static, ..*providers };
|
|
}
|