Skip to content

Commit 1a525ab

Browse files
Wip
1 parent 77968ca commit 1a525ab

25 files changed

+135
-104
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use rustc_hir::{MethodKind, Target};
66
use rustc_span::{Span, Symbol, sym};
77

88
use super::{CombineAttributeParser, ConvertFn};
9-
use crate::context::{AcceptContext, Stage};
9+
use crate::context::{AcceptContext, AllowedTargets, Stage};
10+
use crate::context::MaybeWarn::Allow;
1011
use crate::parser::ArgParser;
1112
use crate::session_diagnostics;
1213

@@ -18,7 +19,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1819
|items, span| AttributeKind::AllowInternalUnstable(items, span);
1920
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
2021
Allow(Target::MacroDef),
21-
Target::Fn, //TODO if proc macro
22+
Allow(Target::Fn), //TODO if proc macro
2223
]);
2324
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
2425

@@ -37,7 +38,8 @@ impl<S: Stage> CombineAttributeParser<S> for UnstableFeatureBoundParser {
3738
const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound];
3839
type Item = (Symbol, Span);
3940
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::UnstableFeatureBound(items);
40-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn), Target::Impl {of_trait: true}]);
41+
const ALLOWED_TARGETS: AllowedTargets =
42+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::Impl { of_trait: true })]);
4143
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
4244

4345
fn extend<'c>(

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ use rustc_hir::attrs::{AttributeKind, CoverageAttrKind, OptimizeAttr, UsedBy};
33
use rustc_hir::{MethodKind, Target};
44
use rustc_session::parse::feature_err;
55
use rustc_span::{Span, Symbol, sym};
6-
use crate::context::AllowedTargets;
7-
use crate::context::MaybeWarn::Allow;
6+
87
use super::{
98
AcceptMapping, AttributeOrder, AttributeParser, CombineAttributeParser, ConvertFn,
109
NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
1110
};
12-
use crate::context::{AcceptContext, FinalizeContext, Stage};
13-
use crate::context::AllowedTargets;
1411
use crate::context::MaybeWarn::Allow;
12+
use crate::context::{
13+
AcceptContext, AllowedTargets, FinalizeContext, Stage,
14+
};
1515
use crate::parser::ArgParser;
1616
use crate::session_diagnostics::{NakedFunctionIncompatibleAttribute, NullOnExport};
17-
use crate::context::AllowedTargets;
18-
use crate::context::MaybeWarn::Allow;
1917

2018
pub(crate) struct OptimizeParser;
2119

@@ -83,9 +81,9 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
8381
Allow(Target::Closure),
8482
Allow(Target::Method(MethodKind::Trait { body: true })),
8583
Allow(Target::Method(MethodKind::Inherent)),
86-
Target::Impl { of_trait: true },
87-
Target::Impl { of_trait: false },
88-
Target::Mod,
84+
Allow(Target::Impl { of_trait: true }),
85+
Allow(Target::Impl { of_trait: false }),
86+
Allow(Target::Mod),
8987
]);
9088
const TEMPLATE: AttributeTemplate = template!(OneOf: &[sym::off, sym::on]);
9189

@@ -126,8 +124,12 @@ impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
126124
const PATH: &[rustc_span::Symbol] = &[sym::export_name];
127125
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
128126
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
129-
const ALLOWED_TARGETS: AllowedTargets =
130-
&[Target::Static, Target::Fn, Target::Method(MethodKind::Inherent), Target::Method(MethodKind::Trait { body: true })];
127+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
128+
Allow(Target::Static),
129+
Allow(Target::Fn),
130+
Allow(Target::Method(MethodKind::Inherent)),
131+
Allow(Target::Method(MethodKind::Trait { body: true })),
132+
]);
131133
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
132134

133135
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
@@ -170,9 +172,9 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
170172
}
171173
})];
172174
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
173-
Target::Fn,
174-
Target::Method(MethodKind::Inherent),
175-
Target::Method(MethodKind::Trait { body: true }),
175+
Allow(Target::Fn),
176+
Allow(Target::Method(MethodKind::Inherent)),
177+
Allow(Target::Method(MethodKind::Trait { body: true })),
176178
]);
177179

178180
fn finalize(self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
@@ -267,12 +269,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
267269
const PATH: &[Symbol] = &[sym::track_caller];
268270
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
269271
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
270-
Target::Fn,
271-
Target::Method(MethodKind::Inherent),
272-
Target::Method(MethodKind::Trait { body: true }),
273-
Target::Method(MethodKind::Trait { body: false }),
274-
Target::ForeignFn,
275-
Target::Closure,
272+
Allow(Target::Fn),
273+
Allow(Target::Method(MethodKind::Inherent)),
274+
Allow(Target::Method(MethodKind::Trait { body: true })),
275+
Allow(Target::Method(MethodKind::Trait { body: false })),
276+
Allow(Target::ForeignFn),
277+
Allow(Target::Closure),
276278
]);
277279
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TrackCaller;
278280
}
@@ -281,7 +283,12 @@ pub(crate) struct NoMangleParser;
281283
impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
282284
const PATH: &[Symbol] = &[sym::no_mangle];
283285
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
284-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Target::Fn, Target::Static, Target::Method(MethodKind::Inherent), Target::Method(MethodKind::Trait {body: true})]);
286+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
287+
Allow(Target::Fn),
288+
Allow(Target::Static),
289+
Allow(Target::Method(MethodKind::Inherent)),
290+
Allow(Target::Method(MethodKind::Trait { body: true })),
291+
]);
285292
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
286293
}
287294

