diff --git a/tests/ui/attributes/positions/README.md b/tests/ui/attributes/positions/README.md new file mode 100644 index 0000000000000..5cb5f50b55d1a --- /dev/null +++ b/tests/ui/attributes/positions/README.md @@ -0,0 +1,286 @@ +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 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. +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 + 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 + 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() {} + } + + fn x() { + #[ATTRIBUTE] //~ WARN + const { + // .. + } + } +} + +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 + } + } +} + + +#[ATTRIBUTE] //~ WARN +fn main() { + let _closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental + //~^ WARN + | #[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 | #[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 + //~^ 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( + #[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 + 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(#[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 { + () => {}; +} + +#[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..7d9b8edea74a1 --- /dev/null +++ b/tests/ui/attributes/positions/allow.rs @@ -0,0 +1,232 @@ +//@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 + 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 + 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() {} + } + + fn x() { + #[allow()] // OK + const { + // .. + } + } +} + +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 + } + } +} + +#[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..7cb34316a8404 --- /dev/null +++ b/tests/ui/attributes/positions/allow.stderr @@ -0,0 +1,63 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/allow.rs:72: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:132: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:135: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:145: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:151: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:31: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..01540b395c8c1 --- /dev/null +++ b/tests/ui/attributes/positions/must_use.rs @@ -0,0 +1,246 @@ +//@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 + 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] // 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() {} + } + + fn x() { + #[must_use] //~ WARN + const { + // .. + } + } +} + +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 + } + } +} + +#[must_use] // OK +fn main() { + let _closure = #[must_use] //~ ERROR attributes on expressions are experimental + //~^ WARN + | #[must_use] _arg: u32| {}; //~ ERROR + //~^ WARN + let _move_closure = #[must_use] //~ ERROR attributes on expressions are experimental + //~^ WARN + move | #[must_use] _arg: u32| {}; //~ ERROR + //~^ WARN + #[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( + #[must_use] arg: *mut u8, //~ ERROR + #[must_use] ... //~ ERROR + ); + + #[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(#[must_use] _: u32) {} //~ ERROR +//~^ WARN +#[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..ce437b105cc7a --- /dev/null +++ b/tests/ui/attributes/positions/must_use.stderr @@ -0,0 +1,504 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/must_use.rs:73: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:138: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:142: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:155: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:162: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: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: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: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: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: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: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:236:39 + | +LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} + | ^^^^^^^^^^^ + +error[E0658]: trait aliases are experimental + --> $DIR/must_use.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 + +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:119:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a closure + --> $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:140:7 + | +LL | | #[must_use] _arg: u32| {}; + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a closure + --> $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:144:12 + | +LL | move | #[must_use] _arg: u32| {}; + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:146:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:148:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:148:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $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:152:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $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:158:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $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:165:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $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:174:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $DIR/must_use.rs:180:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:185:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $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:191:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $DIR/must_use.rs:197:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a closure + --> $DIR/must_use.rs:205:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $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:216:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a foreign module + --> $DIR/must_use.rs:218:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:218:5 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $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: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:238:1 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a foreign static item + --> $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:231: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:19:5 + | +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 constant item + --> $DIR/must_use.rs:25:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a use + --> $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:31:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a type alias + --> $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:39:9 + | +LL | #[must_use] 'lt, + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a type parameter + --> $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:42:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $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: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:53:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $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:58:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a struct field + --> $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:63:9 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an implementation block + --> $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:83:5 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a lifetime parameter + --> $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:86:9 + | +LL | #[must_use] T + | ^^^^^^^^^^^ + +warning: unused attribute + --> $DIR/must_use.rs:98:9 + | +LL | #![must_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $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:96:9 + | +LL | #[must_use] const N: usize + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to an expression + --> $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: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:73:13 + | +LL | #[must_use] + | ^^^^^^^^^^^ + +warning: `#[must_use]` has no effect when applied to a function param + --> $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: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:131:13 + | +LL | #![must_use] + | ^^^^^^^^^^^^ + +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 new file mode 100644 index 0000000000000..0e2d4bccfd270 --- /dev/null +++ b/tests/ui/attributes/positions/no_link.rs @@ -0,0 +1,246 @@ +//@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 + 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 + 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() {} + } + + fn x() { + #[no_link] //~ ERROR + const { + // .. + } + } +} + +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 + } + } +} + +#[no_link] //~ ERROR +fn main() { + let _closure = #[no_link] //~ ERROR attributes on expressions are experimental + //~^ ERROR + | #[no_link] _arg: u32| {}; //~ ERROR + //~^ ERROR + let _move_closure = #[no_link] //~ ERROR attributes on expressions are experimental + //~^ ERROR + move | #[no_link] _arg: u32| {}; //~ ERROR + //~^ ERROR + #[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( + #[no_link] arg: *mut u8, //~ ERROR + #[no_link] ... //~ ERROR + ); + + #[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(#[no_link] _: u32) {} //~ ERROR +//~^ ERROR +#[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..0ccfcde9b9674 --- /dev/null +++ b/tests/ui/attributes/positions/no_link.stderr @@ -0,0 +1,796 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/no_link.rs:74: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:138: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:142: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:155: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:162: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: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: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: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: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: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: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:236:39 + | +LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} + | ^^^^^^^^^^ + +error[E0658]: trait aliases are experimental + --> $DIR/no_link.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: 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 | | +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:120:5 + | +LL | / pub mod inner_module { +LL | | #![no_link] + | | ^^^^^^^^^^^ +LL | | +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:136:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / fn main() { +LL | | let _closure = #[no_link] +LL | | +LL | | | #[no_link] _arg: u32| {}; +... | +LL | | } + | |_- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:138:20 + | +LL | let _closure = #[no_link] + | ^^^^^^^^^^ +LL | +LL | | #[no_link] _arg: u32| {}; + | -------------------------- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:140: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:142:25 + | +LL | let _move_closure = #[no_link] + | ^^^^^^^^^^ +LL | +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:144: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:146: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:148:9 + | +LL | / { +LL | | #![no_link] + | | ^^^^^^^^^^^ +... | +LL | | tail +LL | | } + | |_____- not an `extern crate` item + +warning: unused attribute + --> $DIR/no_link.rs:148:9 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:146: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:152: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:155: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:158: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:162: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:165: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:170: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:174: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:180: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:185: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:189: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:191:13 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:197: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:205:13 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | || {}, + | ----- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:210: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:216: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:218: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:218:5 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:216:1 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:235:1 + | +LL | #[no_link] + | ^^^^^^^^^^ +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:236: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:238:1 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:222:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / pub fn external_function( +LL | | #[no_link] arg: *mut u8, +LL | | #[no_link] ... +LL | | ); + | |______- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:228: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:231: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:19: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:22: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:25: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:28: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:31: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:34: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:37: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: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: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:42:9 + | +LL | #[no_link] + | ^^^^^^^^^^ + +warning: `#[no_link]` is ignored on struct fields, match arms and macro defs + --> $DIR/no_link.rs:44:9 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:48: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:49:28 + | +LL | pub struct TupleStruct(#[no_link] pub u32); + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:51: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:53: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:55:13 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:58: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:59:22 + | +LL | TupleVariant(#[no_link] u32), + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:61: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:63:9 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:67:5 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / impl<'lt, T> Struct<'lt, T> { +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:84: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: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: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:95: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:99: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:99:9 + | +LL | #![no_link] + | ^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/no_link.rs:95:5 + | +LL | #[no_link] + | ^^^^^^^^^^ + +error: attribute should be applied to an `extern crate` item + --> $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:105: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 | / const { +LL | | // .. +LL | | } + | |_________- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $DIR/no_link.rs:107: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:71: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: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:74: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:79: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:80: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:89:9 + | +LL | #[no_link] + | ^^^^^^^^^^ +LL | / fn drop(&mut self) { +LL | | // .. +LL | | } + | |_________- not an `extern crate` item + +error: attribute should be applied to an `extern crate` item + --> $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] + | | ^^^^^^^^^^^ +LL | | } + | |_________- not an `extern crate` item + +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`.