diff options
| author | Jonathan Brouwer <jonathantbrouwer@gmail.com> | 2025-08-16 17:13:15 +0200 |
|---|---|---|
| committer | Jonathan Brouwer <jonathantbrouwer@gmail.com> | 2025-08-19 09:03:54 +0200 |
| commit | d5dc797dceedee45842f7a8b9c69c341db895cff (patch) | |
| tree | acec4fb65226cf63d49c09a1531662c77aa2d264 /tests/ui/lint | |
| parent | c1c204d707011a1987f2a00f1d421a253f83d3a6 (diff) | |
| download | rust-d5dc797dceedee45842f7a8b9c69c341db895cff.tar.gz rust-d5dc797dceedee45842f7a8b9c69c341db895cff.zip | |
Update uitests
Diffstat (limited to 'tests/ui/lint')
| -rw-r--r-- | tests/ui/lint/unused/unused_attributes-must_use.fixed | 63 | ||||
| -rw-r--r-- | tests/ui/lint/unused/unused_attributes-must_use.rs | 63 | ||||
| -rw-r--r-- | tests/ui/lint/unused/unused_attributes-must_use.stderr | 193 |
3 files changed, 212 insertions, 107 deletions
diff --git a/tests/ui/lint/unused/unused_attributes-must_use.fixed b/tests/ui/lint/unused/unused_attributes-must_use.fixed index 80d488296ea..2e800cbff3f 100644 --- a/tests/ui/lint/unused/unused_attributes-must_use.fixed +++ b/tests/ui/lint/unused/unused_attributes-must_use.fixed @@ -4,18 +4,23 @@ #![deny(unused_attributes, unused_must_use)] #![feature(asm_experimental_arch, stmt_expr_attributes, trait_alias)] - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted extern crate std as std2; - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted mod test_mod {} - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted use std::arch::global_asm; - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted const CONST: usize = 4; - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted #[no_mangle] static STATIC: usize = 4; @@ -32,7 +37,8 @@ union U { unit: (), } - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted impl U { #[must_use] fn method() -> i32 { @@ -46,10 +52,12 @@ fn foo() -> i64 { 4 } - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted extern "Rust" { #[link_name = "STATIC"] - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on + //~| WARN previously accepted static FOREIGN_STATIC: usize; #[link_name = "foo"] @@ -60,16 +68,20 @@ extern "Rust" { //~ ERROR unused attribute global_asm!(""); - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted type UseMe = (); -fn qux< T>(_: T) {} //~ ERROR `#[must_use]` has no effect +fn qux< T>(_: T) {} //~ ERROR attribute cannot be used on +//~| WARN previously accepted #[must_use] trait Use { - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on + //~| WARN previously accepted const ASSOC_CONST: usize = 4; - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on + //~| WARN previously accepted type AssocTy; #[must_use] @@ -78,20 +90,24 @@ trait Use { } } - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted impl Use for () { type AssocTy = (); - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on + //~| WARN previously accepted fn get_four(&self) -> usize { 4 } } - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted trait Alias = Use; - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on +//~| WARN previously accepted macro_rules! cool_macro { () => { 4 @@ -99,11 +115,13 @@ macro_rules! cool_macro { } fn main() { - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on + //~| WARN previously accepted let x = || {}; x(); - let x = //~ ERROR `#[must_use]` has no effect + let x = //~ ERROR attribute cannot be used on + //~| WARN previously accepted || {}; x(); @@ -125,7 +143,8 @@ fn main() { let _ = ().get_four(); //~ ERROR that must be used match Some(4) { - //~ ERROR `#[must_use]` has no effect + //~ ERROR attribute cannot be used on + //~| WARN previously accepted Some(res) => res, None => 0, }; @@ -133,7 +152,9 @@ fn main() { struct PatternField { foo: i32, } - let s = PatternField { foo: 123 }; //~ ERROR `#[must_use]` has no effect - let PatternField { foo } = s; //~ ERROR `#[must_use]` has no effect + let s = PatternField { foo: 123 }; //~ ERROR attribute cannot be used on + //~| WARN previously accepted + let PatternField { foo } = s; //~ ERROR attribute cannot be used on + //~| WARN previously accepted let _ = foo; } diff --git a/tests/ui/lint/unused/unused_attributes-must_use.rs b/tests/ui/lint/unused/unused_attributes-must_use.rs index edefe8ed65e..c41c6c1d706 100644 --- a/tests/ui/lint/unused/unused_attributes-must_use.rs +++ b/tests/ui/lint/unused/unused_attributes-must_use.rs @@ -4,18 +4,23 @@ #![deny(unused_attributes, unused_must_use)] #![feature(asm_experimental_arch, stmt_expr_attributes, trait_alias)] -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted extern crate std as std2; -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted mod test_mod {} -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted use std::arch::global_asm; -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted const CONST: usize = 4; -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted #[no_mangle] static STATIC: usize = 4; @@ -32,7 +37,8 @@ union U { unit: (), } -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted impl U { #[must_use] fn method() -> i32 { @@ -46,10 +52,12 @@ fn foo() -> i64 { 4 } -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted extern "Rust" { #[link_name = "STATIC"] - #[must_use] //~ ERROR `#[must_use]` has no effect + #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted static FOREIGN_STATIC: usize; #[link_name = "foo"] @@ -60,16 +68,20 @@ extern "Rust" { #[must_use] //~ ERROR unused attribute global_asm!(""); -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted type UseMe = (); -fn qux<#[must_use] T>(_: T) {} //~ ERROR `#[must_use]` has no effect +fn qux<#[must_use] T>(_: T) {} //~ ERROR attribute cannot be used on +//~| WARN previously accepted #[must_use] trait Use { - #[must_use] //~ ERROR `#[must_use]` has no effect + #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted const ASSOC_CONST: usize = 4; - #[must_use] //~ ERROR `#[must_use]` has no effect + #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted type AssocTy; #[must_use] @@ -78,20 +90,24 @@ trait Use { } } -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted impl Use for () { type AssocTy = (); - #[must_use] //~ ERROR `#[must_use]` has no effect + #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted fn get_four(&self) -> usize { 4 } } -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted trait Alias = Use; -#[must_use] //~ ERROR `#[must_use]` has no effect +#[must_use] //~ ERROR attribute cannot be used on +//~| WARN previously accepted macro_rules! cool_macro { () => { 4 @@ -99,11 +115,13 @@ macro_rules! cool_macro { } fn main() { - #[must_use] //~ ERROR `#[must_use]` has no effect + #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted let x = || {}; x(); - let x = #[must_use] //~ ERROR `#[must_use]` has no effect + let x = #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted || {}; x(); @@ -125,7 +143,8 @@ fn main() { ().get_four(); //~ ERROR that must be used match Some(4) { - #[must_use] //~ ERROR `#[must_use]` has no effect + #[must_use] //~ ERROR attribute cannot be used on + //~| WARN previously accepted Some(res) => res, None => 0, }; @@ -133,7 +152,9 @@ fn main() { struct PatternField { foo: i32, } - let s = PatternField { #[must_use] foo: 123 }; //~ ERROR `#[must_use]` has no effect - let PatternField { #[must_use] foo } = s; //~ ERROR `#[must_use]` has no effect + let s = PatternField { #[must_use] foo: 123 }; //~ ERROR attribute cannot be used on + //~| WARN previously accepted + let PatternField { #[must_use] foo } = s; //~ ERROR attribute cannot be used on + //~| WARN previously accepted let _ = foo; } diff --git a/tests/ui/lint/unused/unused_attributes-must_use.stderr b/tests/ui/lint/unused/unused_attributes-must_use.stderr index 9e37f6504cc..12cc2ea56be 100644 --- a/tests/ui/lint/unused/unused_attributes-must_use.stderr +++ b/tests/ui/lint/unused/unused_attributes-must_use.stderr @@ -1,11 +1,11 @@ error: unused attribute `must_use` - --> $DIR/unused_attributes-must_use.rs:60:1 + --> $DIR/unused_attributes-must_use.rs:68:1 | LL | #[must_use] | ^^^^^^^^^^^ | note: the built-in attribute `must_use` will be ignored, since it's applied to the macro invocation `global_asm` - --> $DIR/unused_attributes-must_use.rs:61:1 + --> $DIR/unused_attributes-must_use.rs:69:1 | LL | global_asm!(""); | ^^^^^^^^^^ @@ -15,134 +15,197 @@ note: the lint level is defined here LL | #![deny(unused_attributes, unused_must_use)] | ^^^^^^^^^^^^^^^^^ -error: `#[must_use]` has no effect when applied to extern crates +error: `#[must_use]` attribute cannot be used on extern crates --> $DIR/unused_attributes-must_use.rs:7: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to modules - --> $DIR/unused_attributes-must_use.rs:10:1 +error: `#[must_use]` attribute cannot be used on modules + --> $DIR/unused_attributes-must_use.rs:11: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to use statements - --> $DIR/unused_attributes-must_use.rs:13:1 +error: `#[must_use]` attribute cannot be used on use statements + --> $DIR/unused_attributes-must_use.rs:15: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to constants - --> $DIR/unused_attributes-must_use.rs:16:1 +error: `#[must_use]` attribute cannot be used on constants + --> $DIR/unused_attributes-must_use.rs:19: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to statics - --> $DIR/unused_attributes-must_use.rs:18:1 +error: `#[must_use]` attribute cannot be used on statics + --> $DIR/unused_attributes-must_use.rs:22: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to inherent impl blocks - --> $DIR/unused_attributes-must_use.rs:35:1 +error: `#[must_use]` attribute cannot be used on inherent impl blocks + --> $DIR/unused_attributes-must_use.rs:40: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to foreign modules - --> $DIR/unused_attributes-must_use.rs:49:1 +error: `#[must_use]` attribute cannot be used on foreign modules + --> $DIR/unused_attributes-must_use.rs:55: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to type aliases - --> $DIR/unused_attributes-must_use.rs:63:1 +error: `#[must_use]` attribute cannot be used on foreign statics + --> $DIR/unused_attributes-must_use.rs:59: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits + +error: `#[must_use]` attribute cannot be used on type aliases + --> $DIR/unused_attributes-must_use.rs:71: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to type parameters - --> $DIR/unused_attributes-must_use.rs:66:8 +error: `#[must_use]` attribute cannot be used on function params + --> $DIR/unused_attributes-must_use.rs:75:8 | LL | fn qux<#[must_use] T>(_: T) {} | ^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to trait impl blocks - --> $DIR/unused_attributes-must_use.rs:81:1 +error: `#[must_use]` attribute cannot be used on associated consts + --> $DIR/unused_attributes-must_use.rs:80: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits + +error: `#[must_use]` attribute cannot be used on associated types + --> $DIR/unused_attributes-must_use.rs:83: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits + +error: `#[must_use]` attribute cannot be used on trait impl blocks + --> $DIR/unused_attributes-must_use.rs:93: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to trait aliases - --> $DIR/unused_attributes-must_use.rs:91:1 +error: `#[must_use]` attribute cannot be used on trait methods in impl blocks + --> $DIR/unused_attributes-must_use.rs:98: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! + = help: `#[must_use]` can be applied to data types, functions, unions, required trait methods, provided trait methods, inherent methods, foreign functions, traits + +error: `#[must_use]` attribute cannot be used on trait aliases + --> $DIR/unused_attributes-must_use.rs:105: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to macro defs - --> $DIR/unused_attributes-must_use.rs:94:1 +error: `#[must_use]` attribute cannot be used on macro defs + --> $DIR/unused_attributes-must_use.rs:109: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to statements - --> $DIR/unused_attributes-must_use.rs:102:5 +error: `#[must_use]` attribute cannot be used on statements + --> $DIR/unused_attributes-must_use.rs:118: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to closures - --> $DIR/unused_attributes-must_use.rs:106:13 +error: `#[must_use]` attribute cannot be used on closures + --> $DIR/unused_attributes-must_use.rs:123:13 | LL | let x = #[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! + = help: `#[must_use]` can be applied to methods, data types, functions, unions, foreign functions, traits -error: `#[must_use]` has no effect when applied to match arms - --> $DIR/unused_attributes-must_use.rs:128:9 +error: `#[must_use]` attribute cannot be used on match arms + --> $DIR/unused_attributes-must_use.rs:146:9 | 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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to struct fields - --> $DIR/unused_attributes-must_use.rs:136:28 +error: `#[must_use]` attribute cannot be used on struct fields + --> $DIR/unused_attributes-must_use.rs:155:28 | LL | let s = PatternField { #[must_use] foo: 123 }; | ^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = help: `#[must_use]` can be applied to functions, data types, unions, traits -error: `#[must_use]` has no effect when applied to pattern fields - --> $DIR/unused_attributes-must_use.rs:137:24 +error: `#[must_use]` attribute cannot be used on pattern fields + --> $DIR/unused_attributes-must_use.rs:157:24 | LL | let PatternField { #[must_use] foo } = s; | ^^^^^^^^^^^ - -error: `#[must_use]` has no effect when applied to associated consts - --> $DIR/unused_attributes-must_use.rs:70:5 | -LL | #[must_use] - | ^^^^^^^^^^^ - -error: `#[must_use]` has no effect when applied to associated types - --> $DIR/unused_attributes-must_use.rs:72:5 - | -LL | #[must_use] - | ^^^^^^^^^^^ - -error: `#[must_use]` has no effect when applied to provided trait methods - --> $DIR/unused_attributes-must_use.rs:85:5 - | -LL | #[must_use] - | ^^^^^^^^^^^ - -error: `#[must_use]` has no effect when applied to foreign statics - --> $DIR/unused_attributes-must_use.rs:52: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! + = help: `#[must_use]` can be applied to functions, data types, unions, traits error: unused `X` that must be used - --> $DIR/unused_attributes-must_use.rs:110:5 + --> $DIR/unused_attributes-must_use.rs:128:5 | LL | X; | ^ @@ -158,7 +221,7 @@ LL | let _ = X; | +++++++ error: unused `Y` that must be used - --> $DIR/unused_attributes-must_use.rs:111:5 + --> $DIR/unused_attributes-must_use.rs:129:5 | LL | Y::Z; | ^^^^ @@ -169,7 +232,7 @@ LL | let _ = Y::Z; | +++++++ error: unused `U` that must be used - --> $DIR/unused_attributes-must_use.rs:112:5 + --> $DIR/unused_attributes-must_use.rs:130:5 | LL | U { unit: () }; | ^^^^^^^^^^^^^^ @@ -180,7 +243,7 @@ LL | let _ = U { unit: () }; | +++++++ error: unused return value of `U::method` that must be used - --> $DIR/unused_attributes-must_use.rs:113:5 + --> $DIR/unused_attributes-must_use.rs:131:5 | LL | U::method(); | ^^^^^^^^^^^ @@ -191,7 +254,7 @@ LL | let _ = U::method(); | +++++++ error: unused return value of `foo` that must be used - --> $DIR/unused_attributes-must_use.rs:114:5 + --> $DIR/unused_attributes-must_use.rs:132:5 | LL | foo(); | ^^^^^ @@ -202,7 +265,7 @@ LL | let _ = foo(); | +++++++ error: unused return value of `foreign_foo` that must be used - --> $DIR/unused_attributes-must_use.rs:117:9 + --> $DIR/unused_attributes-must_use.rs:135:9 | LL | foreign_foo(); | ^^^^^^^^^^^^^ @@ -213,7 +276,7 @@ LL | let _ = foreign_foo(); | +++++++ error: unused return value of `Use::get_four` that must be used - --> $DIR/unused_attributes-must_use.rs:125:5 + --> $DIR/unused_attributes-must_use.rs:143:5 | LL | ().get_four(); | ^^^^^^^^^^^^^ |