@@ -420,5 +427,8 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
420427
features
421428
}
422429

423-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Target::Fn, Target::Method(MethodKind::Inherent)]);
430+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
431+
Allow(Target::Fn),
432+
Allow(Target::Method(MethodKind::Inherent)),
433+
]);
424434
}

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use rustc_span::{Span, Symbol, sym};
55
use thin_vec::ThinVec;
66

77
use super::{AcceptMapping, AttributeParser};
8-
use crate::context::{FinalizeContext, Stage};
9-
use crate::session_diagnostics;
10-
use crate::context::AllowedTargets;
118
use crate::context::MaybeWarn::Allow;
9+
use crate::context::{AllowedTargets, FinalizeContext, Stage};
10+
use crate::session_diagnostics;
1211
#[derive(Default)]
1312
pub(crate) struct ConfusablesParser {
1413
confusables: ThinVec<Symbol>,
@@ -43,7 +42,8 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
4342
this.first_span.get_or_insert(cx.attr_span);
4443
},
4544
)];
46-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Target::Method(MethodKind::Inherent)]);
45+
const ALLOWED_TARGETS: AllowedTargets =
46+
AllowedTargets::AllowList(&[Allow(Target::Method(MethodKind::Inherent))]);
4747

4848
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
4949
if self.confusables.is_empty() {

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ use rustc_span::{Span, Symbol, sym};
55

66
use super::util::parse_version;
77
use super::{AttributeOrder, OnDuplicate, SingleAttributeParser};
8-
use crate::context::{AcceptContext, Stage};
8+
use crate::context::MaybeWarn::Allow;
9+
use crate::context::{AcceptContext, AllowedTargets, Stage};
910
use crate::parser::ArgParser;
1011
use crate::session_diagnostics;
11-
use crate::context::AllowedTargets;
12-
use crate::context::MaybeWarn::Allow;
1312
pub(crate) struct DeprecationParser;
1413

1514
fn get<S: Stage>(
@@ -56,7 +55,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5655
Allow(Target::Field),
5756
Allow(Target::Trait),
5857
Allow(Target::AssocTy),
59-
Target::Variant
58+
Allow(Target::Variant),
6059
]);
6160
const TEMPLATE: AttributeTemplate = template!(
6261
Word,

compiler/rustc_attr_parsing/src/attributes/dummy.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use rustc_hir::attrs::AttributeKind;
33
use rustc_span::{Symbol, sym};
44

55
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
6-
use crate::context::{AcceptContext, Stage};
6+
use crate::context::{AcceptContext, AllowedTargets, Stage};
77
use crate::parser::ArgParser;
8-
use crate::context::AllowedTargets;
98
pub(crate) struct DummyParser;
109
impl<S: Stage> SingleAttributeParser<S> for DummyParser {
1110
const PATH: &[Symbol] = &[sym::rustc_dummy];

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use rustc_span::{Symbol, sym};
1010

1111
use super::{AcceptContext, AttributeOrder, OnDuplicate};
1212
use crate::attributes::SingleAttributeParser;
13-
use crate::context::Stage;
14-
use crate::parser::ArgParser;
15-
use crate::context::AllowedTargets;
1613
use crate::context::MaybeWarn::Allow;
14+
use crate::context::{AllowedTargets, Stage};
15+
use crate::parser::ArgParser;
1716
pub(crate) struct InlineParser;
1817

1918
impl<S: Stage> SingleAttributeParser<S> for InlineParser {

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ use rustc_span::{Span, Symbol, sym};
77
use crate::attributes::{
88
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
99
};
10-
use crate::context::{AcceptContext, Stage, parse_single_integer};
10+
use crate::context::MaybeWarn::Allow;
11+
use crate::context::{AcceptContext, AllowedTargets, Stage, parse_single_integer};
1112
use crate::parser::ArgParser;
1213
use crate::session_diagnostics::{LinkOrdinalOutOfRange, NullOnLinkSection};
13-
use crate::context::AllowedTargets;
14-
use crate::context::MaybeWarn::Allow;
1514
pub(crate) struct LinkNameParser;
1615

1716
impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
1817
const PATH: &[Symbol] = &[sym::link_name];
1918
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
2019
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
21-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn), Allow(Target::ForeignStatic)]);
20+
const ALLOWED_TARGETS: AllowedTargets =
21+
AllowedTargets::AllowList(&[Allow(Target::ForeignFn), Allow(Target::ForeignStatic)]);
2222
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
2323

