Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl CombineAttributeParser for RegisterToolParser {
const PATH: &[Symbol] = &[sym::register_tool];
type Item = Ident;
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);
const STABILITY: AttributeStability = unstable!(register_tool);

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/attributes/attr-on-mac-call.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ check-fail
// Regression test for https://github.com/rust-lang/rust/issues/145779
#![warn(unused_attributes)]
#![feature(register_tool)]
#![feature(sanitize)]

fn main() {
Expand Down Expand Up @@ -106,4 +107,7 @@ fn main() {
//~^ WARN attribute cannot be used on macro calls
//~| WARN previously accepted
unreachable!();
#[register_tool(xyz)]
//~^ WARN crate-level attribute should be an inner attribute
unreachable!();
}
Comment on lines +110 to 113
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an error? I notice crate level attrs are basically allowed anywhere, I'd like that not to be the case with a new crate level attribute if I can help it.

78 changes: 45 additions & 33 deletions tests/ui/attributes/attr-on-mac-call.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: `#[sanitize]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:76:5
--> $DIR/attr-on-mac-call.rs:77:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics

warning: `#[export_name]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:7:5
--> $DIR/attr-on-mac-call.rs:8:5
|
LL | #[export_name = "x"]
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -21,7 +21,7 @@ LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^

warning: `#[naked]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:10:5
--> $DIR/attr-on-mac-call.rs:11:5
|
LL | #[unsafe(naked)]
| ^^^^^^^^^^^^^^^^
Expand All @@ -30,7 +30,7 @@ LL | #[unsafe(naked)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[track_caller]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:13:5
--> $DIR/attr-on-mac-call.rs:14:5
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
Expand All @@ -39,7 +39,7 @@ LL | #[track_caller]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[used]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:16:5
--> $DIR/attr-on-mac-call.rs:17:5
|
LL | #[used]
| ^^^^^^^
Expand All @@ -48,7 +48,7 @@ LL | #[used]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[target_feature]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:19:5
--> $DIR/attr-on-mac-call.rs:20:5
|
LL | #[target_feature(enable = "x")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -57,7 +57,7 @@ LL | #[target_feature(enable = "x")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[deprecated]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:22:5
--> $DIR/attr-on-mac-call.rs:23:5
|
LL | #[deprecated]
| ^^^^^^^^^^^^^
Expand All @@ -66,7 +66,7 @@ LL | #[deprecated]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[inline]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:25:5
--> $DIR/attr-on-mac-call.rs:26:5
|
LL | #[inline]
| ^^^^^^^^^
Expand All @@ -75,7 +75,7 @@ LL | #[inline]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[link_name]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:28:5
--> $DIR/attr-on-mac-call.rs:29:5
|
LL | #[link_name = "x"]
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -84,7 +84,7 @@ LL | #[link_name = "x"]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[link_section]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:31:5
--> $DIR/attr-on-mac-call.rs:32:5
|
LL | #[link_section = "__TEXT,__text"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -93,7 +93,7 @@ LL | #[link_section = "__TEXT,__text"]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[link_ordinal]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:34:5
--> $DIR/attr-on-mac-call.rs:35:5
|
LL | #[link_ordinal(42)]
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -102,7 +102,7 @@ LL | #[link_ordinal(42)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[non_exhaustive]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:37:5
--> $DIR/attr-on-mac-call.rs:38:5
|
LL | #[non_exhaustive]
| ^^^^^^^^^^^^^^^^^
Expand All @@ -111,7 +111,7 @@ LL | #[non_exhaustive]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[proc_macro]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:40:5
--> $DIR/attr-on-mac-call.rs:41:5
|
LL | #[proc_macro]
| ^^^^^^^^^^^^^
Expand All @@ -120,7 +120,7 @@ LL | #[proc_macro]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[cold]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:43:5
--> $DIR/attr-on-mac-call.rs:44:5
|
LL | #[cold]
| ^^^^^^^
Expand All @@ -129,7 +129,7 @@ LL | #[cold]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[no_mangle]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:46:5
--> $DIR/attr-on-mac-call.rs:47:5
|
LL | #[no_mangle]
| ^^^^^^^^^^^^
Expand All @@ -138,7 +138,7 @@ LL | #[no_mangle]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[deprecated]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:49:5
--> $DIR/attr-on-mac-call.rs:50:5
|
LL | #[deprecated]
| ^^^^^^^^^^^^^
Expand All @@ -147,7 +147,7 @@ LL | #[deprecated]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[automatically_derived]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:52:5
--> $DIR/attr-on-mac-call.rs:53:5
|
LL | #[automatically_derived]
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -156,7 +156,7 @@ LL | #[automatically_derived]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[macro_use]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:55:5
--> $DIR/attr-on-mac-call.rs:56:5
|
LL | #[macro_use]
| ^^^^^^^^^^^^
Expand All @@ -165,7 +165,7 @@ LL | #[macro_use]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[must_use]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:58:5
--> $DIR/attr-on-mac-call.rs:59:5
|
LL | #[must_use]
| ^^^^^^^^^^^
Expand All @@ -174,7 +174,7 @@ LL | #[must_use]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:61:5
--> $DIR/attr-on-mac-call.rs:62:5
|
LL | #[no_implicit_prelude]
| ^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -183,7 +183,7 @@ LL | #[no_implicit_prelude]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[path]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:64:5
--> $DIR/attr-on-mac-call.rs:65:5
|
LL | #[path = ""]
| ^^^^^^^^^^^^
Expand All @@ -192,7 +192,7 @@ LL | #[path = ""]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[ignore]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:67:5
--> $DIR/attr-on-mac-call.rs:68:5
|
LL | #[ignore]
| ^^^^^^^^^
Expand All @@ -201,7 +201,7 @@ LL | #[ignore]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[should_panic]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:70:5
--> $DIR/attr-on-mac-call.rs:71:5
|
LL | #[should_panic]
| ^^^^^^^^^^^^^^^
Expand All @@ -210,7 +210,7 @@ LL | #[should_panic]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[link_name]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:73:5
--> $DIR/attr-on-mac-call.rs:74:5
|
LL | #[link_name = "x"]
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -219,7 +219,7 @@ LL | #[link_name = "x"]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[repr()]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:80:5
--> $DIR/attr-on-mac-call.rs:81:5
|
LL | #[repr()]
| ^^^^^^^^^
Expand All @@ -228,15 +228,15 @@ LL | #[repr()]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: unused attribute
--> $DIR/attr-on-mac-call.rs:80:5
--> $DIR/attr-on-mac-call.rs:81:5
|
LL | #[repr()]
| ^^^^^^^^^ help: remove this attribute
|
= note: using `repr` with an empty list has no effect

warning: `#[repr(u8)]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:85:5
--> $DIR/attr-on-mac-call.rs:86:5
|
LL | #[repr(u8)]
| ^^^^^^^^^^^
Expand All @@ -245,7 +245,7 @@ LL | #[repr(u8)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[repr(align(...))]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:89:5
--> $DIR/attr-on-mac-call.rs:90:5
|
LL | #[repr(align(8))]
| ^^^^^^^^^^^^^^^^^
Expand All @@ -254,7 +254,7 @@ LL | #[repr(align(8))]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[repr(packed)]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:93:5
--> $DIR/attr-on-mac-call.rs:94:5
|
LL | #[repr(packed)]
| ^^^^^^^^^^^^^^^
Expand All @@ -263,7 +263,7 @@ LL | #[repr(packed)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[repr(C)]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:97:5
--> $DIR/attr-on-mac-call.rs:98:5
|
LL | #[repr(C)]
| ^^^^^^^^^^
Expand All @@ -272,7 +272,7 @@ LL | #[repr(C)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[repr(Rust)]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:101:5
--> $DIR/attr-on-mac-call.rs:102:5
|
LL | #[repr(Rust)]
| ^^^^^^^^^^^^^
Expand All @@ -281,13 +281,25 @@ LL | #[repr(Rust)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: `#[repr(simd)]` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:105:5
--> $DIR/attr-on-mac-call.rs:106:5
|
LL | #[repr(simd)]
| ^^^^^^^^^^^^^
|
= help: `#[repr(simd)]` can only be applied to structs
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

error: aborting due to 1 previous error; 31 warnings emitted
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
--> $DIR/attr-on-mac-call.rs:110:5
|
LL | #[register_tool(xyz)]
| ^^^^^^^^^^^^^^^^^^^^^
|
note: this attribute does not have an `!`, which means it is applied to this macro call
--> $DIR/attr-on-mac-call.rs:112:5
|
LL | unreachable!();
| ^^^^^^^^^^^^^^

error: aborting due to 1 previous error; 32 warnings emitted

8 changes: 8 additions & 0 deletions tests/ui/attributes/register-tool-target.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ check-pass
#![feature(register_tool)]

#[register_tool(no_valid_target)]
//~^ WARN crate-level attribute should be an inner attribute
fn main() {

}
17 changes: 17 additions & 0 deletions tests/ui/attributes/register-tool-target.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
--> $DIR/register-tool-target.rs:4:1
|
LL | #[register_tool(no_valid_target)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: this attribute does not have an `!`, which means it is applied to this function
--> $DIR/register-tool-target.rs:6:1
|
LL | / fn main() {
LL | |
LL | | }
| |_^
= note: requested on the command line with `-W unused-attributes`

warning: 1 warning emitted

Loading