Skip to main content

rustc_interface/
proc_macro_decls.rs

1use rustc_hir::def_id::LocalDefId;
2use rustc_hir::find_attr;
3use rustc_middle::query::Providers;
4use rustc_middle::ty::TyCtxt;
5
6fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
7    let mut decls = None;
8
9    for id in tcx.hir_free_items() {
10        if {
        {
            'done:
                {
                for i in
                    ::rustc_hir::attrs::HasAttrs::get_attrs(id.hir_id(), &tcx) {
                    #[allow(unused_imports)]
                    use rustc_hir::attrs::AttributeKind::*;
                    let i: &rustc_hir::Attribute = i;
                    match i {
                        rustc_hir::Attribute::Parsed(RustcProcMacroDecls) => {
                            break 'done Some(());
                        }
                        rustc_hir::Attribute::Unparsed(..) =>
                            {}
                            #[deny(unreachable_patterns)]
                            _ => {}
                    }
                }
                None
            }
        }
    }.is_some()find_attr!(tcx, id.hir_id(), RustcProcMacroDecls) {
11            decls = Some(id.owner_id.def_id);
12        }
13    }
14
15    decls
16}
17
18pub(crate) fn provide(providers: &mut Providers) {
19    *providers = Providers { proc_macro_decls_static, ..*providers };
20}