2424
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
@@ -41,7 +41,8 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
4141
const PATH: &[Symbol] = &[sym::link_section];
4242
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4343
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
44-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::Fn)]);
44+
const ALLOWED_TARGETS: AllowedTargets =
45+
AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::Fn)]);
4546
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
4647

4748
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
@@ -92,7 +93,8 @@ pub(crate) struct StdInternalSymbolParser;
9293
impl<S: Stage> NoArgsAttributeParser<S> for StdInternalSymbolParser {
9394
const PATH: &[Symbol] = &[sym::rustc_std_internal_symbol];
9495
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
95-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
96+
const ALLOWED_TARGETS: AllowedTargets =
97+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
9698
const CREATE: fn(Span) -> AttributeKind = AttributeKind::StdInternalSymbol;
9799
}
98100

@@ -102,7 +104,8 @@ impl<S: Stage> SingleAttributeParser<S> for LinkOrdinalParser {
102104
const PATH: &[Symbol] = &[sym::link_ordinal];
103105
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
104106
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
105-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn), Allow(Target::ForeignStatic)]);
107+
const ALLOWED_TARGETS: AllowedTargets =
108+
AllowedTargets::AllowList(&[Allow(Target::ForeignFn), Allow(Target::ForeignStatic)]);
106109
const TEMPLATE: AttributeTemplate = template!(List: "ordinal");
107110

108111
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use rustc_hir::{MethodKind, Target};
33
use rustc_span::{Span, Symbol, sym};
44

55
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
6-
use crate::context::Stage;
7-
use crate::context::AllowedTargets;
86
use crate::context::MaybeWarn::Allow;
7+
use crate::context::{AllowedTargets, Stage};
98
pub(crate) struct AsPtrParser;
109
impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
1110
const PATH: &[Symbol] = &[sym::rustc_as_ptr];
@@ -23,7 +22,11 @@ pub(crate) struct PubTransparentParser;
2322
impl<S: Stage> NoArgsAttributeParser<S> for PubTransparentParser {
2423
const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
2524
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
26-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct), Allow(Target::Enum), Allow(Target::Union)]);
25+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
26+
Allow(Target::Struct),
27+
Allow(Target::Enum),
28+
Allow(Target::Union),
29+
]);
2730
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PubTransparent;
2831
}
2932

@@ -39,6 +42,7 @@ pub(crate) struct AutomaticallyDerivedParser;
3942
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4043
const PATH: &[Symbol] = &[sym::automatically_derived];
4144
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
42-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Target::Impl { of_trait: true }]);
45+
const ALLOWED_TARGETS: AllowedTargets =
46+
AllowedTargets::AllowList(&[Allow(Target::Impl { of_trait: true })]);
4347
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
4448
}

compiler/rustc_attr_parsing/src/attributes/loop_match.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use rustc_hir::attrs::AttributeKind;
33
use rustc_span::{Span, Symbol, sym};
44

55
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
6-
use crate::context::Stage;
7-
use crate::context::AllowedTargets;
86
use crate::context::MaybeWarn::Allow;
7+
use crate::context::{AllowedTargets, Stage};
98
pub(crate) struct LoopMatchParser;
109
impl<S: Stage> NoArgsAttributeParser<S> for LoopMatchParser {
1110
const PATH: &[Symbol] = &[sym::loop_match];

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ use rustc_span::{Span, Symbol, sym};
66
use thin_vec::ThinVec;
77

88
use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate};
9-
use crate::context::{AcceptContext, FinalizeContext, Stage};
9+
use crate::context::MaybeWarn::Allow;
10+
use crate::context::{AcceptContext, AllowedTargets, FinalizeContext, Stage};
1011
use crate::parser::ArgParser;
1112
use crate::session_diagnostics;
12-
use crate::context::AllowedTargets;
13-
use crate::context::MaybeWarn::Allow;
1413
pub(crate) struct MacroEscapeParser;
1514
impl<S: Stage> NoArgsAttributeParser<S> for MacroEscapeParser {
1615
const PATH: &[Symbol] = &[sym::macro_escape];
1716
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
18-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::ExternCrate)]);
17+
const ALLOWED_TARGETS: AllowedTargets =
18+
AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::ExternCrate)]);
1919
const CREATE: fn(Span) -> AttributeKind = AttributeKind::MacroEscape;
2020
}
2121

@@ -111,7 +111,8 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
111111
}
112112
},
113113
)];
114-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::ExternCrate)]);
114+
const ALLOWED_TARGETS: AllowedTargets =
115+
AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::ExternCrate)]);
115116

116117
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
117118
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })

0 commit comments

Comments
 (0)