summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_interface/src/proc_macro_decls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_interface/src/proc_macro_decls.rs')
-rw-r--r--compiler/rustc_interface/src/proc_macro_decls.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/compiler/rustc_interface/src/proc_macro_decls.rs b/compiler/rustc_interface/src/proc_macro_decls.rs
new file mode 100644
index 000000000..5371c513d
--- /dev/null
+++ b/compiler/rustc_interface/src/proc_macro_decls.rs
@@ -0,0 +1,27 @@
+use rustc_hir as hir;
+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.def_id);
+ }
+ }
+
+ finder.decls
+}
+
+struct Finder<'tcx> {
+ tcx: TyCtxt<'tcx>,
+ decls: Option<hir::def_id::LocalDefId>,
+}
+
+pub(crate) fn provide(providers: &mut Providers) {
+ *providers = Providers { proc_macro_decls_static, ..*providers };
+}