Skip to content

Commit 9af7dca

Browse files
committed
Port #![profiler_runtime] to the attribute parser.
1 parent 1ced9e3 commit 9af7dca

6 files changed

Lines changed: 18 additions & 4 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for NeedsPanicRuntimeParser {
202202
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
203203
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NeedsPanicRuntime;
204204
}
205+
206+
pub(crate) struct ProfilerRuntimeParser;
207+
208+
impl<S: Stage> NoArgsAttributeParser<S> for ProfilerRuntimeParser {
209+
const PATH: &[Symbol] = &[sym::profiler_runtime];
210+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
211+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
212+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProfilerRuntime;
213+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use crate::attributes::codegen_attrs::{
2828
};
2929
use crate::attributes::confusables::ConfusablesParser;
3030
use crate::attributes::crate_level::{
31-
CrateNameParser, MoveSizeLimitParser, NeedsPanicRuntimeParser, NoCoreParser, NoMainParser,
32-
NoStdParser, PanicRuntimeParser, PatternComplexityLimitParser, RecursionLimitParser,
31+
CrateNameParser, MoveSizeLimitParser, NeedsPanicRuntimeParser, NoCoreParser, NoMainParser, NoStdParser,
32+
PanicRuntimeParser, PatternComplexityLimitParser, ProfilerRuntimeParser, RecursionLimitParser,
3333
RustcCoherenceIsCoreParser, TypeLengthLimitParser, WindowsSubsystemParser,
3434
};
3535
use crate::attributes::debugger::DebuggerViualizerParser;
@@ -282,6 +282,7 @@ attribute_parsers!(
282282
Single<WithoutArgs<PointeeParser>>,
283283
Single<WithoutArgs<ProcMacroAttributeParser>>,
284284
Single<WithoutArgs<ProcMacroParser>>,
285+
Single<WithoutArgs<ProfilerRuntimeParser>>,
285286
Single<WithoutArgs<PubTransparentParser>>,
286287
Single<WithoutArgs<RustcAllocatorParser>>,
287288
Single<WithoutArgs<RustcAllocatorZeroedParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,9 @@ pub enum AttributeKind {
909909
/// Represents `#[proc_macro_derive]`
910910
ProcMacroDerive { trait_name: Symbol, helper_attrs: ThinVec<Symbol>, span: Span },
911911

912+
/// Represents `#[profiler_runtime]`
913+
ProfilerRuntime,
914+
912915
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
913916
PubTransparent(Span),
914917

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl AttributeKind {
9898
ProcMacro(..) => No,
9999
ProcMacroAttribute(..) => No,
100100
ProcMacroDerive { .. } => No,
101+
ProfilerRuntime => No,
101102
PubTransparent(..) => Yes,
102103
RecursionLimit { .. } => No,
103104
Repr { .. } => No,

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
746746
needs_panic_runtime: find_attr!(attrs, AttributeKind::NeedsPanicRuntime),
747747
no_builtins: ast::attr::contains_name(attrs, sym::no_builtins),
748748
panic_runtime: find_attr!(attrs, AttributeKind::PanicRuntime),
749-
profiler_runtime: ast::attr::contains_name(attrs, sym::profiler_runtime),
749+
profiler_runtime: find_attr!(attrs, AttributeKind::ProfilerRuntime),
750750
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
751751

752752
crate_deps,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
325325
| AttributeKind::CompilerBuiltins
326326
| AttributeKind::PanicRuntime
327327
| AttributeKind::NeedsPanicRuntime
328+
| AttributeKind::ProfilerRuntime
328329
) => { /* do nothing */ }
329330
Attribute::Unparsed(attr_item) => {
330331
style = Some(attr_item.style);
@@ -402,7 +403,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
402403
| sym::reexport_test_harness_main
403404
| sym::no_builtins
404405
| sym::crate_type
405-
| sym::profiler_runtime
406406
| sym::rustc_preserve_ub_checks,
407407
..
408408
] => {}

0 commit comments

Comments
 (0)