diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index c7bf465bfb7a9..d6d9b761a1e76 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -314,7 +314,7 @@ impl CombineAttributeParser for RegisterToolParser { const PATH: &[Symbol] = &[sym::register_tool]; type Item = Ident; const CONVERT: ConvertFn = |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); diff --git a/tests/ui/attributes/attr-on-mac-call.rs b/tests/ui/attributes/attr-on-mac-call.rs index 182e9935de25f..2875ff0c74e6d 100644 --- a/tests/ui/attributes/attr-on-mac-call.rs +++ b/tests/ui/attributes/attr-on-mac-call.rs @@ -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() { @@ -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!(); } diff --git a/tests/ui/attributes/attr-on-mac-call.stderr b/tests/ui/attributes/attr-on-mac-call.stderr index cafa43b6f0a1a..8d19137da4457 100644 --- a/tests/ui/attributes/attr-on-mac-call.stderr +++ b/tests/ui/attributes/attr-on-mac-call.stderr @@ -1,5 +1,5 @@ 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")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ 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"] | ^^^^^^^^^^^^^^^^^^^^ @@ -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)] | ^^^^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^^^ @@ -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] | ^^^^^^^ @@ -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")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^ @@ -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"] | ^^^^^^^^^^^^^^^^^^ @@ -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"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -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)] | ^^^^^^^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^ @@ -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] | ^^^^^^^ @@ -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] | ^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^^^^^^^^^^ @@ -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 = ""] | ^^^^^^^^^^^^ @@ -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] | ^^^^^^^^^ @@ -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] | ^^^^^^^^^^^^^^^ @@ -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"] | ^^^^^^^^^^^^^^^^^^ @@ -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()] | ^^^^^^^^^ @@ -228,7 +228,7 @@ 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 @@ -236,7 +236,7 @@ LL | #[repr()] = 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)] | ^^^^^^^^^^^ @@ -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))] | ^^^^^^^^^^^^^^^^^ @@ -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)] | ^^^^^^^^^^^^^^^ @@ -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)] | ^^^^^^^^^^ @@ -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)] | ^^^^^^^^^^^^^ @@ -281,7 +281,7 @@ 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)] | ^^^^^^^^^^^^^ @@ -289,5 +289,17 @@ 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 diff --git a/tests/ui/attributes/register-tool-target.rs b/tests/ui/attributes/register-tool-target.rs new file mode 100644 index 0000000000000..a92b946c95f2d --- /dev/null +++ b/tests/ui/attributes/register-tool-target.rs @@ -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() { + +} diff --git a/tests/ui/attributes/register-tool-target.stderr b/tests/ui/attributes/register-tool-target.stderr new file mode 100644 index 0000000000000..4808ee49ee6a4 --- /dev/null +++ b/tests/ui/attributes/register-tool-target.stderr @@ -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 +