Skip to content

Commit d01ec70

Browse files
Rollup merge of rust-lang#152577 - Ozzy1423:macro-attr, r=JonathanBrouwer
Port #[rustc_proc_macro_decls] to the new attribute parser. Tracking issue: rust-lang#131229 r? @JonathanBrouwer
2 parents f87ec09 + ab13120 commit d01ec70

6 files changed

Lines changed: 18 additions & 5 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,12 @@ impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
206206
Some(AttributeKind::CollapseDebugInfo(info))
207207
}
208208
}
209+
210+
pub(crate) struct RustcProcMacroDeclsParser;
211+
212+
impl<S: Stage> NoArgsAttributeParser<S> for RustcProcMacroDeclsParser {
213+
const PATH: &[Symbol] = &[sym::rustc_proc_macro_decls];
214+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
215+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Static)]);
216+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcProcMacroDecls;
217+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ attribute_parsers!(
300300
Single<WithoutArgs<RustcOutlivesParser>>,
301301
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
302302
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
303+
Single<WithoutArgs<RustcProcMacroDeclsParser>>,
303304
Single<WithoutArgs<RustcReallocatorParser>>,
304305
Single<WithoutArgs<RustcRegionsParser>>,
305306
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ pub enum AttributeKind {
12951295
/// Represents `#[rustc_preserve_ub_checks]`
12961296
RustcPreserveUbChecks,
12971297

1298+
/// Represents `#[rustc_proc_macro_decls]`
1299+
RustcProcMacroDecls,
1300+
12981301
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
12991302
RustcPubTransparent(Span),
13001303

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl AttributeKind {
158158
RustcPassByValue(..) => Yes,
159159
RustcPassIndirectlyInNonRusticAbis(..) => No,
160160
RustcPreserveUbChecks => No,
161+
RustcProcMacroDecls => No,
161162
RustcPubTransparent(..) => Yes,
162163
RustcReallocator => No,
163164
RustcRegions => No,

compiler/rustc_interface/src/proc_macro_decls.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
use rustc_ast::attr;
1+
use rustc_hir::attrs::AttributeKind;
22
use rustc_hir::def_id::LocalDefId;
3+
use rustc_hir::find_attr;
34
use rustc_middle::query::Providers;
45
use rustc_middle::ty::TyCtxt;
5-
use rustc_span::sym;
66

77
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
88
let mut decls = None;
99

1010
for id in tcx.hir_free_items() {
11-
let attrs = tcx.hir_attrs(id.hir_id());
12-
if attr::contains_name(attrs, sym::rustc_proc_macro_decls) {
11+
if find_attr!(tcx.hir_attrs(id.hir_id()), AttributeKind::RustcProcMacroDecls) {
1312
decls = Some(id.owner_id.def_id);
1413
}
1514
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
350350
| AttributeKind::RustcPassByValue (..)
351351
| AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
352352
| AttributeKind::RustcPreserveUbChecks
353+
| AttributeKind::RustcProcMacroDecls
353354
| AttributeKind::RustcReallocator
354355
| AttributeKind::RustcRegions
355356
| AttributeKind::RustcReservationImpl(..)
@@ -403,7 +404,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
403404
| sym::rustc_doc_primitive
404405
| sym::rustc_test_marker
405406
| sym::rustc_layout
406-
| sym::rustc_proc_macro_decls
407407
| sym::rustc_autodiff
408408
| sym::rustc_capture_analysis
409409
| sym::rustc_mir

0 commit comments

Comments
 (0)