Skip to content

Commit 73c631d

Browse files
Make all unstable crate-level attributes on incorrect targets an error
1 parent 7ed4c9d commit 73c631d

12 files changed

Lines changed: 51 additions & 71 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ pub(crate) struct MoveSizeLimitParser;
9292
impl SingleAttributeParser for MoveSizeLimitParser {
9393
const PATH: &[Symbol] = &[sym::move_size_limit];
9494
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
95-
const ALLOWED_TARGETS: AllowedTargets =
96-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
95+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
9796
const STABILITY: AttributeStability = unstable!(large_assignments);
9897

9998
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -125,8 +124,7 @@ pub(crate) struct PatternComplexityLimitParser;
125124
impl SingleAttributeParser for PatternComplexityLimitParser {
126125
const PATH: &[Symbol] = &[sym::pattern_complexity_limit];
127126
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
128-
const ALLOWED_TARGETS: AllowedTargets =
129-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
127+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
130128
const STABILITY: AttributeStability = unstable!(
131129
rustc_attrs,
132130
"the `#[pattern_complexity_limit]` attribute is used for rustc unit tests"
@@ -143,8 +141,7 @@ pub(crate) struct NoCoreParser;
143141

144142
impl NoArgsAttributeParser for NoCoreParser {
145143
const PATH: &[Symbol] = &[sym::no_core];
146-
const ALLOWED_TARGETS: AllowedTargets =
147-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
144+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
148145
const STABILITY: AttributeStability = unstable!(no_core);
149146
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoCore;
150147
}
@@ -175,8 +172,7 @@ pub(crate) struct RustcCoherenceIsCoreParser;
175172

176173
impl NoArgsAttributeParser for RustcCoherenceIsCoreParser {
177174
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
178-
const ALLOWED_TARGETS: AllowedTargets =
179-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
175+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
180176
const STABILITY: AttributeStability = unstable!(rustc_attrs);
181177
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcCoherenceIsCore;
182178
}
@@ -214,8 +210,7 @@ pub(crate) struct PanicRuntimeParser;
214210

215211
impl NoArgsAttributeParser for PanicRuntimeParser {
216212
const PATH: &[Symbol] = &[sym::panic_runtime];
217-
const ALLOWED_TARGETS: AllowedTargets =
218-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
213+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
219214
const STABILITY: AttributeStability = unstable!(panic_runtime);
220215
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::PanicRuntime;
221216
}
@@ -224,8 +219,7 @@ pub(crate) struct NeedsPanicRuntimeParser;
224219

225220
impl NoArgsAttributeParser for NeedsPanicRuntimeParser {
226221
const PATH: &[Symbol] = &[sym::needs_panic_runtime];
227-
const ALLOWED_TARGETS: AllowedTargets =
228-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
222+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
229223
const STABILITY: AttributeStability = unstable!(needs_panic_runtime);
230224
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NeedsPanicRuntime;
231225
}
@@ -234,8 +228,7 @@ pub(crate) struct ProfilerRuntimeParser;
234228

235229
impl NoArgsAttributeParser for ProfilerRuntimeParser {
236230
const PATH: &[Symbol] = &[sym::profiler_runtime];
237-
const ALLOWED_TARGETS: AllowedTargets =
238-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
231+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
239232
const STABILITY: AttributeStability = unstable!(profiler_runtime);
240233
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProfilerRuntime;
241234
}
@@ -255,8 +248,7 @@ pub(crate) struct RustcPreserveUbChecksParser;
255248

256249
impl NoArgsAttributeParser for RustcPreserveUbChecksParser {
257250
const PATH: &[Symbol] = &[sym::rustc_preserve_ub_checks];
258-
const ALLOWED_TARGETS: AllowedTargets =
259-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
251+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
260252
const STABILITY: AttributeStability = unstable!(rustc_attrs);
261253
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPreserveUbChecks;
262254
}
@@ -265,8 +257,7 @@ pub(crate) struct RustcNoImplicitBoundsParser;
265257

266258
impl NoArgsAttributeParser for RustcNoImplicitBoundsParser {
267259
const PATH: &[Symbol] = &[sym::rustc_no_implicit_bounds];
268-
const ALLOWED_TARGETS: AllowedTargets =
269-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
260+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
270261
const STABILITY: AttributeStability = unstable!(rustc_attrs);
271262
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitBounds;
272263
}
@@ -275,8 +266,7 @@ pub(crate) struct DefaultLibAllocatorParser;
275266

276267
impl NoArgsAttributeParser for DefaultLibAllocatorParser {
277268
const PATH: &[Symbol] = &[sym::default_lib_allocator];
278-
const ALLOWED_TARGETS: AllowedTargets =
279-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
269+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
280270
const STABILITY: AttributeStability = unstable!(allocator_internals);
281271
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::DefaultLibAllocator;
282272
}
@@ -333,8 +323,7 @@ impl CombineAttributeParser for RegisterToolParser {
333323
const PATH: &[Symbol] = &[sym::register_tool];
334324
type Item = Ident;
335325
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
336-
const ALLOWED_TARGETS: AllowedTargets =
337-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
326+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
338327
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);
339328
const STABILITY: AttributeStability = unstable!(register_tool);
340329

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,7 @@ pub(crate) struct NeedsAllocatorParser;
688688

689689
impl NoArgsAttributeParser for NeedsAllocatorParser {
690690
const PATH: &[Symbol] = &[sym::needs_allocator];
691-
const ALLOWED_TARGETS: AllowedTargets =
692-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
691+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
693692
const STABILITY: AttributeStability = unstable!(allocator_internals);
694693
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NeedsAllocator;
695694
}
@@ -698,8 +697,7 @@ pub(crate) struct CompilerBuiltinsParser;
698697

699698
impl NoArgsAttributeParser for CompilerBuiltinsParser {
700699
const PATH: &[Symbol] = &[sym::compiler_builtins];
701-
const ALLOWED_TARGETS: AllowedTargets =
702-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
700+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
703701
const STABILITY: AttributeStability = unstable!(compiler_builtins);
704702
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::CompilerBuiltins;
705703
}

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ pub(crate) struct RustcDumpHiddenTypeOfOpaquesParser;
4949

5050
impl NoArgsAttributeParser for RustcDumpHiddenTypeOfOpaquesParser {
5151
const PATH: &[Symbol] = &[sym::rustc_dump_hidden_type_of_opaques];
52-
const ALLOWED_TARGETS: AllowedTargets =
53-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
52+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
5453
const STABILITY: AttributeStability = unstable!(rustc_attrs);
5554
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpHiddenTypeOfOpaques;
5655
}
@@ -243,8 +242,7 @@ pub(crate) struct RustcDumpVariancesOfOpaquesParser;
243242

244243
impl NoArgsAttributeParser for RustcDumpVariancesOfOpaquesParser {
245244
const PATH: &[Symbol] = &[sym::rustc_dump_variances_of_opaques];
246-
const ALLOWED_TARGETS: AllowedTargets =
247-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
245+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
248246
const STABILITY: AttributeStability = unstable!(rustc_attrs);
249247
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpVariancesOfOpaques;
250248
}

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ pub(crate) struct RustcNeverTypeOptionsParser;
370370

371371
impl SingleAttributeParser for RustcNeverTypeOptionsParser {
372372
const PATH: &[Symbol] = &[sym::rustc_never_type_options];
373-
const ALLOWED_TARGETS: AllowedTargets =
374-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
373+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
375374
const TEMPLATE: AttributeTemplate = template!(List: &[
376375
r#"fallback = "unit", "never", "no""#,
377376
r#"diverging_block_default = "unit", "never""#,

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,7 @@ pub(crate) struct UnstableRemovedParser;
460460
impl CombineAttributeParser for UnstableRemovedParser {
461461
type Item = UnstableRemovedFeature;
462462
const PATH: &[Symbol] = &[sym::unstable_removed];
463-
const ALLOWED_TARGETS: AllowedTargets =
464-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
463+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
465464
const TEMPLATE: AttributeTemplate =
466465
template!(List: &[r#"feature = "name", reason = "...", link = "...", since = "version""#]);
467466
const STABILITY: AttributeStability = unstable!(staged_api);

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ pub(crate) struct ReexportTestHarnessMainParser;
8383

8484
impl SingleAttributeParser for ReexportTestHarnessMainParser {
8585
const PATH: &[Symbol] = &[sym::reexport_test_harness_main];
86-
const ALLOWED_TARGETS: AllowedTargets =
87-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
86+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
8887
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
8988
const STABILITY: AttributeStability = unstable!(custom_test_frameworks);
9089

@@ -175,8 +174,7 @@ pub(crate) struct TestRunnerParser;
175174

176175
impl SingleAttributeParser for TestRunnerParser {
177176
const PATH: &[Symbol] = &[sym::test_runner];
178-
const ALLOWED_TARGETS: AllowedTargets =
179-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
177+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
180178
const TEMPLATE: AttributeTemplate = template!(List: &["path"]);
181179
const STABILITY: AttributeStability = unstable!(custom_test_frameworks);
182180

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub(crate) struct InvalidAttrStyle {
148148
pub crate_root_path: String,
149149
#[help("the crate root is at `{$crate_root_path}`")]
150150
pub show_crate_root_help: bool,
151+
#[primary_span]
151152
pub span: Span,
152153
}
153154

tests/ui/attributes/attr-on-mac-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ fn main() {
108108
//~| WARN previously accepted
109109
unreachable!();
110110
#[register_tool(xyz)]
111-
//~^ WARN crate-level attribute should be an inner attribute
111+
//~^ ERROR crate-level attribute should be an inner attribute
112112
unreachable!();
113113
}

tests/ui/attributes/attr-on-mac-call.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ LL | #[sanitize(address = "off")]
66
|
77
= help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics
88

9+
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
10+
--> $DIR/attr-on-mac-call.rs:110:5
11+
|
12+
LL | #[register_tool(xyz)]
13+
| ^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
note: this attribute does not have an `!`, which means it is applied to this macro call
16+
--> $DIR/attr-on-mac-call.rs:112:5
17+
|
18+
LL | unreachable!();
19+
| ^^^^^^^^^^^^^^
20+
921
warning: `#[export_name]` attribute cannot be used on macro calls
1022
--> $DIR/attr-on-mac-call.rs:8:5
1123
|
@@ -289,17 +301,5 @@ LL | #[repr(simd)]
289301
= help: `#[repr(simd)]` can only be applied to structs
290302
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
291303

292-
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
293-
--> $DIR/attr-on-mac-call.rs:110:5
294-
|
295-
LL | #[register_tool(xyz)]
296-
| ^^^^^^^^^^^^^^^^^^^^^
297-
|
298-
note: this attribute does not have an `!`, which means it is applied to this macro call
299-
--> $DIR/attr-on-mac-call.rs:112:5
300-
|
301-
LL | unreachable!();
302-
| ^^^^^^^^^^^^^^
303-
304-
error: aborting due to 1 previous error; 32 warnings emitted
304+
error: aborting due to 2 previous errors; 31 warnings emitted
305305

tests/ui/attributes/malformed-no-std.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ note: attribute also specified here
106106
LL | #![no_core = "foo"]
107107
| ^^^^^^^^^^^^^^^^^^^
108108

109+
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_core]`
110+
--> $DIR/malformed-no-std.rs:23:1
111+
|
112+
LL | #[no_core]
113+
| ^^^^^^^^^^
114+
|
115+
note: this attribute does not have an `!`, which means it is applied to this extern crate
116+
--> $DIR/malformed-no-std.rs:26:1
117+
|
118+
LL | extern crate core;
119+
| ^^^^^^^^^^^^^^^^^^
120+
109121
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]`
110122
--> $DIR/malformed-no-std.rs:21:1
111123
|
@@ -123,18 +135,6 @@ note: the lint level is defined here
123135
LL | #[deny(unused_attributes)]
124136
| ^^^^^^^^^^^^^^^^^
125137

126-
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_core]`
127-
--> $DIR/malformed-no-std.rs:23:1
128-
|
129-
LL | #[no_core]
130-
| ^^^^^^^^^^
131-
|
132-
note: this attribute does not have an `!`, which means it is applied to this extern crate
133-
--> $DIR/malformed-no-std.rs:26:1
134-
|
135-
LL | extern crate core;
136-
| ^^^^^^^^^^^^^^^^^^
137-
138138
warning: unused attribute
139139
--> $DIR/malformed-no-std.rs:5:1
140140
|

0 commit comments

Comments
 (0)