Skip to content

Commit 8bb7fdb

Browse files
committed
NoArgsAttributeParser: use an assoc const instead
1 parent 187babc commit 8bb7fdb

File tree

6 files changed

+11
-38
lines changed

6 files changed

+11
-38
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ pub(crate) struct ColdParser;
4949
impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
5050
const PATH: &[Symbol] = &[sym::cold];
5151
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
52-
53-
fn create(span: Span) -> AttributeKind {
54-
AttributeKind::Cold(span)
55-
}
52+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
5653
}
5754

5855
pub(crate) struct ExportNameParser;
@@ -193,20 +190,14 @@ pub(crate) struct TrackCallerParser;
193190
impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
194191
const PATH: &[Symbol] = &[sym::track_caller];
195192
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
196-
197-
fn create(span: Span) -> AttributeKind {
198-
AttributeKind::TrackCaller(span)
199-
}
193+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TrackCaller;
200194
}
201195

202196
pub(crate) struct NoMangleParser;
203197
impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
204198
const PATH: &[Symbol] = &[sym::no_mangle];
205199
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
206-
207-
fn create(span: Span) -> AttributeKind {
208-
AttributeKind::NoMangle(span)
209-
}
200+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
210201
}
211202

212203
#[derive(Default)]

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ pub(crate) struct AsPtrParser;
88
impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
99
const PATH: &[Symbol] = &[sym::rustc_as_ptr];
1010
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
11-
12-
fn create(span: Span) -> AttributeKind {
13-
AttributeKind::AsPtr(span)
14-
}
11+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AsPtr;
1512
}
1613

1714
pub(crate) struct PubTransparentParser;
1815
impl<S: Stage> NoArgsAttributeParser<S> for PubTransparentParser {
1916
const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
2017
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
21-
22-
fn create(span: Span) -> AttributeKind {
23-
AttributeKind::PubTransparent(span)
24-
}
18+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PubTransparent;
2519
}

compiler/rustc_attr_parsing/src/attributes/loop_match.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ pub(crate) struct LoopMatchParser;
88
impl<S: Stage> NoArgsAttributeParser<S> for LoopMatchParser {
99
const PATH: &[Symbol] = &[sym::loop_match];
1010
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
11-
12-
fn create(span: Span) -> AttributeKind {
13-
AttributeKind::LoopMatch(span)
14-
}
11+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::LoopMatch;
1512
}
1613

1714
pub(crate) struct ConstContinueParser;
1815
impl<S: Stage> NoArgsAttributeParser<S> for ConstContinueParser {
1916
const PATH: &[Symbol] = &[sym::const_continue];
2017
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
21-
22-
fn create(span: Span) -> AttributeKind {
23-
AttributeKind::ConstContinue(span)
24-
}
18+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ConstContinue;
2519
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub(crate) trait NoArgsAttributeParser<S: Stage>: 'static {
238238
const ON_DUPLICATE: OnDuplicate<S>;
239239

240240
/// Create the [`AttributeKind`] given attribute's [`Span`].
241-
fn create(span: Span) -> AttributeKind;
241+
const CREATE: fn(Span) -> AttributeKind;
242242
}
243243

244244
pub(crate) struct WithoutArgs<T: NoArgsAttributeParser<S>, S: Stage>(PhantomData<(S, T)>);
@@ -259,7 +259,7 @@ impl<T: NoArgsAttributeParser<S>, S: Stage> SingleAttributeParser<S> for Without
259259
if let Err(span) = args.no_args() {
260260
cx.expected_no_args(span);
261261
}
262-
Some(T::create(cx.attr_span))
262+
Some(T::CREATE(cx.attr_span))
263263
}
264264
}
265265

compiler/rustc_attr_parsing/src/attributes/semantics.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ pub(crate) struct MayDangleParser;
88
impl<S: Stage> NoArgsAttributeParser<S> for MayDangleParser {
99
const PATH: &[Symbol] = &[sym::may_dangle];
1010
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
11-
12-
fn create(span: Span) -> AttributeKind {
13-
AttributeKind::MayDangle(span)
14-
}
11+
const CREATE: fn(span: Span) -> AttributeKind = AttributeKind::MayDangle;
1512
}

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ pub(crate) struct ConstStabilityIndirectParser;
136136
impl<S: Stage> NoArgsAttributeParser<S> for ConstStabilityIndirectParser {
137137
const PATH: &[Symbol] = &[sym::rustc_const_stable_indirect];
138138
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
139-
140-
fn create(_: Span) -> AttributeKind {
141-
AttributeKind::ConstStabilityIndirect
142-
}
139+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ConstStabilityIndirect;
143140
}
144141

145142
#[derive(Default)]

0 commit comments

Comments
 (0)