Skip to content

Commit ab13120

Browse files
committed
Port #[rustc_proc_macro_decls] to the new attribute parser.
1 parent d7daac0 commit ab13120

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
@@ -297,6 +297,7 @@ attribute_parsers!(
297297
Single<WithoutArgs<RustcOutlivesParser>>,
298298
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
299299
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
300+
Single<WithoutArgs<RustcProcMacroDeclsParser>>,
300301
Single<WithoutArgs<RustcReallocatorParser>>,
301302
Single<WithoutArgs<RustcRegionsParser>>,
302303
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
@@ -1288,6 +1288,9 @@ pub enum AttributeKind {
12881288
/// Represents `#[rustc_preserve_ub_checks]`
12891289
RustcPreserveUbChecks,
12901290

1291+
/// Represents `#[rustc_proc_macro_decls]`
1292+
RustcProcMacroDecls,
1293+
12911294
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
12921295
RustcPubTransparent(Span),
12931296

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl AttributeKind {
156156
RustcPassByValue(..) => Yes,
157157
RustcPassIndirectlyInNonRusticAbis(..) => No,
158158
RustcPreserveUbChecks => No,
159+
RustcProcMacroDecls => No,
159160
RustcPubTransparent(..) => Yes,
160161
RustcReallocator => No,
161162
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
@@ -348,6 +348,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
348348
| AttributeKind::RustcPassByValue (..)
349349
| AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
350350
| AttributeKind::RustcPreserveUbChecks
351+
| AttributeKind::RustcProcMacroDecls
351352
| AttributeKind::RustcReallocator
352353
| AttributeKind::RustcRegions
353354
| AttributeKind::RustcReservationImpl(..)
@@ -406,7 +407,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
406407
| sym::rustc_doc_primitive
407408
| sym::rustc_test_marker
408409
| sym::rustc_layout
409-
| sym::rustc_proc_macro_decls
410410
| sym::rustc_autodiff
411411
| sym::rustc_capture_analysis
412412
| sym::rustc_mir

0 commit comments

Comments
 (0)