From 33eb2d7e01330a4601b5dfc4e80c2ab66e991a83 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 12 May 2025 16:16:27 +0200 Subject: [PATCH 1/5] start with properly testing attribute positions --- tests/ui/attributes/positions/README.md | 262 +++++++ tests/ui/attributes/positions/allow.rs | 208 +++++ tests/ui/attributes/positions/allow.stderr | 63 ++ .../attributes/positions/auxiliary/dummy.rs | 1 + tests/ui/attributes/positions/empty_crate.rs | 5 + tests/ui/attributes/positions/must_use.rs | 227 ++++++ tests/ui/attributes/positions/must_use.stderr | 470 +++++++++++ tests/ui/attributes/positions/no_link.rs | 227 ++++++ tests/ui/attributes/positions/no_link.stderr | 730 ++++++++++++++++++ 9 files changed, 2193 insertions(+) create mode 100644 tests/ui/attributes/positions/README.md create mode 100644 tests/ui/attributes/positions/allow.rs create mode 100644 tests/ui/attributes/positions/allow.stderr create mode 100644 tests/ui/attributes/positions/auxiliary/dummy.rs create mode 100644 tests/ui/attributes/positions/empty_crate.rs create mode 100644 tests/ui/attributes/positions/must_use.rs create mode 100644 tests/ui/attributes/positions/must_use.stderr create mode 100644 tests/ui/attributes/positions/no_link.rs create mode 100644 tests/ui/attributes/positions/no_link.stderr diff --git a/tests/ui/attributes/positions/README.md b/tests/ui/attributes/positions/README.md new file mode 100644 index 0000000000000..c885c5f84f5d5 --- /dev/null +++ b/tests/ui/attributes/positions/README.md @@ -0,0 +1,262 @@ +It's not uncommon to see comments like these when reading attribute related code: + +```rust +// FIXME(#80564): We permit struct fields, match arms and macro defs to have an +// `#[no_mangle]` attribute with just a lint, because we previously +// erroneously allowed it and some crates used it accidentally, to be compatible +// with crates depending on them, we can't throw an error here. +``` + +or: + +```rust +// FIXME: This can be used on stable but shouldn't. +``` + +Or perhaps you've seen discussions getting derailed by comments like: + +```text +I discovered today that the following code already compiles on stable since at least Rust 1.31 +... +``` + +This is largely because our coverage of attributes and where they're allowed is very poor. +This test suite attempts to consistently and exhaustively check attributes in various positions. +Hopefully, improving test coverage leads to the following: +- We become aware of the weird edge cases that are already allowed. +- We avoid unknowingly breaking those things. +- We can avoid accidentally stabilizing things we don't want stabilized. + +If you know an attribute or a position that isn't tested but should be, please file an issue or PR. + +## Template + +`ATTRIBUTE.rs` +```rust +//@aux-build:dummy.rs + +#![forbid(unstable_features)] +#![warn(unused_attributes)] + +#![ATTRIBUTE] //~ WARN + +#[ATTRIBUTE] //~ WARN +extern crate dummy; + +extern crate core; + +#[ATTRIBUTE] //~ WARN +pub mod empty_crate; + +#[ATTRIBUTE] //~ WARN +pub mod module { + #![ATTRIBUTE] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[ATTRIBUTE] //~ WARN + pub static GLOBAL: u32 = 42; + + #[ATTRIBUTE] //~ WARN + pub static mut GLOBAL_MUT: u32 = 42; + + #[ATTRIBUTE] //~ WARN + pub const CONST: u32 = 42; + + #[ATTRIBUTE] //~ WARN + use ::core::fmt::Debug; + + #[ATTRIBUTE] //~ WARN + trait TraitAlias = Debug; //~ ERROR trait aliases are experimental + + #[ATTRIBUTE] //~ WARN + pub type TypeAlias = u32; + + #[ATTRIBUTE] //~ WARN + pub struct Struct< + #[ATTRIBUTE] 'lt, //~ WARN + #[ATTRIBUTE] T> //~ WARN + { + #[ATTRIBUTE] //~ WARN + pub struct_field: u32, + #[ATTRIBUTE] //~ WARN + pub generic_field: &'lt T, + } + + #[ATTRIBUTE] //~ WARN + pub struct TupleStruct(#[ATTRIBUTE] pub u32); //~ WARN + + #[ATTRIBUTE] //~ WARN + pub enum Enum { + #[ATTRIBUTE] //~ WARN + FieldVariant { + #[ATTRIBUTE] //~ WARN + field: u32, + }, + #[ATTRIBUTE] //~ WARN + TupleVariant(#[ATTRIBUTE] u32), //~ WARN + } + #[ATTRIBUTE] //~ WARN + pub union Union { + #[ATTRIBUTE] //~ WARN + pub field: u32, + } + + #[ATTRIBUTE] //~ WARN + impl<'lt, T> Struct<'lt, T> { + #![ATTRIBUTE] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[ATTRIBUTE] //~ WARN + pub fn method(#[ATTRIBUTE] &mut self) { //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ WARN + #[ATTRIBUTE] //~ ERROR + //~^ WARN + self.struct_field = struct_field; + } + + #[ATTRIBUTE] //~ WARN + pub fn static_method(#[ATTRIBUTE] _arg: u32) {} //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + } + + #[ATTRIBUTE] + impl< + #[ATTRIBUTE] 'lt, //~ WARN + #[ATTRIBUTE] T //~ WARN + > Drop for Struct<'lt, T> { + #[ATTRIBUTE] //~ WARN + fn drop(&mut self) { + // .. + } + } + + #[ATTRIBUTE] //~ WARN + pub fn function< + #[ATTRIBUTE] const N: usize //~ WARN + >(arg: u32) -> u32 { + #![ATTRIBUTE] //~ WARN + //~^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + arg + } + + #[ATTRIBUTE] //~ WARN + pub trait Trait { + #[ATTRIBUTE] //~ WARN + fn trait_method() {} + } +} + +#[ATTRIBUTE] //~ WARN +fn main() { + let _closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental + //~^ WARN + | _arg: u32| {}; + + let _move_closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental + //~^ WARN + move | _arg: u32| {}; + + #[ATTRIBUTE] //~ WARN + { + #![ATTRIBUTE] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[ATTRIBUTE] //~ WARN + let variable = 42_u32; + + let _array = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental + //~^ WARN + [ + #[ATTRIBUTE] //~ WARN + 1, + 2, + ]; + let _tuple = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental + //~^ WARN + ( + #[ATTRIBUTE] //~ WARN + 1, + 2, + ); + let _tuple_struct = module::TupleStruct( + #[ATTRIBUTE] //~ WARN + 2, + ); + let _struct = module::Struct { + #[ATTRIBUTE] //~ WARN + struct_field: 42, + generic_field: &13, + }; + + let _union = module::Union { + #[ATTRIBUTE] //~ WARN + field: 42, + }; + + let _fn_call = module::function::<7>( + #[ATTRIBUTE] //~ WARN + 42, + ); + + #[ATTRIBUTE] //~ WARN + match variable { + #[ATTRIBUTE] //~ WARN + _match_arm => {} + } + + let tail = (); + + #[ATTRIBUTE] //~ WARN + tail + } + + { + fn f(_: impl Fn()) {} + // Is this attribute argument-level or expression-level? + f( + #[ATTRIBUTE] //~ WARN + || {}, + ); + } + + #[ATTRIBUTE] //~ WARN + unsafe { + let _x = [1, 2, 3].get_unchecked(1); + } +} + +#[ATTRIBUTE] //~ WARN +unsafe extern "C" { + #![ATTRIBUTE] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[ATTRIBUTE] //~ WARN + pub fn external_function( + arg: *mut u8, + ... + ); + + #[ATTRIBUTE] //~ WARN + pub static EXTERNAL_STATIC: *const u32; + + #[ATTRIBUTE] //~ WARN + pub static mut EXTERNAL_STATIC_MUT: *mut u32; +} + +#[ATTRIBUTE] //~ WARN +pub unsafe extern "C" fn abi_function(_: u32) {} + +#[ATTRIBUTE] //~ WARN +#[macro_export] +macro_rules! my_macro { + () => {}; +} + +#[ATTRIBUTE] //~ WARN +#[test] +fn test_fn() {} +``` diff --git a/tests/ui/attributes/positions/allow.rs b/tests/ui/attributes/positions/allow.rs new file mode 100644 index 0000000000000..edaaeda3fab11 --- /dev/null +++ b/tests/ui/attributes/positions/allow.rs @@ -0,0 +1,208 @@ +//@aux-build:dummy.rs + +#![forbid(unstable_features)] + +#![allow()] // OK + +#[allow()] // OK +extern crate dummy; + +extern crate core; + +#[allow()] // OK +pub mod empty_crate; + +#[allow()] // OK +pub mod module { + #![allow()] // OK + + #[allow()] // OK + pub static GLOBAL: u32 = 42; + + #[allow()] // OK + pub static mut GLOBAL_MUT: u32 = 42; + + #[allow()] // OK + pub const CONST: u32 = 42; + + #[allow()] // OK + use core::fmt::Debug; + + #[allow()] // OK + trait TraitAlias = Debug; //~ ERROR trait aliases are experimental + + #[allow()] // OK + pub type TypeAlias = u32; + + #[allow()] // OK + pub struct Struct< + #[allow()] 'lt, // OK + #[allow()] T> // OK + { + #[allow()] // OK + pub struct_field: u32, + #[allow()] // OK + pub generic_field: &'lt T, + } + + #[allow()] // OK + pub struct TupleStruct(#[allow()] pub u32); // OK + + #[allow()] // OK + pub enum Enum { + #[allow()] // OK + FieldVariant { + #[allow()] // OK + field: u32, + }, + #[allow()] // OK + TupleVariant(#[allow()] u32), + } + #[allow()] // OK + pub union Union { + #[allow()] // OK + pub field: u32, + } + + #[allow()] // OK + impl<'lt, T> Struct<'lt, T> { + #![allow()] // OK + #[allow()] // OK + pub fn method(#[allow()] &mut self) { // OK + + #[allow()] //~ ERROR + self.struct_field = 73; + } + #[allow()] // OK + pub fn static_method(#[allow()] _arg: u32) {} + } + + #[allow()] + impl< + #[allow()] 'lt, // OK + #[allow()] T // OK + > Drop for Struct<'lt, T> { + #[allow()] // OK + fn drop(&mut self) { + // .. + } + } + + #[allow()] // OK + pub fn function< + #[allow()] const N: usize // OK + >(#[allow()] arg: u32) -> u32 { // OK + #![allow()] // OK + arg + } + + #[allow()] // OK + pub trait Trait { + #[allow()] // OK + fn trait_method() {} + } +} + +#[allow()] // OK +fn main() { + let _closure = #[allow()] //~ ERROR attributes on expressions are experimental + |#[allow()] _arg: u32| {}; // OK + + let _move_closure = #[allow()] //~ ERROR attributes on expressions are experimental + move |#[allow()] _arg: u32| {}; // OK + + #[allow()] // OK + { + #![allow()] // OK + + #[allow()] // OK + let variable = 42_u32; + + let _array = #[allow()] //~ ERROR attributes on expressions are experimental + [ + #[allow()] // OK + 1, + 2, + ]; + let _tuple = #[allow()] //~ ERROR attributes on expressions are experimental + ( + #[allow()] // OK + 1, + 2, + ); + let _tuple_struct = module::TupleStruct( + #[allow()] // OK + 2, + ); + let _struct = module::Struct { + #[allow()] // OK + struct_field: 42, + generic_field: &13, + }; + + let _union = module::Union { + #[allow()] // OK + field: 42, + }; + + let _fn_call = module::function::<7>( + #[allow()] // OK + 42, + ); + + #[allow()] // OK + match variable { + #[allow()] // OK + _match_arm => {} + } + + let tail = (); + + #[allow()] // OK + tail + } + + { + fn f(_: impl Fn()) {} + // Is this attribute argument-level or expression-level? + f( + #[allow()] // OK + || {}, + ); + } + + #[allow()] // OK + unsafe { + let _x = [1, 2, 3].get_unchecked(1); + } +} + +#[allow()] // OK +unsafe extern "C" { + #![allow()] // OK + + #[allow()] // OK + pub fn external_function( + #[allow()] arg: *mut u8, // OK + #[allow()] ... // OK + ); + + #[allow()] // OK + pub static EXTERNAL_STATIC: *const u32; + + #[allow()] // OK + pub static mut EXTERNAL_STATIC_MUT: *mut u32; +} + +#[allow()] // OK +pub unsafe extern "C" fn abi_function(#[allow()] _: u32) {} + +#[allow()] // OK +#[macro_export] +macro_rules! my_macro { + () => {}; +} + +#[allow()] // OK +#[test] +fn test_fn() {} diff --git a/tests/ui/attributes/positions/allow.stderr b/tests/ui/attributes/positions/allow.stderr new file mode 100644 index 0000000000000..ef9e05cd691c0 --- /dev/null +++ b/tests/ui/attributes/positions/allow.stderr @@ -0,0 +1,63 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/allow.rs:73:13 + | +LL | #[allow()] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/allow.rs:108:20 + | +LL | let _closure = #[allow()] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/allow.rs:111:25 + | +LL | let _move_closure = #[allow()] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/allow.rs:121:22 + | +LL | let _array = #[allow()] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/allow.rs:127:22 + | +LL | let _tuple = #[allow()] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: trait aliases are experimental + --> $DIR/allow.rs:32:5 + | +LL | trait TraitAlias = Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #41517 for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/attributes/positions/auxiliary/dummy.rs b/tests/ui/attributes/positions/auxiliary/dummy.rs new file mode 100644 index 0000000000000..0942a90fd5fb8 --- /dev/null +++ b/tests/ui/attributes/positions/auxiliary/dummy.rs @@ -0,0 +1 @@ +// Empty file so that other tests can do `extern crate dummy;` diff --git a/tests/ui/attributes/positions/empty_crate.rs b/tests/ui/attributes/positions/empty_crate.rs new file mode 100644 index 0000000000000..4ca95e1f67432 --- /dev/null +++ b/tests/ui/attributes/positions/empty_crate.rs @@ -0,0 +1,5 @@ +//@ check-pass + +// Empty file so that other tests can do `pub mod empty_crate;` + +pub fn main() {} diff --git a/tests/ui/attributes/positions/must_use.rs b/tests/ui/attributes/positions/must_use.rs new file mode 100644 index 0000000000000..eaa37547303bb --- /dev/null +++ b/tests/ui/attributes/positions/must_use.rs @@ -0,0 +1,227 @@ +//@aux-build:dummy.rs + +#![forbid(unstable_features)] +#![warn(unused_attributes)] + +#![must_use] //~ WARN + +#[must_use] //~ WARN +extern crate dummy; + +extern crate core; + +#[must_use] //~ WARN +pub mod empty_crate; + +#[must_use] //~ WARN +pub mod module { + #![must_use] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[must_use] //~ WARN + pub static GLOBAL: u32 = 42; + + #[must_use] //~ WARN + pub static mut GLOBAL_MUT: u32 = 42; + + #[must_use] //~ WARN + pub const CONST: u32 = 42; + + #[must_use] //~ WARN + use ::core::fmt::Debug; + + #[must_use] //~ WARN + trait TraitAlias = Debug; //~ ERROR trait aliases are experimental + + #[must_use] //~ WARN + pub type TypeAlias = u32; + + #[must_use] // OK + pub struct Struct< + #[must_use] 'lt, //~ WARN + #[must_use] T> //~ WARN + { + #[must_use] //~ WARN + pub struct_field: u32, + #[must_use] //~ WARN + pub generic_field: &'lt T, + } + + #[must_use] // OK + pub struct TupleStruct(#[must_use] pub u32); //~ WARN + + #[must_use] // OK + pub enum Enum { + #[must_use] //~ WARN + FieldVariant { + #[must_use] //~ WARN + field: u32, + }, + #[must_use] //~ WARN + TupleVariant(#[must_use] u32), //~ WARN + } + #[must_use] // OK + pub union Union { + #[must_use] //~ WARN + pub field: u32, + } + + #[must_use] //~ WARN + impl<'lt, T> Struct<'lt, T> { + #![must_use] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[must_use] // OK + pub fn method(#[must_use] &mut self) { //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ WARN + #[must_use] //~ ERROR + //~^ WARN + self.struct_field = 73; + } + + #[must_use] // OK + pub fn static_method(#[must_use] _arg: u32) {} //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ WARN + } + + #[must_use] //~ WARN + impl< + #[must_use] 'lt, //~ WARN + #[must_use] T //~ WARN + > Drop for Struct<'lt, T> { + #[must_use] //~ WARN + fn drop(&mut self) { + // .. + } + } + + #[must_use] // OK + pub fn function< + #[must_use] const N: usize //~ WARN + >(arg: u32) -> u32 { + #![must_use] //~ WARN + //~^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + arg + } + + #[must_use] // OK + pub trait Trait { + #[must_use] // OK + fn trait_method() {} + } +} + +#[must_use] // OK +fn main() { + let _closure = #[must_use] //~ ERROR attributes on expressions are experimental + //~^ WARN + | _arg: u32| {}; + + let _move_closure = #[must_use] //~ ERROR attributes on expressions are experimental + //~^ WARN + move | _arg: u32| {}; + + #[must_use] //~ WARN + { + #![must_use] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[must_use] //~ WARN + let variable = 42_u32; + + let _array = #[must_use] //~ ERROR attributes on expressions are experimental + //~^ WARN + [ + #[must_use] //~ WARN + 1, + 2, + ]; + let _tuple = #[must_use] //~ ERROR attributes on expressions are experimental + //~^ WARN + ( + #[must_use] //~ WARN + 1, + 2, + ); + let _tuple_struct = module::TupleStruct( + #[must_use] //~ WARN + 2, + ); + let _struct = module::Struct { + #[must_use] //~ WARN + struct_field: 42, + generic_field: &13, + }; + + let _union = module::Union { + #[must_use] //~ WARN + field: 42, + }; + + let _fn_call = module::function::<7>( + #[must_use] //~ WARN + 42, + ); + + #[must_use] //~ WARN + match variable { + #[must_use] //~ WARN + _match_arm => {} + } + + let tail = (); + + #[must_use] //~ WARN + tail + } + + { + fn f(_: impl Fn()) {} + // Is this attribute argument-level or expression-level? + f( + #[must_use] //~ WARN + || {}, + ); + } + + #[must_use] //~ WARN + unsafe { + let _x = [1, 2, 3].get_unchecked(1); + } +} + +#[must_use] //~ WARN +unsafe extern "C" { + #![must_use] //~ WARN + //~^ WARN unused attribute + //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + + #[must_use] // OK + pub fn external_function( + arg: *mut u8, + ... + ); + + #[must_use] //~ WARN + pub static EXTERNAL_STATIC: *const u32; + + #[must_use] //~ WARN + pub static mut EXTERNAL_STATIC_MUT: *mut u32; +} + +#[must_use] // OK +pub unsafe extern "C" fn abi_function(_: u32) {} + +#[must_use] //~ WARN +#[macro_export] +macro_rules! my_macro { + () => {}; +} + +#[must_use] // OK +#[test] +fn test_fn() {} diff --git a/tests/ui/attributes/positions/must_use.stderr b/tests/ui/attributes/positions/must_use.stderr new file mode 100644 index 0000000000000..6a45f9ac6fcbf --- /dev/null +++ b/tests/ui/attributes/positions/must_use.stderr @@ -0,0 +1,470 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/must_use.rs:79:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/must_use.rs:119:20 + | +LL | let _closure = #[must_use] + | ^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/must_use.rs:123:25 + | +LL | let _move_closure = #[must_use] + | ^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/must_use.rs:136:22 + | +LL | let _array = #[must_use] + | ^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/must_use.rs:143:22 + | +LL | let _tuple = #[must_use] + | ^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:77:23 + | +LL | ... pub fn method(#[must_use] &mut self) { + | ^^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:85:30 + | +LL | ... pub fn static_method(#[must_use] _arg: u32) {} + | ^^^^^^^^^^^ + +error[E0658]: trait aliases are experimental + --> $DIR/must_use.rs:35:5 + | +LL | trait TraitAlias = Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #41517 for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +warning: `#[must_use]` has no effect when applied to an extern crate + --> $DIR/must_use.rs:8:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/must_use.rs:4:9 + | +LL | #![warn(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a module + --> $DIR/must_use.rs:13:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a module + --> $DIR/must_use.rs:16:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a module + --> $DIR/must_use.rs:18:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:18:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/must_use.rs:16:1 + | +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: `#[must_use]` has no effect when applied to a closure + --> $DIR/must_use.rs:119:20 + | +LL | let _closure = #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a closure + --> $DIR/must_use.rs:123:25 + | +LL | let _move_closure = #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:127:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:129:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:129:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/must_use.rs:127:5 + | +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: `#[must_use]` has no effect when applied to a statement + --> $DIR/must_use.rs:133:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:136:22 + | +LL | let _array = #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:139:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:143:22 + | +LL | let _tuple = #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:146:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:151:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:155:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:161:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:166:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:170:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an match arm + --> $DIR/must_use.rs:172:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:178:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a closure + --> $DIR/must_use.rs:186:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:191:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a foreign module + --> $DIR/must_use.rs:197:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a foreign module + --> $DIR/must_use.rs:199:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:199:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/must_use.rs:197:1 + | +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: `#[must_use]` has no effect when applied to a macro def + --> $DIR/must_use.rs:219:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a foreign static item + --> $DIR/must_use.rs:209:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a foreign static item + --> $DIR/must_use.rs:212:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a module + --> $DIR/must_use.rs:6:1 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a static item + --> $DIR/must_use.rs:22:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a static item + --> $DIR/must_use.rs:25:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a constant item + --> $DIR/must_use.rs:28:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a use + --> $DIR/must_use.rs:31:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a trait alias + --> $DIR/must_use.rs:34:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a type alias + --> $DIR/must_use.rs:37:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a lifetime parameter + --> $DIR/must_use.rs:42:9 + | +LL | #[must_use] 'lt, + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a type parameter + --> $DIR/must_use.rs:43:9 + | +LL | #[must_use] T> + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:45:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:47:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:52:28 + | +LL | pub struct TupleStruct(#[must_use] pub u32); + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a enum variant + --> $DIR/must_use.rs:56:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:58:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a enum variant + --> $DIR/must_use.rs:61:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:62:22 + | +LL | TupleVariant(#[must_use] u32), + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:66:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an implementation block + --> $DIR/must_use.rs:70:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an implementation block + --> $DIR/must_use.rs:72:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:72:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/must_use.rs:70:5 + | +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: `#[must_use]` has no effect when applied to an implementation block + --> $DIR/must_use.rs:89:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a lifetime parameter + --> $DIR/must_use.rs:91:9 + | +LL | #[must_use] 'lt, + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a type parameter + --> $DIR/must_use.rs:92:9 + | +LL | #[must_use] T + | ^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:104:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/must_use.rs:100:5 + | +LL | #[must_use] // OK + | ^^^^^^^^^^^ + = 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]` has no effect when applied to a const parameter + --> $DIR/must_use.rs:102:9 + | +LL | #[must_use] const N: usize + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a function param + --> $DIR/must_use.rs:77:23 + | +LL | ... pub fn method(#[must_use] &mut self) { + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:79:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a function param + --> $DIR/must_use.rs:85:30 + | +LL | ... pub fn static_method(#[must_use] _arg: u32) {} + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a provided trait method + --> $DIR/must_use.rs:94:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +error: aborting due to 8 previous errors; 59 warnings emitted + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/attributes/positions/no_link.rs b/tests/ui/attributes/positions/no_link.rs new file mode 100644 index 0000000000000..832d59b48c801 --- /dev/null +++ b/tests/ui/attributes/positions/no_link.rs @@ -0,0 +1,227 @@ +//@aux-build:dummy.rs + +#![forbid(unstable_features)] +#![warn(unused_attributes)] + +#![no_link] //~ ERROR + +#[no_link] // OK +extern crate dummy; + +extern crate core; + +#[no_link] //~ ERROR +pub mod empty_crate; + +#[no_link] //~ ERROR +pub mod module { + #![no_link] //~ ERROR + //~^ WARN unused attribute + + + #[no_link] //~ ERROR + pub static GLOBAL: u32 = 42; + + #[no_link] //~ ERROR + pub static mut GLOBAL_MUT: u32 = 42; + + #[no_link] //~ ERROR + pub const CONST: u32 = 42; + + #[no_link] //~ ERROR + use ::core::fmt::Debug; + + #[no_link] //~ ERROR + trait TraitAlias = Debug; //~ ERROR trait aliases are experimental + + #[no_link] //~ ERROR + pub type TypeAlias = u32; + + #[no_link] //~ ERROR + pub struct Struct< + #[no_link] 'lt, //~ ERROR + #[no_link] T> //~ ERROR + { + #[no_link] //~ WARN + pub struct_field: u32, + #[no_link] //~ WARN + pub generic_field: &'lt T, + } + + #[no_link] //~ ERROR + pub struct TupleStruct(#[no_link] pub u32); //~ WARN + + #[no_link] //~ ERROR + pub enum Enum { + #[no_link] //~ ERROR + FieldVariant { + #[no_link] //~ WARN + field: u32, + }, + #[no_link] //~ ERROR + TupleVariant(#[no_link] u32), //~ WARN + } + #[no_link] //~ ERROR + pub union Union { + #[no_link] //~ WARN + pub field: u32, + } + + #[no_link] //~ ERROR + impl<'lt, T> Struct<'lt, T> { + #![no_link] //~ ERROR + //~^ WARN unused attribute + + + #[no_link] //~ ERROR + pub fn method(#[no_link] &mut self) { //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ ERROR + #[no_link] //~ ERROR + //~^ ERROR + self.struct_field = 73; + } + + #[no_link] //~ ERROR + pub fn static_method(#[no_link] _arg: u32) {} //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ ERROR + } + + #[no_link] //~ ERROR + impl< + #[no_link] 'lt, //~ ERROR + #[no_link] T //~ ERROR + > Drop for Struct<'lt, T> { + #[no_link] //~ ERROR + fn drop(&mut self) { + // .. + } + } + + #[no_link] //~ ERROR + pub fn function< + #[no_link] const N: usize //~ ERROR + >(arg: u32) -> u32 { + #![no_link] //~ ERROR + //~^ WARN + + arg + } + + #[no_link] //~ ERROR + pub trait Trait { + #[no_link] //~ ERROR + fn trait_method() {} + } +} + +#[no_link] //~ ERROR +fn main() { + let _closure = #[no_link] //~ ERROR attributes on expressions are experimental + //~^ ERROR + | _arg: u32| {}; + + let _move_closure = #[no_link] //~ ERROR attributes on expressions are experimental + //~^ ERROR + move | _arg: u32| {}; + + #[no_link] //~ ERROR + { + #![no_link] //~ ERROR + //~^ WARN unused attribute + + + #[no_link] //~ ERROR + let variable = 42_u32; + + let _array = #[no_link] //~ ERROR attributes on expressions are experimental + //~^ ERROR + [ + #[no_link] //~ ERROR + 1, + 2, + ]; + let _tuple = #[no_link] //~ ERROR attributes on expressions are experimental + //~^ ERROR + ( + #[no_link] //~ ERROR + 1, + 2, + ); + let _tuple_struct = module::TupleStruct( + #[no_link] //~ ERROR + 2, + ); + let _struct = module::Struct { + #[no_link] //~ ERROR + struct_field: 42, + generic_field: &13, + }; + + let _union = module::Union { + #[no_link] //~ ERROR + field: 42, + }; + + let _fn_call = module::function::<7>( + #[no_link] //~ ERROR + 42, + ); + + #[no_link] //~ ERROR + match variable { + #[no_link] //~ WARN + _match_arm => {} + } + + let tail = (); + + #[no_link] //~ ERROR + tail + } + + { + fn f(_: impl Fn()) {} + // Is this attribute argument-level or expression-level? + f( + #[no_link] //~ ERROR + || {}, + ); + } + + #[no_link] //~ ERROR + unsafe { + let _x = [1, 2, 3].get_unchecked(1); + } +} + +#[no_link] //~ ERROR +unsafe extern "C" { + #![no_link] //~ ERROR + //~^ WARN unused attribute + + + #[no_link] //~ ERROR + pub fn external_function( + arg: *mut u8, + ... + ); + + #[no_link] //~ ERROR + pub static EXTERNAL_STATIC: *const u32; + + #[no_link] //~ ERROR + pub static mut EXTERNAL_STATIC_MUT: *mut u32; +} + +#[no_link] //~ ERROR +pub unsafe extern "C" fn abi_function(_: u32) {} + +#[no_link] //~ WARN +#[macro_export] +macro_rules! my_macro { + () => {}; +} + +#[no_link] // OK +#[test] +fn test_fn() {} diff --git a/tests/ui/attributes/positions/no_link.stderr b/tests/ui/attributes/positions/no_link.stderr new file mode 100644 index 0000000000000..b21853a723560 --- /dev/null +++ b/tests/ui/attributes/positions/no_link.stderr @@ -0,0 +1,730 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/no_link.rs:79:13 + | +LL | #[no_link] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/no_link.rs:119:20 + | +LL | let _closure = #[no_link] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/no_link.rs:123:25 + | +LL | let _move_closure = #[no_link] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/no_link.rs:136:22 + | +LL | let _array = #[no_link] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: attributes on expressions are experimental + --> $DIR/no_link.rs:143:22 + | +LL | let _tuple = #[no_link] + | ^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:77:23 + | +LL | ... pub fn method(#[no_link] &mut self) { + | ^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:85:30 + | +LL | ... pub fn static_method(#[no_link] _arg: u32) {} + | ^^^^^^^^^^ + +error[E0658]: trait aliases are experimental + --> $DIR/no_link.rs:35:5 + | +LL | trait TraitAlias = Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #41517 for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:13:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub mod empty_crate; + | -------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:16:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub mod module { +LL | | #![no_link] +... | +LL | | } + | |_- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:18:5 + | +LL | / pub mod module { +LL | | #![no_link] + | | ^^^^^^^^^^^ +... | +LL | | } + | |_- not an `extern crate` item + +warning: unused attribute + --> $DIR/no_link.rs:18:5 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:16:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/no_link.rs:4:9 + | +LL | #![warn(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:117:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / fn main() { +LL | | let _closure = #[no_link] +LL | | +LL | | | _arg: u32| {}; +... | +LL | | } + | |_- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:119:20 + | +LL | let _closure = #[no_link] + | ^^^^^^^^^^ +LL | +LL | | _arg: u32| {}; + | --------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:123:25 + | +LL | let _move_closure = #[no_link] + | ^^^^^^^^^^ +LL | +LL | move | _arg: u32| {}; + | -------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:127:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / { +LL | | #![no_link] +... | +LL | | tail +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:129:9 + | +LL | / { +LL | | #![no_link] + | | ^^^^^^^^^^^ +... | +LL | | tail +LL | | } + | |_____- not an `extern crate` item + +warning: unused attribute + --> $DIR/no_link.rs:129:9 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:127:5 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:133:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | let variable = 42_u32; + | ---------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:136:22 + | +LL | let _array = #[no_link] + | ^^^^^^^^^^ +LL | +LL | / [ +LL | | #[no_link] +LL | | 1, +LL | | 2, +LL | | ]; + | |_________- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:139:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | 1, + | - not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:143:22 + | +LL | let _tuple = #[no_link] + | ^^^^^^^^^^ +LL | +LL | / ( +LL | | #[no_link] +LL | | 1, +LL | | 2, +LL | | ); + | |_________- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:146:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | 1, + | - not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:151:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | 2, + | - not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:155:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | struct_field: 42, + | ---------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:161:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | field: 42, + | --------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:166:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | 42, + | -- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:170:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / match variable { +LL | | #[no_link] +LL | | _match_arm => {} +LL | | } + | |_________- not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:172:13 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:178:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | tail + | ---- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:186:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | || {}, + | ----- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:191:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / unsafe { +LL | | let _x = [1, 2, 3].get_unchecked(1); +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:197:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / unsafe extern "C" { +LL | | #![no_link] +... | +LL | | pub static mut EXTERNAL_STATIC_MUT: *mut u32; +LL | | } + | |_- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:199:5 + | +LL | / unsafe extern "C" { +LL | | #![no_link] + | | ^^^^^^^^^^^ +... | +LL | | pub static mut EXTERNAL_STATIC_MUT: *mut u32; +LL | | } + | |_- not an `extern crate` item + +warning: unused attribute + --> $DIR/no_link.rs:199:5 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:197:1 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:216:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub unsafe extern "C" fn abi_function(_: u32) {} + | ------------------------------------------------ not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:219:1 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:203:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub fn external_function( +LL | | arg: *mut u8, +LL | | ... +LL | | ); + | |______- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:209:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub static EXTERNAL_STATIC: *const u32; + | --------------------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:212:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub static mut EXTERNAL_STATIC_MUT: *mut u32; + | --------------------------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:6:1 + | +LL | #![no_link] + | ^^^^^^^^^^^ not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:22:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub static GLOBAL: u32 = 42; + | ---------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:25:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub static mut GLOBAL_MUT: u32 = 42; + | ------------------------------------ not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:28:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub const CONST: u32 = 42; + | -------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:31:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | use ::core::fmt::Debug; + | ----------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:34:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | trait TraitAlias = Debug; + | ------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:37:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub type TypeAlias = u32; + | ------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:40:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub struct Struct< +LL | | #[no_link] 'lt, +LL | | #[no_link] T> +... | +LL | | pub generic_field: &'lt T, +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:42:9 + | +LL | #[no_link] 'lt, + | ^^^^^^^^^^ --- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:43:9 + | +LL | #[no_link] T> + | ^^^^^^^^^^ - not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:45:9 + | +LL | #[no_link] + | ^^^^^^^^^^ + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:47:9 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:51:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | pub struct TupleStruct(#[no_link] pub u32); + | ------------------------------------------- not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:52:28 + | +LL | pub struct TupleStruct(#[no_link] pub u32); + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:54:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub enum Enum { +LL | | #[no_link] +LL | | FieldVariant { +LL | | #[no_link] +... | +LL | | TupleVariant(#[no_link] u32), +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:56:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / FieldVariant { +LL | | #[no_link] +LL | | field: u32, +LL | | }, + | |_________- not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:58:13 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:61:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | TupleVariant(#[no_link] u32), + | ---------------------------- not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:62:22 + | +LL | TupleVariant(#[no_link] u32), + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:64:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub union Union { +LL | | #[no_link] +LL | | pub field: u32, +LL | | } + | |_____- not an `extern crate` item + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:66:9 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:70:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / impl<'lt, T> Struct<'lt, T> { +LL | | #![no_link] +... | +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:72:9 + | +LL | / impl<'lt, T> Struct<'lt, T> { +LL | | #![no_link] + | | ^^^^^^^^^^^ +... | +LL | | } + | |_____- not an `extern crate` item + +warning: unused attribute + --> $DIR/no_link.rs:72:9 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:70:5 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:89:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / impl< +LL | | #[no_link] 'lt, +LL | | #[no_link] T +LL | | > Drop for Struct<'lt, T> { +... | +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:91:9 + | +LL | #[no_link] 'lt, + | ^^^^^^^^^^ --- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:92:9 + | +LL | #[no_link] T + | ^^^^^^^^^^ - not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:100:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub fn function< +LL | | #[no_link] const N: usize +LL | | >(arg: u32) -> u32 { +LL | | #![no_link] +... | +LL | | arg +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:104:9 + | +LL | / pub fn function< +LL | | #[no_link] const N: usize +LL | | >(arg: u32) -> u32 { +LL | | #![no_link] + | | ^^^^^^^^^^^ +... | +LL | | arg +LL | | } + | |_____- not an `extern crate` item + +warning: unused attribute + --> $DIR/no_link.rs:104:9 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:100:5 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:102:9 + | +LL | #[no_link] const N: usize + | ^^^^^^^^^^ -------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:110:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub trait Trait { +LL | | #[no_link] +LL | | fn trait_method() {} +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:112:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | fn trait_method() {} + | -------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:76:9 + | +LL | ... #[no_link] + | ^^^^^^^^^^ +LL | / ... pub fn method(#[no_link] &mut self) { +LL | | ... +LL | | ... #[no_link] +... | +LL | | ... } + | |_______- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:77:23 + | +LL | ... pub fn method(#[no_link] &mut self) { + | ^^^^^^^^^^ --------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:79:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | +LL | self.struct_field = 73; + | ----------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:84:9 + | +LL | ... #[no_link] + | ^^^^^^^^^^ +LL | ... pub fn static_method(#[no_link] _arg: u32) {} + | --------------------------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:85:30 + | +LL | ... pub fn static_method(#[no_link] _arg: u32) {} + | ^^^^^^^^^^---------- + | | + | not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:94:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / fn drop(&mut self) { +LL | | // .. +LL | | } + | |_________- not an `extern crate` item + +error: aborting due to 66 previous errors; 13 warnings emitted + +For more information about this error, try `rustc --explain E0658`. From ea048627c89fc7b4e1c7f2f2e9a04e3c4dcc4f01 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 12 May 2025 22:02:26 +0200 Subject: [PATCH 2/5] Add attrs on function/closure params --- tests/ui/attributes/positions/README.md | 16 ++-- tests/ui/attributes/positions/must_use.rs | 16 ++-- tests/ui/attributes/positions/must_use.stderr | 50 ++++++++++++- tests/ui/attributes/positions/no_link.rs | 16 ++-- tests/ui/attributes/positions/no_link.stderr | 74 ++++++++++++++++--- 5 files changed, 137 insertions(+), 35 deletions(-) diff --git a/tests/ui/attributes/positions/README.md b/tests/ui/attributes/positions/README.md index c885c5f84f5d5..e11dea433c734 100644 --- a/tests/ui/attributes/positions/README.md +++ b/tests/ui/attributes/positions/README.md @@ -152,12 +152,12 @@ pub mod module { fn main() { let _closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental //~^ WARN - | _arg: u32| {}; - + | #[ATTRIBUTE] _arg: u32| {}; //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ ERROR let _move_closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental //~^ WARN - move | _arg: u32| {}; - + move | #[ATTRIBUTE] _arg: u32| {}; //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + //~^ ERROR #[ATTRIBUTE] //~ WARN { #![ATTRIBUTE] //~ WARN @@ -236,8 +236,8 @@ unsafe extern "C" { #[ATTRIBUTE] //~ WARN pub fn external_function( - arg: *mut u8, - ... + #[ATTRIBUTE] arg: *mut u8, //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + #[ATTRIBUTE] ... //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters ); #[ATTRIBUTE] //~ WARN @@ -248,8 +248,8 @@ unsafe extern "C" { } #[ATTRIBUTE] //~ WARN -pub unsafe extern "C" fn abi_function(_: u32) {} - +pub unsafe extern "C" fn abi_function(#[ATTRIBUTE] _: u32) {} //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters +//~^ ERROR #[ATTRIBUTE] //~ WARN #[macro_export] macro_rules! my_macro { diff --git a/tests/ui/attributes/positions/must_use.rs b/tests/ui/attributes/positions/must_use.rs index eaa37547303bb..449914c0d933b 100644 --- a/tests/ui/attributes/positions/must_use.rs +++ b/tests/ui/attributes/positions/must_use.rs @@ -118,12 +118,12 @@ pub mod module { fn main() { let _closure = #[must_use] //~ ERROR attributes on expressions are experimental //~^ WARN - | _arg: u32| {}; - + | #[must_use] _arg: u32| {}; //~ ERROR + //~^ WARN let _move_closure = #[must_use] //~ ERROR attributes on expressions are experimental //~^ WARN - move | _arg: u32| {}; - + move | #[must_use] _arg: u32| {}; //~ ERROR + //~^ WARN #[must_use] //~ WARN { #![must_use] //~ WARN @@ -202,8 +202,8 @@ unsafe extern "C" { #[must_use] // OK pub fn external_function( - arg: *mut u8, - ... + #[must_use] arg: *mut u8, //~ ERROR + #[must_use] ... //~ ERROR ); #[must_use] //~ WARN @@ -214,8 +214,8 @@ unsafe extern "C" { } #[must_use] // OK -pub unsafe extern "C" fn abi_function(_: u32) {} - +pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} //~ ERROR +//~^ WARN #[must_use] //~ WARN #[macro_export] macro_rules! my_macro { diff --git a/tests/ui/attributes/positions/must_use.stderr b/tests/ui/attributes/positions/must_use.stderr index 6a45f9ac6fcbf..e0bb208fa1f03 100644 --- a/tests/ui/attributes/positions/must_use.stderr +++ b/tests/ui/attributes/positions/must_use.stderr @@ -60,6 +60,36 @@ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed LL | ... pub fn static_method(#[must_use] _arg: u32) {} | ^^^^^^^^^^^ +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:121:7 + | +LL | | #[must_use] _arg: u32| {}; + | ^^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:125:12 + | +LL | move | #[must_use] _arg: u32| {}; + | ^^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:205:9 + | +LL | #[must_use] arg: *mut u8, + | ^^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:206:9 + | +LL | #[must_use] ... + | ^^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/must_use.rs:217:39 + | +LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} + | ^^^^^^^^^^^ + error[E0658]: trait aliases are experimental --> $DIR/must_use.rs:35:5 | @@ -119,12 +149,24 @@ warning: `#[must_use]` has no effect when applied to a closure LL | let _closure = #[must_use] | ^^^^^^^^^^^ +warning: `#[must_use]` has no effect when applied to a function param + --> $DIR/must_use.rs:121:7 + | +LL | | #[must_use] _arg: u32| {}; + | ^^^^^^^^^^^ + warning: `#[must_use]` has no effect when applied to a closure --> $DIR/must_use.rs:123:25 | LL | let _move_closure = #[must_use] | ^^^^^^^^^^^ +warning: `#[must_use]` has no effect when applied to a function param + --> $DIR/must_use.rs:125:12 + | +LL | move | #[must_use] _arg: u32| {}; + | ^^^^^^^^^^^ + warning: `#[must_use]` has no effect when applied to an expression --> $DIR/must_use.rs:127:5 | @@ -259,6 +301,12 @@ 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: `#[must_use]` has no effect when applied to a function param + --> $DIR/must_use.rs:217:39 + | +LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} + | ^^^^^^^^^^^ + warning: `#[must_use]` has no effect when applied to a macro def --> $DIR/must_use.rs:219:1 | @@ -465,6 +513,6 @@ warning: `#[must_use]` has no effect when applied to a provided trait method LL | #[must_use] | ^^^^^^^^^^^ -error: aborting due to 8 previous errors; 59 warnings emitted +error: aborting due to 13 previous errors; 62 warnings emitted For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/attributes/positions/no_link.rs b/tests/ui/attributes/positions/no_link.rs index 832d59b48c801..07524734502bc 100644 --- a/tests/ui/attributes/positions/no_link.rs +++ b/tests/ui/attributes/positions/no_link.rs @@ -118,12 +118,12 @@ pub mod module { fn main() { let _closure = #[no_link] //~ ERROR attributes on expressions are experimental //~^ ERROR - | _arg: u32| {}; - + | #[no_link] _arg: u32| {}; //~ ERROR + //~^ ERROR let _move_closure = #[no_link] //~ ERROR attributes on expressions are experimental //~^ ERROR - move | _arg: u32| {}; - + move | #[no_link] _arg: u32| {}; //~ ERROR + //~^ ERROR #[no_link] //~ ERROR { #![no_link] //~ ERROR @@ -202,8 +202,8 @@ unsafe extern "C" { #[no_link] //~ ERROR pub fn external_function( - arg: *mut u8, - ... + #[no_link] arg: *mut u8, //~ ERROR + #[no_link] ... //~ ERROR ); #[no_link] //~ ERROR @@ -214,8 +214,8 @@ unsafe extern "C" { } #[no_link] //~ ERROR -pub unsafe extern "C" fn abi_function(_: u32) {} - +pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} //~ ERROR +//~^ ERROR #[no_link] //~ WARN #[macro_export] macro_rules! my_macro { diff --git a/tests/ui/attributes/positions/no_link.stderr b/tests/ui/attributes/positions/no_link.stderr index b21853a723560..f2b2f5e22fd2b 100644 --- a/tests/ui/attributes/positions/no_link.stderr +++ b/tests/ui/attributes/positions/no_link.stderr @@ -60,6 +60,36 @@ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed LL | ... pub fn static_method(#[no_link] _arg: u32) {} | ^^^^^^^^^^ +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:121:7 + | +LL | | #[no_link] _arg: u32| {}; + | ^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:125:12 + | +LL | move | #[no_link] _arg: u32| {}; + | ^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:205:9 + | +LL | #[no_link] arg: *mut u8, + | ^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:206:9 + | +LL | #[no_link] ... + | ^^^^^^^^^^ + +error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters + --> $DIR/no_link.rs:217:39 + | +LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} + | ^^^^^^^^^^ + error[E0658]: trait aliases are experimental --> $DIR/no_link.rs:35:5 | @@ -124,7 +154,7 @@ LL | #[no_link] LL | / fn main() { LL | | let _closure = #[no_link] LL | | -LL | | | _arg: u32| {}; +LL | | | #[no_link] _arg: u32| {}; ... | LL | | } | |_- not an `extern crate` item @@ -135,8 +165,16 @@ error: attribute should be applied to an `extern crate` item LL | let _closure = #[no_link] | ^^^^^^^^^^ LL | -LL | | _arg: u32| {}; - | --------------- not an `extern crate` item +LL | | #[no_link] _arg: u32| {}; + | -------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:121:7 + | +LL | | #[no_link] _arg: u32| {}; + | ^^^^^^^^^^---------- + | | + | not an `extern crate` item error: attribute should be applied to an `extern crate` item --> $DIR/no_link.rs:123:25 @@ -144,8 +182,16 @@ error: attribute should be applied to an `extern crate` item LL | let _move_closure = #[no_link] | ^^^^^^^^^^ LL | -LL | move | _arg: u32| {}; - | -------------------- not an `extern crate` item +LL | move | #[no_link] _arg: u32| {}; + | ------------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:125:12 + | +LL | move | #[no_link] _arg: u32| {}; + | ^^^^^^^^^^---------- + | | + | not an `extern crate` item error: attribute should be applied to an `extern crate` item --> $DIR/no_link.rs:127:5 @@ -347,8 +393,16 @@ error: attribute should be applied to an `extern crate` item | LL | #[no_link] | ^^^^^^^^^^ -LL | pub unsafe extern "C" fn abi_function(_: u32) {} - | ------------------------------------------------ not an `extern crate` item +LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} + | ----------------------------------------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:217:39 + | +LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} + | ^^^^^^^^^^------- + | | + | not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs --> $DIR/no_link.rs:219:1 @@ -362,8 +416,8 @@ error: attribute should be applied to an `extern crate` item LL | #[no_link] | ^^^^^^^^^^ LL | / pub fn external_function( -LL | | arg: *mut u8, -LL | | ... +LL | | #[no_link] arg: *mut u8, +LL | | #[no_link] ... LL | | ); | |______- not an `extern crate` item @@ -725,6 +779,6 @@ LL | | // .. LL | | } | |_________- not an `extern crate` item -error: aborting due to 66 previous errors; 13 warnings emitted +error: aborting due to 74 previous errors; 13 warnings emitted For more information about this error, try `rustc --explain E0658`. From 3e2f4dc70d17693ff13827d24193a4ab75a5b243 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 12 May 2025 23:03:07 +0200 Subject: [PATCH 3/5] Add inner module and const blocks --- tests/ui/attributes/positions/README.md | 21 +- tests/ui/attributes/positions/allow.rs | 18 +- tests/ui/attributes/positions/allow.stderr | 12 +- tests/ui/attributes/positions/must_use.rs | 20 +- tests/ui/attributes/positions/must_use.stderr | 175 +++++++------- tests/ui/attributes/positions/no_link.rs | 20 +- tests/ui/attributes/positions/no_link.stderr | 225 +++++++++--------- 7 files changed, 280 insertions(+), 211 deletions(-) diff --git a/tests/ui/attributes/positions/README.md b/tests/ui/attributes/positions/README.md index e11dea433c734..d0eb75d9ebb58 100644 --- a/tests/ui/attributes/positions/README.md +++ b/tests/ui/attributes/positions/README.md @@ -50,9 +50,6 @@ pub mod empty_crate; #[ATTRIBUTE] //~ WARN pub mod module { - #![ATTRIBUTE] //~ WARN - //~^ WARN unused attribute - //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! #[ATTRIBUTE] //~ WARN pub static GLOBAL: u32 = 42; @@ -146,8 +143,26 @@ pub mod module { #[ATTRIBUTE] //~ WARN fn trait_method() {} } + + fn x() { + #[ATTRIBUTE] //~ WARN + const { + // .. + } + } } +pub mod inner_module { + #![ATTRIBUTE] //~ WARN + + fn x() { + const { + #![ATTRIBUTE] //~ WARN + } + } +} + + #[ATTRIBUTE] //~ WARN fn main() { let _closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental diff --git a/tests/ui/attributes/positions/allow.rs b/tests/ui/attributes/positions/allow.rs index edaaeda3fab11..2cb13dd68fa5f 100644 --- a/tests/ui/attributes/positions/allow.rs +++ b/tests/ui/attributes/positions/allow.rs @@ -14,7 +14,6 @@ pub mod empty_crate; #[allow()] // OK pub mod module { - #![allow()] // OK #[allow()] // OK pub static GLOBAL: u32 = 42; @@ -101,6 +100,23 @@ pub mod module { #[allow()] // OK fn trait_method() {} } + + fn x() { + #[allow()] // OK + const { + // .. + } + } +} + +pub mod inner_module { + #![allow()] // OK + + fn x() { + const { + #![allow()] // OK + } + } } #[allow()] // OK diff --git a/tests/ui/attributes/positions/allow.stderr b/tests/ui/attributes/positions/allow.stderr index ef9e05cd691c0..9aa4005f6b71b 100644 --- a/tests/ui/attributes/positions/allow.stderr +++ b/tests/ui/attributes/positions/allow.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:73:13 + --> $DIR/allow.rs:72:13 | LL | #[allow()] | ^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:108:20 + --> $DIR/allow.rs:124:20 | LL | let _closure = #[allow()] | ^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _closure = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:111:25 + --> $DIR/allow.rs:127:25 | LL | let _move_closure = #[allow()] | ^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _move_closure = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:121:22 + --> $DIR/allow.rs:137:22 | LL | let _array = #[allow()] | ^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | let _array = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:127:22 + --> $DIR/allow.rs:143:22 | LL | let _tuple = #[allow()] | ^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _tuple = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: trait aliases are experimental - --> $DIR/allow.rs:32:5 + --> $DIR/allow.rs:31:5 | LL | trait TraitAlias = Debug; | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/positions/must_use.rs b/tests/ui/attributes/positions/must_use.rs index 449914c0d933b..2819b5e2afa74 100644 --- a/tests/ui/attributes/positions/must_use.rs +++ b/tests/ui/attributes/positions/must_use.rs @@ -15,9 +15,6 @@ pub mod empty_crate; #[must_use] //~ WARN pub mod module { - #![must_use] //~ WARN - //~^ WARN unused attribute - //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! #[must_use] //~ WARN pub static GLOBAL: u32 = 42; @@ -112,6 +109,23 @@ pub mod module { #[must_use] // OK fn trait_method() {} } + + fn x() { + #[must_use] //~ WARN + const { + // .. + } + } +} + +pub mod inner_module { + #![must_use] //~ WARN + + fn x() { + const { + #![must_use] //~ WARN + } + } } #[must_use] // OK diff --git a/tests/ui/attributes/positions/must_use.stderr b/tests/ui/attributes/positions/must_use.stderr index e0bb208fa1f03..4f46abcbbddf1 100644 --- a/tests/ui/attributes/positions/must_use.stderr +++ b/tests/ui/attributes/positions/must_use.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:79:13 + --> $DIR/must_use.rs:76:13 | LL | #[must_use] | ^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:119:20 + --> $DIR/must_use.rs:133:20 | LL | let _closure = #[must_use] | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _closure = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:123:25 + --> $DIR/must_use.rs:137:25 | LL | let _move_closure = #[must_use] | ^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _move_closure = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:136:22 + --> $DIR/must_use.rs:150:22 | LL | let _array = #[must_use] | ^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | let _array = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:143:22 + --> $DIR/must_use.rs:157:22 | LL | let _tuple = #[must_use] | ^^^^^^^^^^^ @@ -49,49 +49,49 @@ LL | let _tuple = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:77:23 + --> $DIR/must_use.rs:74:23 | LL | ... pub fn method(#[must_use] &mut self) { | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:85:30 + --> $DIR/must_use.rs:82:30 | LL | ... pub fn static_method(#[must_use] _arg: u32) {} | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:121:7 + --> $DIR/must_use.rs:135:7 | LL | | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:125:12 + --> $DIR/must_use.rs:139:12 | LL | move | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:205:9 + --> $DIR/must_use.rs:219:9 | LL | #[must_use] arg: *mut u8, | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:206:9 + --> $DIR/must_use.rs:220:9 | LL | #[must_use] ... | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:217:39 + --> $DIR/must_use.rs:231:39 | LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} | ^^^^^^^^^^^ error[E0658]: trait aliases are experimental - --> $DIR/must_use.rs:35:5 + --> $DIR/must_use.rs:32:5 | LL | trait TraitAlias = Debug; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -125,202 +125,189 @@ LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a module - --> $DIR/must_use.rs:18:5 + --> $DIR/must_use.rs:122:5 | LL | #![must_use] | ^^^^^^^^^^^^ -warning: unused attribute - --> $DIR/must_use.rs:18:5 - | -LL | #![must_use] - | ^^^^^^^^^^^^ help: remove this attribute - | -note: attribute also specified here - --> $DIR/must_use.rs:16:1 - | -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: `#[must_use]` has no effect when applied to a closure - --> $DIR/must_use.rs:119:20 + --> $DIR/must_use.rs:133:20 | LL | let _closure = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:121:7 + --> $DIR/must_use.rs:135:7 | LL | | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a closure - --> $DIR/must_use.rs:123:25 + --> $DIR/must_use.rs:137:25 | LL | let _move_closure = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:125:12 + --> $DIR/must_use.rs:139:12 | LL | move | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:127:5 + --> $DIR/must_use.rs:141:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:129:9 + --> $DIR/must_use.rs:143:9 | LL | #![must_use] | ^^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:129:9 + --> $DIR/must_use.rs:143:9 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:127:5 + --> $DIR/must_use.rs:141:5 | 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: `#[must_use]` has no effect when applied to a statement - --> $DIR/must_use.rs:133:9 + --> $DIR/must_use.rs:147:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:136:22 + --> $DIR/must_use.rs:150:22 | LL | let _array = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:139:13 + --> $DIR/must_use.rs:153:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:143:22 + --> $DIR/must_use.rs:157:22 | LL | let _tuple = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:146:13 + --> $DIR/must_use.rs:160:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:151:13 + --> $DIR/must_use.rs:165:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:155:13 + --> $DIR/must_use.rs:169:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:161:13 + --> $DIR/must_use.rs:175:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:166:13 + --> $DIR/must_use.rs:180:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:170:9 + --> $DIR/must_use.rs:184:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an match arm - --> $DIR/must_use.rs:172:13 + --> $DIR/must_use.rs:186:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:178:9 + --> $DIR/must_use.rs:192:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a closure - --> $DIR/must_use.rs:186:13 + --> $DIR/must_use.rs:200:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:191:5 + --> $DIR/must_use.rs:205:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign module - --> $DIR/must_use.rs:197:1 + --> $DIR/must_use.rs:211:1 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign module - --> $DIR/must_use.rs:199:5 + --> $DIR/must_use.rs:213:5 | LL | #![must_use] | ^^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:199:5 + --> $DIR/must_use.rs:213:5 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:197:1 + --> $DIR/must_use.rs:211:1 | 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: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:217:39 + --> $DIR/must_use.rs:231:39 | LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a macro def - --> $DIR/must_use.rs:219:1 + --> $DIR/must_use.rs:233:1 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign static item - --> $DIR/must_use.rs:209:5 + --> $DIR/must_use.rs:223:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign static item - --> $DIR/must_use.rs:212:5 + --> $DIR/must_use.rs:226:5 | LL | #[must_use] | ^^^^^^^^^^^ @@ -332,187 +319,199 @@ LL | #![must_use] | ^^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a static item - --> $DIR/must_use.rs:22:5 + --> $DIR/must_use.rs:19:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a static item - --> $DIR/must_use.rs:25:5 + --> $DIR/must_use.rs:22:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a constant item - --> $DIR/must_use.rs:28:5 + --> $DIR/must_use.rs:25:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a use - --> $DIR/must_use.rs:31:5 + --> $DIR/must_use.rs:28:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a trait alias - --> $DIR/must_use.rs:34:5 + --> $DIR/must_use.rs:31:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a type alias - --> $DIR/must_use.rs:37:5 + --> $DIR/must_use.rs:34:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a lifetime parameter - --> $DIR/must_use.rs:42:9 + --> $DIR/must_use.rs:39:9 | LL | #[must_use] 'lt, | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a type parameter - --> $DIR/must_use.rs:43:9 + --> $DIR/must_use.rs:40:9 | LL | #[must_use] T> | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:45:9 + --> $DIR/must_use.rs:42:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:47:9 + --> $DIR/must_use.rs:44:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:52:28 + --> $DIR/must_use.rs:49:28 | LL | pub struct TupleStruct(#[must_use] pub u32); | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a enum variant - --> $DIR/must_use.rs:56:9 + --> $DIR/must_use.rs:53:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:58:13 + --> $DIR/must_use.rs:55:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a enum variant - --> $DIR/must_use.rs:61:9 + --> $DIR/must_use.rs:58:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:62:22 + --> $DIR/must_use.rs:59:22 | LL | TupleVariant(#[must_use] u32), | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:66:9 + --> $DIR/must_use.rs:63:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an implementation block - --> $DIR/must_use.rs:70:5 + --> $DIR/must_use.rs:67:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an implementation block - --> $DIR/must_use.rs:72:9 + --> $DIR/must_use.rs:69:9 | LL | #![must_use] | ^^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:72:9 + --> $DIR/must_use.rs:69:9 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:70:5 + --> $DIR/must_use.rs:67:5 | 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: `#[must_use]` has no effect when applied to an implementation block - --> $DIR/must_use.rs:89:5 + --> $DIR/must_use.rs:86:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a lifetime parameter - --> $DIR/must_use.rs:91:9 + --> $DIR/must_use.rs:88:9 | LL | #[must_use] 'lt, | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a type parameter - --> $DIR/must_use.rs:92:9 + --> $DIR/must_use.rs:89:9 | LL | #[must_use] T | ^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:104:9 + --> $DIR/must_use.rs:101:9 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:100:5 + --> $DIR/must_use.rs:97:5 | LL | #[must_use] // OK | ^^^^^^^^^^^ = 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]` has no effect when applied to a const parameter - --> $DIR/must_use.rs:102:9 + --> $DIR/must_use.rs:99:9 | LL | #[must_use] const N: usize | ^^^^^^^^^^^ +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:114:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:77:23 + --> $DIR/must_use.rs:74:23 | LL | ... pub fn method(#[must_use] &mut self) { | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:79:13 + --> $DIR/must_use.rs:76:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:85:30 + --> $DIR/must_use.rs:82:30 | LL | ... pub fn static_method(#[must_use] _arg: u32) {} | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a provided trait method - --> $DIR/must_use.rs:94:9 + --> $DIR/must_use.rs:91:9 | LL | #[must_use] | ^^^^^^^^^^^ -error: aborting due to 13 previous errors; 62 warnings emitted +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:126:13 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +error: aborting due to 13 previous errors; 63 warnings emitted For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/attributes/positions/no_link.rs b/tests/ui/attributes/positions/no_link.rs index 07524734502bc..84513fc313f1e 100644 --- a/tests/ui/attributes/positions/no_link.rs +++ b/tests/ui/attributes/positions/no_link.rs @@ -15,9 +15,6 @@ pub mod empty_crate; #[no_link] //~ ERROR pub mod module { - #![no_link] //~ ERROR - //~^ WARN unused attribute - #[no_link] //~ ERROR pub static GLOBAL: u32 = 42; @@ -112,6 +109,23 @@ pub mod module { #[no_link] //~ ERROR fn trait_method() {} } + + fn x() { + #[no_link] //~ ERROR + const { + // .. + } + } +} + +pub mod inner_module { + #![no_link] //~ ERROR + + fn x(){ + const { + #![no_link] //~ ERROR + } + } } #[no_link] //~ ERROR diff --git a/tests/ui/attributes/positions/no_link.stderr b/tests/ui/attributes/positions/no_link.stderr index f2b2f5e22fd2b..4fc87ea574dd9 100644 --- a/tests/ui/attributes/positions/no_link.stderr +++ b/tests/ui/attributes/positions/no_link.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:79:13 + --> $DIR/no_link.rs:76:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:119:20 + --> $DIR/no_link.rs:133:20 | LL | let _closure = #[no_link] | ^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _closure = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:123:25 + --> $DIR/no_link.rs:137:25 | LL | let _move_closure = #[no_link] | ^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _move_closure = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:136:22 + --> $DIR/no_link.rs:150:22 | LL | let _array = #[no_link] | ^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | let _array = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:143:22 + --> $DIR/no_link.rs:157:22 | LL | let _tuple = #[no_link] | ^^^^^^^^^^ @@ -49,49 +49,49 @@ LL | let _tuple = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:77:23 + --> $DIR/no_link.rs:74:23 | LL | ... pub fn method(#[no_link] &mut self) { | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:85:30 + --> $DIR/no_link.rs:82:30 | LL | ... pub fn static_method(#[no_link] _arg: u32) {} | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:121:7 + --> $DIR/no_link.rs:135:7 | LL | | #[no_link] _arg: u32| {}; | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:125:12 + --> $DIR/no_link.rs:139:12 | LL | move | #[no_link] _arg: u32| {}; | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:205:9 + --> $DIR/no_link.rs:219:9 | LL | #[no_link] arg: *mut u8, | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:206:9 + --> $DIR/no_link.rs:220:9 | LL | #[no_link] ... | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:217:39 + --> $DIR/no_link.rs:231:39 | LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | ^^^^^^^^^^ error[E0658]: trait aliases are experimental - --> $DIR/no_link.rs:35:5 + --> $DIR/no_link.rs:32:5 | LL | trait TraitAlias = Debug; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,40 +114,27 @@ error: attribute should be applied to an `extern crate` item LL | #[no_link] | ^^^^^^^^^^ LL | / pub mod module { -LL | | #![no_link] +LL | | +LL | | #[no_link] +LL | | pub static GLOBAL: u32 = 42; ... | LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:18:5 + --> $DIR/no_link.rs:122:5 | -LL | / pub mod module { +LL | / pub mod inner_module { LL | | #![no_link] | | ^^^^^^^^^^^ +LL | | +LL | | fn x(){ ... | LL | | } | |_- not an `extern crate` item -warning: unused attribute - --> $DIR/no_link.rs:18:5 - | -LL | #![no_link] - | ^^^^^^^^^^^ help: remove this attribute - | -note: attribute also specified here - --> $DIR/no_link.rs:16:1 - | -LL | #[no_link] - | ^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/no_link.rs:4:9 - | -LL | #![warn(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ - error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:117:1 + --> $DIR/no_link.rs:131:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -160,7 +147,7 @@ LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:119:20 + --> $DIR/no_link.rs:133:20 | LL | let _closure = #[no_link] | ^^^^^^^^^^ @@ -169,7 +156,7 @@ LL | | #[no_link] _arg: u32| {}; | -------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:121:7 + --> $DIR/no_link.rs:135:7 | LL | | #[no_link] _arg: u32| {}; | ^^^^^^^^^^---------- @@ -177,7 +164,7 @@ LL | | #[no_link] _arg: u32| {}; | not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:123:25 + --> $DIR/no_link.rs:137:25 | LL | let _move_closure = #[no_link] | ^^^^^^^^^^ @@ -186,7 +173,7 @@ LL | move | #[no_link] _arg: u32| {}; | ------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:125:12 + --> $DIR/no_link.rs:139:12 | LL | move | #[no_link] _arg: u32| {}; | ^^^^^^^^^^---------- @@ -194,7 +181,7 @@ LL | move | #[no_link] _arg: u32| {}; | not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:127:5 + --> $DIR/no_link.rs:141:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -206,7 +193,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:129:9 + --> $DIR/no_link.rs:143:9 | LL | / { LL | | #![no_link] @@ -217,19 +204,24 @@ LL | | } | |_____- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:129:9 + --> $DIR/no_link.rs:143:9 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:127:5 + --> $DIR/no_link.rs:141:5 | LL | #[no_link] | ^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/no_link.rs:4:9 + | +LL | #![warn(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:133:9 + --> $DIR/no_link.rs:147:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -237,7 +229,7 @@ LL | let variable = 42_u32; | ---------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:136:22 + --> $DIR/no_link.rs:150:22 | LL | let _array = #[no_link] | ^^^^^^^^^^ @@ -250,7 +242,7 @@ LL | | ]; | |_________- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:139:13 + --> $DIR/no_link.rs:153:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -258,7 +250,7 @@ LL | 1, | - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:143:22 + --> $DIR/no_link.rs:157:22 | LL | let _tuple = #[no_link] | ^^^^^^^^^^ @@ -271,7 +263,7 @@ LL | | ); | |_________- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:146:13 + --> $DIR/no_link.rs:160:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -279,7 +271,7 @@ LL | 1, | - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:151:13 + --> $DIR/no_link.rs:165:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -287,7 +279,7 @@ LL | 2, | - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:155:13 + --> $DIR/no_link.rs:169:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -295,7 +287,7 @@ LL | struct_field: 42, | ---------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:161:13 + --> $DIR/no_link.rs:175:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -303,7 +295,7 @@ LL | field: 42, | --------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:166:13 + --> $DIR/no_link.rs:180:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -311,7 +303,7 @@ LL | 42, | -- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:170:9 + --> $DIR/no_link.rs:184:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -322,13 +314,13 @@ LL | | } | |_________- not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:172:13 + --> $DIR/no_link.rs:186:13 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:178:9 + --> $DIR/no_link.rs:192:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -336,7 +328,7 @@ LL | tail | ---- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:186:13 + --> $DIR/no_link.rs:200:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -344,7 +336,7 @@ LL | || {}, | ----- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:191:5 + --> $DIR/no_link.rs:205:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -354,7 +346,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:197:1 + --> $DIR/no_link.rs:211:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -366,7 +358,7 @@ LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:199:5 + --> $DIR/no_link.rs:213:5 | LL | / unsafe extern "C" { LL | | #![no_link] @@ -377,19 +369,19 @@ LL | | } | |_- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:199:5 + --> $DIR/no_link.rs:213:5 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:197:1 + --> $DIR/no_link.rs:211:1 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:216:1 + --> $DIR/no_link.rs:230:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -397,7 +389,7 @@ LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | ----------------------------------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:217:39 + --> $DIR/no_link.rs:231:39 | LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | ^^^^^^^^^^------- @@ -405,13 +397,13 @@ LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:219:1 + --> $DIR/no_link.rs:233:1 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:203:5 + --> $DIR/no_link.rs:217:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -422,7 +414,7 @@ LL | | ); | |______- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:209:5 + --> $DIR/no_link.rs:223:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -430,7 +422,7 @@ LL | pub static EXTERNAL_STATIC: *const u32; | --------------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:212:5 + --> $DIR/no_link.rs:226:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -444,7 +436,7 @@ LL | #![no_link] | ^^^^^^^^^^^ not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:22:5 + --> $DIR/no_link.rs:19:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -452,7 +444,7 @@ LL | pub static GLOBAL: u32 = 42; | ---------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:25:5 + --> $DIR/no_link.rs:22:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -460,7 +452,7 @@ LL | pub static mut GLOBAL_MUT: u32 = 42; | ------------------------------------ not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:28:5 + --> $DIR/no_link.rs:25:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -468,7 +460,7 @@ LL | pub const CONST: u32 = 42; | -------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:31:5 + --> $DIR/no_link.rs:28:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -476,7 +468,7 @@ LL | use ::core::fmt::Debug; | ----------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:34:5 + --> $DIR/no_link.rs:31:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -484,7 +476,7 @@ LL | trait TraitAlias = Debug; | ------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:37:5 + --> $DIR/no_link.rs:34:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -492,7 +484,7 @@ LL | pub type TypeAlias = u32; | ------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:40:5 + --> $DIR/no_link.rs:37:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -505,31 +497,31 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:42:9 + --> $DIR/no_link.rs:39:9 | LL | #[no_link] 'lt, | ^^^^^^^^^^ --- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:43:9 + --> $DIR/no_link.rs:40:9 | LL | #[no_link] T> | ^^^^^^^^^^ - not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:45:9 + --> $DIR/no_link.rs:42:9 | LL | #[no_link] | ^^^^^^^^^^ warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:47:9 + --> $DIR/no_link.rs:44:9 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:51:5 + --> $DIR/no_link.rs:48:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -537,13 +529,13 @@ LL | pub struct TupleStruct(#[no_link] pub u32); | ------------------------------------------- not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:52:28 + --> $DIR/no_link.rs:49:28 | LL | pub struct TupleStruct(#[no_link] pub u32); | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:54:5 + --> $DIR/no_link.rs:51:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -557,7 +549,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:56:9 + --> $DIR/no_link.rs:53:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -568,13 +560,13 @@ LL | | }, | |_________- not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:58:13 + --> $DIR/no_link.rs:55:13 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:61:9 + --> $DIR/no_link.rs:58:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -582,13 +574,13 @@ LL | TupleVariant(#[no_link] u32), | ---------------------------- not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:62:22 + --> $DIR/no_link.rs:59:22 | LL | TupleVariant(#[no_link] u32), | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:64:5 + --> $DIR/no_link.rs:61:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -599,13 +591,13 @@ LL | | } | |_____- not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:66:9 + --> $DIR/no_link.rs:63:9 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:70:5 + --> $DIR/no_link.rs:67:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -616,7 +608,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:72:9 + --> $DIR/no_link.rs:69:9 | LL | / impl<'lt, T> Struct<'lt, T> { LL | | #![no_link] @@ -626,19 +618,19 @@ LL | | } | |_____- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:72:9 + --> $DIR/no_link.rs:69:9 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:70:5 + --> $DIR/no_link.rs:67:5 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:89:5 + --> $DIR/no_link.rs:86:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -651,19 +643,19 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:91:9 + --> $DIR/no_link.rs:88:9 | LL | #[no_link] 'lt, | ^^^^^^^^^^ --- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:92:9 + --> $DIR/no_link.rs:89:9 | LL | #[no_link] T | ^^^^^^^^^^ - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:100:5 + --> $DIR/no_link.rs:97:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -677,7 +669,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:104:9 + --> $DIR/no_link.rs:101:9 | LL | / pub fn function< LL | | #[no_link] const N: usize @@ -690,25 +682,25 @@ LL | | } | |_____- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:104:9 + --> $DIR/no_link.rs:101:9 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:100:5 + --> $DIR/no_link.rs:97:5 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:102:9 + --> $DIR/no_link.rs:99:9 | LL | #[no_link] const N: usize | ^^^^^^^^^^ -------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:110:5 + --> $DIR/no_link.rs:107:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -719,7 +711,17 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:112:9 + --> $DIR/no_link.rs:114:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / const { +LL | | // .. +LL | | } + | |_________- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:109:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -727,7 +729,7 @@ LL | fn trait_method() {} | -------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:76:9 + --> $DIR/no_link.rs:73:9 | LL | ... #[no_link] | ^^^^^^^^^^ @@ -739,13 +741,13 @@ LL | | ... } | |_______- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:77:23 + --> $DIR/no_link.rs:74:23 | LL | ... pub fn method(#[no_link] &mut self) { | ^^^^^^^^^^ --------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:79:13 + --> $DIR/no_link.rs:76:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -754,7 +756,7 @@ LL | self.struct_field = 73; | ----------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:84:9 + --> $DIR/no_link.rs:81:9 | LL | ... #[no_link] | ^^^^^^^^^^ @@ -762,7 +764,7 @@ LL | ... pub fn static_method(#[no_link] _arg: u32) {} | --------------------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:85:30 + --> $DIR/no_link.rs:82:30 | LL | ... pub fn static_method(#[no_link] _arg: u32) {} | ^^^^^^^^^^---------- @@ -770,7 +772,7 @@ LL | ... pub fn static_method(#[no_link] _arg: u32) {} | not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:94:9 + --> $DIR/no_link.rs:91:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -779,6 +781,15 @@ LL | | // .. LL | | } | |_________- not an `extern crate` item -error: aborting due to 74 previous errors; 13 warnings emitted +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:126:13 + | +LL | / const { +LL | | #![no_link] + | | ^^^^^^^^^^^ +LL | | } + | |_________- not an `extern crate` item + +error: aborting due to 76 previous errors; 12 warnings emitted For more information about this error, try `rustc --explain E0658`. From 89c28cde0062557ab8eb63910722769d0a4333f5 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 12 May 2025 23:11:04 +0200 Subject: [PATCH 4/5] Fully quote the comment --- tests/ui/attributes/positions/README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/ui/attributes/positions/README.md b/tests/ui/attributes/positions/README.md index d0eb75d9ebb58..97656b8dd3429 100644 --- a/tests/ui/attributes/positions/README.md +++ b/tests/ui/attributes/positions/README.md @@ -13,12 +13,16 @@ or: // FIXME: This can be used on stable but shouldn't. ``` -Or perhaps you've seen discussions getting derailed by comments like: - -```text -I discovered today that the following code already compiles on stable since at least Rust 1.31 -... -``` +Or perhaps you've seen a discussion get derailed by a [comment](https://github.com/rust-lang/rust/issues/127436#issuecomment-2576134477) like: + +> Amanieu and I discovered today that the following code already compiles on stable since at least Rust 1.31. I suspect that the `#[cold]` attribute is getting picked up as an argument-level attribute (similar to `#[cfg(…)]` being supported on arguments) and not as an expression attribute on the closure expression, and consequently being ignored as opposed to actually making the closure cold. If that's indeed what is happening, consider whether this case needs to be fixed before stabilizing attribute syntax on closures. +> ```rust +> fn main() { +> f(#[cold] || {}); +> } +> +> fn f(_: impl Fn()) {} +> ``` This is largely because our coverage of attributes and where they're allowed is very poor. This test suite attempts to consistently and exhaustively check attributes in various positions. From d9892dabb5bf9071e15a4e11b6f09af3fe3e716a Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 12 May 2025 23:59:50 +0200 Subject: [PATCH 5/5] Split inner impl block and method --- tests/ui/attributes/positions/README.md | 13 +- tests/ui/attributes/positions/allow.rs | 10 +- tests/ui/attributes/positions/allow.stderr | 8 +- tests/ui/attributes/positions/must_use.rs | 11 +- tests/ui/attributes/positions/must_use.stderr | 137 ++++++-------- tests/ui/attributes/positions/no_link.rs | 9 +- tests/ui/attributes/positions/no_link.stderr | 179 +++++++++--------- 7 files changed, 189 insertions(+), 178 deletions(-) diff --git a/tests/ui/attributes/positions/README.md b/tests/ui/attributes/positions/README.md index 97656b8dd3429..5cb5f50b55d1a 100644 --- a/tests/ui/attributes/positions/README.md +++ b/tests/ui/attributes/positions/README.md @@ -20,7 +20,7 @@ Or perhaps you've seen a discussion get derailed by a [comment](https://github.c > fn main() { > f(#[cold] || {}); > } -> +> > fn f(_: impl Fn()) {} > ``` @@ -105,9 +105,6 @@ pub mod module { #[ATTRIBUTE] //~ WARN impl<'lt, T> Struct<'lt, T> { - #![ATTRIBUTE] //~ WARN - //~^ WARN unused attribute - //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! #[ATTRIBUTE] //~ WARN pub fn method(#[ATTRIBUTE] &mut self) { //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters @@ -159,6 +156,14 @@ pub mod module { pub mod inner_module { #![ATTRIBUTE] //~ WARN + impl<'lt, T> super::module::Struct<'lt, T> { + #![ATTRIBUTE] //~ WARN + + pub fn inner_method(&mut self) { + #![ATTRIBUTE] //~ ERROR + } + } + fn x() { const { #![ATTRIBUTE] //~ WARN diff --git a/tests/ui/attributes/positions/allow.rs b/tests/ui/attributes/positions/allow.rs index 2cb13dd68fa5f..7d9b8edea74a1 100644 --- a/tests/ui/attributes/positions/allow.rs +++ b/tests/ui/attributes/positions/allow.rs @@ -65,7 +65,7 @@ pub mod module { #[allow()] // OK impl<'lt, T> Struct<'lt, T> { - #![allow()] // OK + #[allow()] // OK pub fn method(#[allow()] &mut self) { // OK @@ -112,6 +112,14 @@ pub mod module { pub mod inner_module { #![allow()] // OK + impl<'lt, T> super::module::Struct<'lt, T> { + #![allow()] // OK + + pub fn inner_method(&mut self) { + #![allow()] // OK + } + } + fn x() { const { #![allow()] // OK diff --git a/tests/ui/attributes/positions/allow.stderr b/tests/ui/attributes/positions/allow.stderr index 9aa4005f6b71b..7cb34316a8404 100644 --- a/tests/ui/attributes/positions/allow.stderr +++ b/tests/ui/attributes/positions/allow.stderr @@ -9,7 +9,7 @@ LL | #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:124:20 + --> $DIR/allow.rs:132:20 | LL | let _closure = #[allow()] | ^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _closure = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:127:25 + --> $DIR/allow.rs:135:25 | LL | let _move_closure = #[allow()] | ^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _move_closure = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:137:22 + --> $DIR/allow.rs:145:22 | LL | let _array = #[allow()] | ^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | let _array = #[allow()] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/allow.rs:143:22 + --> $DIR/allow.rs:151:22 | LL | let _tuple = #[allow()] | ^^^^^^^^^^ diff --git a/tests/ui/attributes/positions/must_use.rs b/tests/ui/attributes/positions/must_use.rs index 2819b5e2afa74..01540b395c8c1 100644 --- a/tests/ui/attributes/positions/must_use.rs +++ b/tests/ui/attributes/positions/must_use.rs @@ -66,9 +66,6 @@ pub mod module { #[must_use] //~ WARN impl<'lt, T> Struct<'lt, T> { - #![must_use] //~ WARN - //~^ WARN unused attribute - //~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! #[must_use] // OK pub fn method(#[must_use] &mut self) { //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters @@ -121,6 +118,14 @@ pub mod module { pub mod inner_module { #![must_use] //~ WARN + impl<'lt, T> super::module::Struct<'lt, T> { + #![must_use] //~ WARN + + pub fn inner_method(&mut self) { + #![must_use] // OK + } + } + fn x() { const { #![must_use] //~ WARN diff --git a/tests/ui/attributes/positions/must_use.stderr b/tests/ui/attributes/positions/must_use.stderr index 4f46abcbbddf1..ce437b105cc7a 100644 --- a/tests/ui/attributes/positions/must_use.stderr +++ b/tests/ui/attributes/positions/must_use.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:76:13 + --> $DIR/must_use.rs:73:13 | LL | #[must_use] | ^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:133:20 + --> $DIR/must_use.rs:138:20 | LL | let _closure = #[must_use] | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _closure = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:137:25 + --> $DIR/must_use.rs:142:25 | LL | let _move_closure = #[must_use] | ^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _move_closure = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:150:22 + --> $DIR/must_use.rs:155:22 | LL | let _array = #[must_use] | ^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | let _array = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/must_use.rs:157:22 + --> $DIR/must_use.rs:162:22 | LL | let _tuple = #[must_use] | ^^^^^^^^^^^ @@ -49,43 +49,43 @@ LL | let _tuple = #[must_use] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:74:23 + --> $DIR/must_use.rs:71:23 | LL | ... pub fn method(#[must_use] &mut self) { | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:82:30 + --> $DIR/must_use.rs:79:30 | LL | ... pub fn static_method(#[must_use] _arg: u32) {} | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:135:7 + --> $DIR/must_use.rs:140:7 | LL | | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:139:12 + --> $DIR/must_use.rs:144:12 | LL | move | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:219:9 + --> $DIR/must_use.rs:224:9 | LL | #[must_use] arg: *mut u8, | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:220:9 + --> $DIR/must_use.rs:225:9 | LL | #[must_use] ... | ^^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/must_use.rs:231:39 + --> $DIR/must_use.rs:236:39 | LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} | ^^^^^^^^^^^ @@ -125,189 +125,189 @@ LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a module - --> $DIR/must_use.rs:122:5 + --> $DIR/must_use.rs:119:5 | LL | #![must_use] | ^^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a closure - --> $DIR/must_use.rs:133:20 + --> $DIR/must_use.rs:138:20 | LL | let _closure = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:135:7 + --> $DIR/must_use.rs:140:7 | LL | | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a closure - --> $DIR/must_use.rs:137:25 + --> $DIR/must_use.rs:142:25 | LL | let _move_closure = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:139:12 + --> $DIR/must_use.rs:144:12 | LL | move | #[must_use] _arg: u32| {}; | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:141:5 + --> $DIR/must_use.rs:146:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:143:9 + --> $DIR/must_use.rs:148:9 | LL | #![must_use] | ^^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:143:9 + --> $DIR/must_use.rs:148:9 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:141:5 + --> $DIR/must_use.rs:146:5 | 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: `#[must_use]` has no effect when applied to a statement - --> $DIR/must_use.rs:147:9 + --> $DIR/must_use.rs:152:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:150:22 + --> $DIR/must_use.rs:155:22 | LL | let _array = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:153:13 + --> $DIR/must_use.rs:158:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:157:22 + --> $DIR/must_use.rs:162:22 | LL | let _tuple = #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:160:13 + --> $DIR/must_use.rs:165:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:165:13 + --> $DIR/must_use.rs:170:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:169:13 + --> $DIR/must_use.rs:174:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a struct field - --> $DIR/must_use.rs:175:13 + --> $DIR/must_use.rs:180:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:180:13 + --> $DIR/must_use.rs:185:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:184:9 + --> $DIR/must_use.rs:189:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an match arm - --> $DIR/must_use.rs:186:13 + --> $DIR/must_use.rs:191:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:192:9 + --> $DIR/must_use.rs:197:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a closure - --> $DIR/must_use.rs:200:13 + --> $DIR/must_use.rs:205:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:205:5 + --> $DIR/must_use.rs:210:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign module - --> $DIR/must_use.rs:211:1 + --> $DIR/must_use.rs:216:1 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign module - --> $DIR/must_use.rs:213:5 + --> $DIR/must_use.rs:218:5 | LL | #![must_use] | ^^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:213:5 + --> $DIR/must_use.rs:218:5 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:211:1 + --> $DIR/must_use.rs:216:1 | 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: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:231:39 + --> $DIR/must_use.rs:236:39 | LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a macro def - --> $DIR/must_use.rs:233:1 + --> $DIR/must_use.rs:238:1 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign static item - --> $DIR/must_use.rs:223:5 + --> $DIR/must_use.rs:228:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a foreign static item - --> $DIR/must_use.rs:226:5 + --> $DIR/must_use.rs:231:5 | LL | #[must_use] | ^^^^^^^^^^^ @@ -421,97 +421,84 @@ LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an implementation block - --> $DIR/must_use.rs:69:9 - | -LL | #![must_use] - | ^^^^^^^^^^^^ - -warning: unused attribute - --> $DIR/must_use.rs:69:9 - | -LL | #![must_use] - | ^^^^^^^^^^^^ help: remove this attribute - | -note: attribute also specified here - --> $DIR/must_use.rs:67:5 - | -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: `#[must_use]` has no effect when applied to an implementation block - --> $DIR/must_use.rs:86:5 + --> $DIR/must_use.rs:83:5 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a lifetime parameter - --> $DIR/must_use.rs:88:9 + --> $DIR/must_use.rs:85:9 | LL | #[must_use] 'lt, | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a type parameter - --> $DIR/must_use.rs:89:9 + --> $DIR/must_use.rs:86:9 | LL | #[must_use] T | ^^^^^^^^^^^ warning: unused attribute - --> $DIR/must_use.rs:101:9 + --> $DIR/must_use.rs:98:9 | LL | #![must_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/must_use.rs:97:5 + --> $DIR/must_use.rs:94:5 | LL | #[must_use] // OK | ^^^^^^^^^^^ = 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]` has no effect when applied to a const parameter - --> $DIR/must_use.rs:99:9 + --> $DIR/must_use.rs:96:9 | LL | #[must_use] const N: usize | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:114:9 + --> $DIR/must_use.rs:111:9 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:74:23 + --> $DIR/must_use.rs:71:23 | LL | ... pub fn method(#[must_use] &mut self) { | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:76:13 + --> $DIR/must_use.rs:73:13 | LL | #[must_use] | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a function param - --> $DIR/must_use.rs:82:30 + --> $DIR/must_use.rs:79:30 | LL | ... pub fn static_method(#[must_use] _arg: u32) {} | ^^^^^^^^^^^ warning: `#[must_use]` has no effect when applied to a provided trait method - --> $DIR/must_use.rs:91:9 + --> $DIR/must_use.rs:88:9 | LL | #[must_use] | ^^^^^^^^^^^ +warning: `#[must_use]` has no effect when applied to an implementation block + --> $DIR/must_use.rs:122:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + warning: `#[must_use]` has no effect when applied to an expression - --> $DIR/must_use.rs:126:13 + --> $DIR/must_use.rs:131:13 | LL | #![must_use] | ^^^^^^^^^^^^ -error: aborting due to 13 previous errors; 63 warnings emitted +error: aborting due to 13 previous errors; 62 warnings emitted For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/attributes/positions/no_link.rs b/tests/ui/attributes/positions/no_link.rs index 84513fc313f1e..0e2d4bccfd270 100644 --- a/tests/ui/attributes/positions/no_link.rs +++ b/tests/ui/attributes/positions/no_link.rs @@ -66,8 +66,6 @@ pub mod module { #[no_link] //~ ERROR impl<'lt, T> Struct<'lt, T> { - #![no_link] //~ ERROR - //~^ WARN unused attribute #[no_link] //~ ERROR @@ -121,6 +119,13 @@ pub mod module { pub mod inner_module { #![no_link] //~ ERROR + impl<'lt, T> super::module::Struct<'lt, T> { + #![no_link] //~ ERROR + + pub fn inner_method(&mut self) { + #![no_link] //~ ERROR + } + } fn x(){ const { #![no_link] //~ ERROR diff --git a/tests/ui/attributes/positions/no_link.stderr b/tests/ui/attributes/positions/no_link.stderr index 4fc87ea574dd9..0ccfcde9b9674 100644 --- a/tests/ui/attributes/positions/no_link.stderr +++ b/tests/ui/attributes/positions/no_link.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:76:13 + --> $DIR/no_link.rs:74:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:133:20 + --> $DIR/no_link.rs:138:20 | LL | let _closure = #[no_link] | ^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _closure = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:137:25 + --> $DIR/no_link.rs:142:25 | LL | let _move_closure = #[no_link] | ^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _move_closure = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:150:22 + --> $DIR/no_link.rs:155:22 | LL | let _array = #[no_link] | ^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | let _array = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: attributes on expressions are experimental - --> $DIR/no_link.rs:157:22 + --> $DIR/no_link.rs:162:22 | LL | let _tuple = #[no_link] | ^^^^^^^^^^ @@ -49,43 +49,43 @@ LL | let _tuple = #[no_link] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:74:23 + --> $DIR/no_link.rs:72:23 | LL | ... pub fn method(#[no_link] &mut self) { | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:82:30 + --> $DIR/no_link.rs:80:30 | LL | ... pub fn static_method(#[no_link] _arg: u32) {} | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:135:7 + --> $DIR/no_link.rs:140:7 | LL | | #[no_link] _arg: u32| {}; | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:139:12 + --> $DIR/no_link.rs:144:12 | LL | move | #[no_link] _arg: u32| {}; | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:219:9 + --> $DIR/no_link.rs:224:9 | LL | #[no_link] arg: *mut u8, | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:220:9 + --> $DIR/no_link.rs:225:9 | LL | #[no_link] ... | ^^^^^^^^^^ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters - --> $DIR/no_link.rs:231:39 + --> $DIR/no_link.rs:236:39 | LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | ^^^^^^^^^^ @@ -122,19 +122,19 @@ LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:122:5 + --> $DIR/no_link.rs:120:5 | LL | / pub mod inner_module { LL | | #![no_link] | | ^^^^^^^^^^^ LL | | -LL | | fn x(){ +LL | | impl<'lt, T> super::module::Struct<'lt, T> { ... | LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:131:1 + --> $DIR/no_link.rs:136:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -147,7 +147,7 @@ LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:133:20 + --> $DIR/no_link.rs:138:20 | LL | let _closure = #[no_link] | ^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | | #[no_link] _arg: u32| {}; | -------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:135:7 + --> $DIR/no_link.rs:140:7 | LL | | #[no_link] _arg: u32| {}; | ^^^^^^^^^^---------- @@ -164,7 +164,7 @@ LL | | #[no_link] _arg: u32| {}; | not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:137:25 + --> $DIR/no_link.rs:142:25 | LL | let _move_closure = #[no_link] | ^^^^^^^^^^ @@ -173,7 +173,7 @@ LL | move | #[no_link] _arg: u32| {}; | ------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:139:12 + --> $DIR/no_link.rs:144:12 | LL | move | #[no_link] _arg: u32| {}; | ^^^^^^^^^^---------- @@ -181,7 +181,7 @@ LL | move | #[no_link] _arg: u32| {}; | not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:141:5 + --> $DIR/no_link.rs:146:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:143:9 + --> $DIR/no_link.rs:148:9 | LL | / { LL | | #![no_link] @@ -204,13 +204,13 @@ LL | | } | |_____- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:143:9 + --> $DIR/no_link.rs:148:9 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:141:5 + --> $DIR/no_link.rs:146:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -221,7 +221,7 @@ LL | #![warn(unused_attributes)] | ^^^^^^^^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:147:9 + --> $DIR/no_link.rs:152:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -229,7 +229,7 @@ LL | let variable = 42_u32; | ---------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:150:22 + --> $DIR/no_link.rs:155:22 | LL | let _array = #[no_link] | ^^^^^^^^^^ @@ -242,7 +242,7 @@ LL | | ]; | |_________- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:153:13 + --> $DIR/no_link.rs:158:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -250,7 +250,7 @@ LL | 1, | - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:157:22 + --> $DIR/no_link.rs:162:22 | LL | let _tuple = #[no_link] | ^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | | ); | |_________- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:160:13 + --> $DIR/no_link.rs:165:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | 1, | - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:165:13 + --> $DIR/no_link.rs:170:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | 2, | - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:169:13 + --> $DIR/no_link.rs:174:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | struct_field: 42, | ---------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:175:13 + --> $DIR/no_link.rs:180:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -295,7 +295,7 @@ LL | field: 42, | --------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:180:13 + --> $DIR/no_link.rs:185:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -303,7 +303,7 @@ LL | 42, | -- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:184:9 + --> $DIR/no_link.rs:189:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -314,13 +314,13 @@ LL | | } | |_________- not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:186:13 + --> $DIR/no_link.rs:191:13 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:192:9 + --> $DIR/no_link.rs:197:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -328,7 +328,7 @@ LL | tail | ---- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:200:13 + --> $DIR/no_link.rs:205:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -336,7 +336,7 @@ LL | || {}, | ----- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:205:5 + --> $DIR/no_link.rs:210:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -346,7 +346,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:211:1 + --> $DIR/no_link.rs:216:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -358,7 +358,7 @@ LL | | } | |_- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:213:5 + --> $DIR/no_link.rs:218:5 | LL | / unsafe extern "C" { LL | | #![no_link] @@ -369,19 +369,19 @@ LL | | } | |_- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:213:5 + --> $DIR/no_link.rs:218:5 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:211:1 + --> $DIR/no_link.rs:216:1 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:230:1 + --> $DIR/no_link.rs:235:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -389,7 +389,7 @@ LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | ----------------------------------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:231:39 + --> $DIR/no_link.rs:236:39 | LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | ^^^^^^^^^^------- @@ -397,13 +397,13 @@ LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} | not an `extern crate` item warning: `#[no_link]` is ignored on struct fields, match arms and macro defs - --> $DIR/no_link.rs:233:1 + --> $DIR/no_link.rs:238:1 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:217:5 + --> $DIR/no_link.rs:222:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -414,7 +414,7 @@ LL | | ); | |______- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:223:5 + --> $DIR/no_link.rs:228:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -422,7 +422,7 @@ LL | pub static EXTERNAL_STATIC: *const u32; | --------------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:226:5 + --> $DIR/no_link.rs:231:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -602,35 +602,15 @@ error: attribute should be applied to an `extern crate` item LL | #[no_link] | ^^^^^^^^^^ LL | / impl<'lt, T> Struct<'lt, T> { -LL | | #![no_link] +LL | | +LL | | +LL | | #[no_link] ... | LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:69:9 - | -LL | / impl<'lt, T> Struct<'lt, T> { -LL | | #![no_link] - | | ^^^^^^^^^^^ -... | -LL | | } - | |_____- not an `extern crate` item - -warning: unused attribute - --> $DIR/no_link.rs:69:9 - | -LL | #![no_link] - | ^^^^^^^^^^^ help: remove this attribute - | -note: attribute also specified here - --> $DIR/no_link.rs:67:5 - | -LL | #[no_link] - | ^^^^^^^^^^ - -error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:86:5 + --> $DIR/no_link.rs:84:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -643,19 +623,19 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:88:9 + --> $DIR/no_link.rs:86:9 | LL | #[no_link] 'lt, | ^^^^^^^^^^ --- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:89:9 + --> $DIR/no_link.rs:87:9 | LL | #[no_link] T | ^^^^^^^^^^ - not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:97:5 + --> $DIR/no_link.rs:95:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -669,7 +649,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:101:9 + --> $DIR/no_link.rs:99:9 | LL | / pub fn function< LL | | #[no_link] const N: usize @@ -682,25 +662,25 @@ LL | | } | |_____- not an `extern crate` item warning: unused attribute - --> $DIR/no_link.rs:101:9 + --> $DIR/no_link.rs:99:9 | LL | #![no_link] | ^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/no_link.rs:97:5 + --> $DIR/no_link.rs:95:5 | LL | #[no_link] | ^^^^^^^^^^ error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:99:9 + --> $DIR/no_link.rs:97:9 | LL | #[no_link] const N: usize | ^^^^^^^^^^ -------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:107:5 + --> $DIR/no_link.rs:105:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -711,7 +691,7 @@ LL | | } | |_____- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:114:9 + --> $DIR/no_link.rs:112:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -721,7 +701,7 @@ LL | | } | |_________- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:109:9 + --> $DIR/no_link.rs:107:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -729,7 +709,7 @@ LL | fn trait_method() {} | -------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:73:9 + --> $DIR/no_link.rs:71:9 | LL | ... #[no_link] | ^^^^^^^^^^ @@ -741,13 +721,13 @@ LL | | ... } | |_______- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:74:23 + --> $DIR/no_link.rs:72:23 | LL | ... pub fn method(#[no_link] &mut self) { | ^^^^^^^^^^ --------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:76:13 + --> $DIR/no_link.rs:74:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -756,7 +736,7 @@ LL | self.struct_field = 73; | ----------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:81:9 + --> $DIR/no_link.rs:79:9 | LL | ... #[no_link] | ^^^^^^^^^^ @@ -764,7 +744,7 @@ LL | ... pub fn static_method(#[no_link] _arg: u32) {} | --------------------------------------------- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:82:30 + --> $DIR/no_link.rs:80:30 | LL | ... pub fn static_method(#[no_link] _arg: u32) {} | ^^^^^^^^^^---------- @@ -772,7 +752,7 @@ LL | ... pub fn static_method(#[no_link] _arg: u32) {} | not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:91:9 + --> $DIR/no_link.rs:89:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -782,7 +762,19 @@ LL | | } | |_________- not an `extern crate` item error: attribute should be applied to an `extern crate` item - --> $DIR/no_link.rs:126:13 + --> $DIR/no_link.rs:123:9 + | +LL | / impl<'lt, T> super::module::Struct<'lt, T> { +LL | | #![no_link] + | | ^^^^^^^^^^^ +LL | | +LL | | pub fn inner_method(&mut self) { +... | +LL | | } + | |_____- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:131:13 | LL | / const { LL | | #![no_link] @@ -790,6 +782,15 @@ LL | | #![no_link] LL | | } | |_________- not an `extern crate` item -error: aborting due to 76 previous errors; 12 warnings emitted +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:126:13 + | +LL | / pub fn inner_method(&mut self) { +LL | | #![no_link] + | | ^^^^^^^^^^^ +LL | | } + | |_________- not an `extern crate` item + +error: aborting due to 77 previous errors; 11 warnings emitted For more information about this error, try `rustc --explain E0658`.