From 9c96605b20229d08a11f693412494cccc42f1ed0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 28 Jul 2023 15:24:40 +0200 Subject: [PATCH 1/4] Manually add annotations for ui tests --- tests/ui/crashes/auxiliary/ice-7868-aux.rs | 2 + tests/ui/trivially_copy_pass_by_ref.rs | 19 ++++++- tests/ui/trivially_copy_pass_by_ref.stderr | 60 +++++++++++----------- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/tests/ui/crashes/auxiliary/ice-7868-aux.rs b/tests/ui/crashes/auxiliary/ice-7868-aux.rs index bee29894b63d5..882b66d676938 100644 --- a/tests/ui/crashes/auxiliary/ice-7868-aux.rs +++ b/tests/ui/crashes/auxiliary/ice-7868-aux.rs @@ -1,3 +1,5 @@ fn zero() { unsafe { 0 }; + //~^ ERROR: unsafe block missing a safety comment + //~| NOTE: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` } diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index 3575e9f4f4cb8..043a7b63af3cc 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -1,5 +1,5 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" -//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" +//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: 8 byte)" #![deny(clippy::trivially_copy_pass_by_ref)] #![allow( clippy::disallowed_names, @@ -50,6 +50,8 @@ fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> { } fn bad(x: &u32, y: &Foo, z: &Baz) {} +//~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by +//~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by impl Foo { fn good(self, a: &mut u32, b: u32, c: &Bar) {} @@ -57,10 +59,18 @@ impl Foo { fn good2(&mut self) {} fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by fn bad2(x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by fn bad_issue7518(self, other: &Self) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } impl AsRef for Foo { @@ -73,10 +83,14 @@ impl Bar { fn good(&self, a: &mut u32, b: u32, c: &Bar) {} fn bad2(x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } trait MyTrait { fn trait_method(&self, _foo: &Foo); + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } pub trait MyTrait2 { @@ -109,11 +123,13 @@ mod issue5876 { #[inline(never)] fn foo_never(x: &i32) { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by println!("{}", x); } #[inline] fn foo(x: &i32) { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by println!("{}", x); } } @@ -141,6 +157,7 @@ async fn _async_explicit<'a>(x: &'a u32) -> &'a u32 { } fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by y } diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 2af668537f5c3..903c240bfcaba 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -22,92 +22,92 @@ error: this argument (N byte) is passed by reference, but would be more efficien LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:12 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:12 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^^ help: consider passing by value instead: `self` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:22 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:22 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:31 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:31 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:40 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:40 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:61:16 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:61:25 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:61:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:63:35 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:72:35 | LL | fn bad_issue7518(self, other: &Self) {} | ^^^^^ help: consider passing by value instead: `Self` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:75:16 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:75:25 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:75:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:79:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:92:34 | LL | fn trait_method(&self, _foo: &Foo); | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:111:21 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:125:21 | LL | fn foo_never(x: &i32) { | ^^^^ help: consider passing by value instead: `i32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:116:15 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:131:15 | LL | fn foo(x: &i32) { | ^^^^ help: consider passing by value instead: `i32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:143:37 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:159:37 | LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { | ^^^^^^^ help: consider passing by value instead: `u32` From 3a31c0557889cb8242764ef8568fa870685199f9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 28 Jul 2023 20:40:44 +0200 Subject: [PATCH 2/4] Remove/move comments to prevent weird rustfmt wrapping --- tests/ui/bytecount.rs | 24 +- tests/ui/bytecount.stderr | 12 +- tests/ui/cast.rs | 81 ++++-- tests/ui/cast.stderr | 82 +++--- tests/ui/char_lit_as_u8.rs | 3 +- tests/ui/char_lit_as_u8.stderr | 4 +- .../ui/checked_unwrap/complex_conditionals.rs | 60 ++-- .../complex_conditionals.stderr | 86 +++--- .../complex_conditionals_nested.rs | 6 +- .../complex_conditionals_nested.stderr | 9 +- .../ui/checked_unwrap/simple_conditionals.rs | 75 +++-- .../checked_unwrap/simple_conditionals.stderr | 79 ++--- tests/ui/collection_is_never_read.rs | 40 +-- tests/ui/collection_is_never_read.stderr | 40 +-- tests/ui/disallowed_script_idents.rs | 12 +- tests/ui/disallowed_script_idents.stderr | 8 +- tests/ui/eprint_with_newline.fixed | 14 +- tests/ui/eprint_with_newline.rs | 14 +- tests/ui/eprint_with_newline.stderr | 14 +- tests/ui/indexing_slicing_index.rs | 42 ++- tests/ui/indexing_slicing_index.stderr | 26 +- tests/ui/indexing_slicing_slice.rs | 6 +- tests/ui/indexing_slicing_slice.stderr | 12 +- tests/ui/infinite_iter.rs | 59 ++-- tests/ui/infinite_iter.stderr | 56 ++-- tests/ui/missing_inline.rs | 18 +- tests/ui/missing_inline.stderr | 24 +- tests/ui/modulo_one.rs | 15 +- tests/ui/modulo_one.stderr | 24 +- tests/ui/mut_range_bound.rs | 16 +- tests/ui/mut_range_bound.stderr | 10 +- tests/ui/needless_continue.rs | 12 +- tests/ui/needless_continue.stderr | 16 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 4 +- .../out_of_bounds_indexing/issue-3102.stderr | 4 +- tests/ui/print_with_newline.fixed | 17 +- tests/ui/print_with_newline.rs | 17 +- tests/ui/print_with_newline.stderr | 20 +- tests/ui/trailing_zeros.fixed | 4 +- tests/ui/trailing_zeros.rs | 4 +- tests/ui/trailing_zeros.stderr | 4 +- tests/ui/transmute_undefined_repr.rs | 274 +++++++++++------- tests/ui/transmute_undefined_repr.stderr | 48 +-- tests/ui/trivially_copy_pass_by_ref.stderr | 6 +- tests/ui/write_literal_2.rs | 6 +- tests/ui/write_literal_2.stderr | 8 +- tests/ui/write_with_newline.fixed | 14 +- tests/ui/write_with_newline.rs | 14 +- tests/ui/write_with_newline.stderr | 14 +- 49 files changed, 850 insertions(+), 607 deletions(-) diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 10a1d904bf6c7..ba1ef6e49168e 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -6,23 +6,31 @@ fn main() { let x = vec![0_u8; 16]; - let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count + // naive byte count + let _ = x.iter().filter(|&&a| a == 0).count(); - let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count + // naive byte count + let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); - let _ = x.iter().filter(|a| **a > 0).count(); // not an equality count, OK. + // not an equality count, OK. + let _ = x.iter().filter(|a| **a > 0).count(); - let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); // not a slice + // not a slice + let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); let b = 0; - let _ = x.iter().filter(|_| b > 0).count(); // woah there + // woah there + let _ = x.iter().filter(|_| b > 0).count(); - let _ = x.iter().filter(|_a| b == b + 1).count(); // nothing to see here, move along + // nothing to see here, move along + let _ = x.iter().filter(|_a| b == b + 1).count(); - let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count + // naive byte count + let _ = x.iter().filter(|a| b + 1 == **a).count(); let y = vec![0_u16; 3]; - let _ = y.iter().filter(|&&a| a == 0).count(); // naive count, but not bytes + // naive count, but not bytes + let _ = y.iter().filter(|&&a| a == 0).count(); } diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 2b7dc2ac08748..680b7b2bda8b9 100644 --- a/tests/ui/bytecount.stderr +++ b/tests/ui/bytecount.stderr @@ -1,7 +1,7 @@ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:9:13 + --> $DIR/bytecount.rs:10:13 | -LL | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count +LL | let _ = x.iter().filter(|&&a| a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, 0)` | note: the lint level is defined here @@ -11,15 +11,15 @@ LL | #[deny(clippy::naive_bytecount)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:11:13 + --> $DIR/bytecount.rs:13:13 | -LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count +LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)` error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:23:13 + --> $DIR/bytecount.rs:30:13 | -LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count +LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)` error: aborting due to 3 previous errors diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index d5ebe67c4e9fa..d2cfa41611844 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -43,14 +43,22 @@ fn main() { 1u32 as i32; 1u64 as i64; 1usize as isize; - 1usize as i8; // should not wrap, usize is never 8 bits - 1usize as i16; // wraps on 16 bit ptr size - 1usize as i32; // wraps on 32 bit ptr size - 1usize as i64; // wraps on 64 bit ptr size - 1u8 as isize; // should not wrap, isize is never 8 bits - 1u16 as isize; // wraps on 16 bit ptr size - 1u32 as isize; // wraps on 32 bit ptr size - 1u64 as isize; // wraps on 64 bit ptr size + // should not wrap, usize is never 8 bits + 1usize as i8; + // wraps on 16 bit ptr size + 1usize as i16; + // wraps on 32 bit ptr size + 1usize as i32; + // wraps on 64 bit ptr size + 1usize as i64; + // should not wrap, isize is never 8 bits + 1u8 as isize; + // wraps on 16 bit ptr size + 1u16 as isize; + // wraps on 32 bit ptr size + 1u32 as isize; + // wraps on 64 bit ptr size + 1u64 as isize; // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; @@ -122,7 +130,8 @@ fn main() { let _ = s as i32; // Test for signed min - (-99999999999i64).min(1) as i8; // should be linted because signed + // should be linted because signed + (-99999999999i64).min(1) as i8; // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; @@ -134,7 +143,8 @@ fn main() { x.min(1) }) as u8; 999999u64.clamp(0, 255) as u8; - 999999u64.clamp(0, 256) as u8; // should still be linted + // should still be linted + 999999u64.clamp(0, 256) as u8; #[derive(Clone, Copy)] enum E1 { @@ -144,7 +154,8 @@ fn main() { } impl E1 { fn test(self) { - let _ = self as u8; // Don't lint. `0..=2` fits in u8 + // Don't lint. `0..=2` fits in u8 + let _ = self as u8; } } @@ -157,8 +168,10 @@ fn main() { fn test(self) { let _ = self as u8; let _ = Self::B as u8; - let _ = self as i16; // Don't lint. `255..=256` fits in i16 - let _ = Self::A as u8; // Don't lint. + // Don't lint. `255..=256` fits in i16 + let _ = self as i16; + // Don't lint. + let _ = Self::A as u8; } } @@ -170,7 +183,8 @@ fn main() { } impl E3 { fn test(self) { - let _ = self as i8; // Don't lint. `-1..=50` fits in i8 + // Don't lint. `-1..=50` fits in i8 + let _ = self as i8; } } @@ -181,7 +195,8 @@ fn main() { } impl E4 { fn test(self) { - let _ = self as i8; // Don't lint. `-128..=-127` fits in i8 + // Don't lint. `-128..=-127` fits in i8 + let _ = self as i8; } } @@ -194,8 +209,10 @@ fn main() { fn test(self) { let _ = self as i8; let _ = Self::A as i8; - let _ = self as i16; // Don't lint. `-129..=127` fits in i16 - let _ = Self::B as u8; // Don't lint. + // Don't lint. `-129..=127` fits in i16 + let _ = self as i16; + // Don't lint. + let _ = Self::B as u8; } } @@ -208,9 +225,12 @@ fn main() { impl E6 { fn test(self) { let _ = self as i16; - let _ = Self::A as u16; // Don't lint. `2^16-1` fits in u16 - let _ = self as u32; // Don't lint. `2^16-1..=2^16` fits in u32 - let _ = Self::A as u16; // Don't lint. + // Don't lint. `2^16-1` fits in u16 + let _ = Self::A as u16; + // Don't lint. `2^16-1..=2^16` fits in u32 + let _ = self as u32; + // Don't lint. + let _ = Self::A as u16; } } @@ -223,8 +243,10 @@ fn main() { impl E7 { fn test(self) { let _ = self as usize; - let _ = Self::A as usize; // Don't lint. - let _ = self as u64; // Don't lint. `2^32-1..=2^32` fits in u64 + // Don't lint. + let _ = Self::A as usize; + // Don't lint. `2^32-1..=2^32` fits in u64 + let _ = self as u64; } } @@ -238,7 +260,8 @@ fn main() { } impl E8 { fn test(self) { - let _ = self as i128; // Don't lint. `-(2^127)..=2^127-1` fits it i128 + // Don't lint. `-(2^127)..=2^127-1` fits it i128 + let _ = self as i128; } } @@ -250,8 +273,10 @@ fn main() { } impl E9 { fn test(self) { - let _ = Self::A as u8; // Don't lint. - let _ = self as u128; // Don't lint. `0..=2^128-1` fits in u128 + // Don't lint. + let _ = Self::A as u8; + // Don't lint. `0..=2^128-1` fits in u128 + let _ = self as u128; } } @@ -264,8 +289,10 @@ fn main() { impl E10 { fn test(self) { let _ = self as u16; - let _ = Self::B as u32; // Don't lint. - let _ = self as u64; // Don't lint. + // Don't lint. + let _ = Self::B as u32; + // Don't lint. + let _ = self as u64; } } } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index ff2a4294512b5..f0630743aa75c 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -216,133 +216,133 @@ LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> $DIR/cast.rs:46:5 + --> $DIR/cast.rs:47:5 | -LL | 1usize as i8; // should not wrap, usize is never 8 bits +LL | 1usize as i8; | ^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1usize); // should not wrap, usize is never 8 bits +LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:49:5 | -LL | 1usize as i16; // wraps on 16 bit ptr size +LL | 1usize as i16; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i16::try_from(1usize); // wraps on 16 bit ptr size +LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:49:5 | -LL | 1usize as i16; // wraps on 16 bit ptr size +LL | 1usize as i16; | ^^^^^^^^^^^^^ | = note: `usize` and `isize` may be as small as 16 bits on some platforms = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:48:5 + --> $DIR/cast.rs:51:5 | -LL | 1usize as i32; // wraps on 32 bit ptr size +LL | 1usize as i32; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1usize); // wraps on 32 bit ptr size +LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:48:5 + --> $DIR/cast.rs:51:5 | -LL | 1usize as i32; // wraps on 32 bit ptr size +LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:53:5 | -LL | 1usize as i64; // wraps on 64 bit ptr size +LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:57:5 | -LL | 1u16 as isize; // wraps on 16 bit ptr size +LL | 1u16 as isize; | ^^^^^^^^^^^^^ | = note: `usize` and `isize` may be as small as 16 bits on some platforms = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:52:5 + --> $DIR/cast.rs:59:5 | -LL | 1u32 as isize; // wraps on 32 bit ptr size +LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:53:5 + --> $DIR/cast.rs:61:5 | -LL | 1u64 as isize; // wraps on 64 bit ptr size +LL | 1u64 as isize; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1u64); // wraps on 64 bit ptr size +LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:53:5 + --> $DIR/cast.rs:61:5 | -LL | 1u64 as isize; // wraps on 64 bit ptr size +LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:56:5 + --> $DIR/cast.rs:64:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:58:5 + --> $DIR/cast.rs:66:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:125:5 + --> $DIR/cast.rs:134:5 | -LL | (-99999999999i64).min(1) as i8; // should be linted because signed +LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from((-99999999999i64).min(1)); // should be linted because signed +LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> $DIR/cast.rs:137:5 + --> $DIR/cast.rs:147:5 | -LL | 999999u64.clamp(0, 256) as u8; // should still be linted +LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted +LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> $DIR/cast.rs:158:21 + --> $DIR/cast.rs:169:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -354,7 +354,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> $DIR/cast.rs:159:21 + --> $DIR/cast.rs:170:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | let _ = Self::B as u8; = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` error: casting `main::E5` to `i8` may truncate the value - --> $DIR/cast.rs:195:21 + --> $DIR/cast.rs:210:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -374,13 +374,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> $DIR/cast.rs:196:21 + --> $DIR/cast.rs:211:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:210:21 + --> $DIR/cast.rs:227:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -392,7 +392,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:225:21 + --> $DIR/cast.rs:245:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -404,7 +404,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> $DIR/cast.rs:266:21 + --> $DIR/cast.rs:291:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -416,7 +416,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:274:13 + --> $DIR/cast.rs:301:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -428,7 +428,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:277:13 + --> $DIR/cast.rs:304:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index 0a53a3d6490a3..e724c456b8883 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -1,5 +1,6 @@ #![warn(clippy::char_lit_as_u8)] fn main() { - let _ = '❤' as u8; // no suggestion, since a byte literal won't work. + // no suggestion, since a byte literal won't work. + let _ = '❤' as u8; } diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr index 39fc9d6dda674..da3e5c5e52b16 100644 --- a/tests/ui/char_lit_as_u8.stderr +++ b/tests/ui/char_lit_as_u8.stderr @@ -1,7 +1,7 @@ error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8.rs:4:13 + --> $DIR/char_lit_as_u8.rs:5:13 | -LL | let _ = '❤' as u8; // no suggestion, since a byte literal won't work. +LL | let _ = '❤' as u8; | ^^^^^^^^^ | = note: `char` is four bytes wide, but `u8` is a single byte diff --git a/tests/ui/checked_unwrap/complex_conditionals.rs b/tests/ui/checked_unwrap/complex_conditionals.rs index 16e54a7d969ef..9e618350b1982 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -9,10 +9,14 @@ fn test_complex_conditions() { let x: Result<(), ()> = Ok(()); let y: Result<(), ()> = Ok(()); if x.is_ok() && y.is_err() { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary + // unnecessary + x.unwrap(); + // will panic + x.unwrap_err(); + // will panic + y.unwrap(); + // unnecessary + y.unwrap_err(); } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -26,19 +30,29 @@ fn test_complex_conditions() { x.unwrap(); y.unwrap(); } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // unnecessary + x.unwrap_err(); + // will panic + y.unwrap(); + // unnecessary + y.unwrap_err(); } let z: Result<(), ()> = Ok(()); if x.is_ok() && !(y.is_ok() || z.is_err()) { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary - z.unwrap(); // unnecessary - z.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + // will panic + x.unwrap_err(); + // will panic + y.unwrap(); + // unnecessary + y.unwrap_err(); + // unnecessary + z.unwrap(); + // will panic + z.unwrap_err(); } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -46,12 +60,18 @@ fn test_complex_conditions() { y.unwrap(); z.unwrap(); } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - y.unwrap(); // unnecessary - y.unwrap_err(); // will panic - z.unwrap(); // will panic - z.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // unnecessary + x.unwrap_err(); + // unnecessary + y.unwrap(); + // will panic + y.unwrap_err(); + // will panic + z.unwrap(); + // unnecessary + z.unwrap_err(); } } diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index c395c5ba06f2e..f342815ac76ba 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:12:9 + --> $DIR/complex_conditionals.rs:13:9 | LL | if x.is_ok() && y.is_err() { | --------- the check is happening here -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` @@ -14,12 +15,12 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:13:9 + --> $DIR/complex_conditionals.rs:15:9 | LL | if x.is_ok() && y.is_err() { | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | note: the lint level is defined here @@ -29,180 +30,181 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:14:9 + --> $DIR/complex_conditionals.rs:17:9 | LL | if x.is_ok() && y.is_err() { | ---------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:15:9 + --> $DIR/complex_conditionals.rs:19:9 | LL | if x.is_ok() && y.is_err() { | ---------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:29:9 + --> $DIR/complex_conditionals.rs:34:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:30:9 + --> $DIR/complex_conditionals.rs:36:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:31:9 + --> $DIR/complex_conditionals.rs:38:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:32:9 + --> $DIR/complex_conditionals.rs:40:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:36:9 + --> $DIR/complex_conditionals.rs:45:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:37:9 + --> $DIR/complex_conditionals.rs:47:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:38:9 + --> $DIR/complex_conditionals.rs:49:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:39:9 + --> $DIR/complex_conditionals.rs:51:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:40:9 + --> $DIR/complex_conditionals.rs:53:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- the check is happening here ... -LL | z.unwrap(); // unnecessary +LL | z.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:41:9 + --> $DIR/complex_conditionals.rs:55:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- because of this check ... -LL | z.unwrap_err(); // will panic +LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:49:9 + --> $DIR/complex_conditionals.rs:64:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:50:9 + --> $DIR/complex_conditionals.rs:66:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:51:9 + --> $DIR/complex_conditionals.rs:68:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here ... -LL | y.unwrap(); // unnecessary +LL | y.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:52:9 + --> $DIR/complex_conditionals.rs:70:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check ... -LL | y.unwrap_err(); // will panic +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:53:9 + --> $DIR/complex_conditionals.rs:72:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- because of this check ... -LL | z.unwrap(); // will panic +LL | z.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:54:9 + --> $DIR/complex_conditionals.rs:74:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here ... -LL | z.unwrap_err(); // unnecessary +LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index e390cfab58d94..1ee8d16565b5c 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -9,9 +9,11 @@ fn test_nested() { fn nested() { let x = Some(()); if x.is_some() { - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); } else { - x.unwrap(); // will panic + // will panic + x.unwrap(); } } } diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr index 049a69d93bfe9..bf7c6750ccfda 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/complex_conditionals_nested.rs:12:13 + --> $DIR/complex_conditionals_nested.rs:13:13 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -13,12 +14,12 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals_nested.rs:14:13 + --> $DIR/complex_conditionals_nested.rs:16:13 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 15a246fce6403..12522ae5ba12c 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -10,7 +10,8 @@ macro_rules! m { ($a:expr) => { if $a.is_some() { - $a.unwrap(); // unnecessary + // unnecessary + $a.unwrap(); } }; } @@ -42,37 +43,56 @@ macro_rules! checks_some { fn main() { let x = Some(()); if x.is_some() { - x.unwrap(); // unnecessary - x.expect("an error message"); // unnecessary + // unnecessary + x.unwrap(); + // unnecessary + x.expect("an error message"); } else { - x.unwrap(); // will panic - x.expect("an error message"); // will panic + // will panic + x.unwrap(); + // will panic + x.expect("an error message"); } if x.is_none() { - x.unwrap(); // will panic + // will panic + x.unwrap(); } else { - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); } m!(x); - checks_in_param!(x.is_some(), x.unwrap()); // ok - checks_unwrap!(x, x.unwrap()); // ok - checks_some!(x.is_some(), x); // ok + // ok + checks_in_param!(x.is_some(), x.unwrap()); + // ok + checks_unwrap!(x, x.unwrap()); + // ok + checks_some!(x.is_some(), x); let mut x: Result<(), ()> = Ok(()); if x.is_ok() { - x.unwrap(); // unnecessary - x.expect("an error message"); // unnecessary - x.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + // unnecessary + x.expect("an error message"); + // will panic + x.unwrap_err(); } else { - x.unwrap(); // will panic - x.expect("an error message"); // will panic - x.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // will panic + x.expect("an error message"); + // unnecessary + x.unwrap_err(); } if x.is_err() { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // unnecessary + x.unwrap_err(); } else { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + // will panic + x.unwrap_err(); } if x.is_ok() { x = Err(()); @@ -88,20 +108,25 @@ fn main() { x.unwrap_err(); } - assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern + // ok, it's a common test pattern + assert!(x.is_ok(), "{:?}", x.unwrap_err()); } fn check_expect() { let x = Some(()); if x.is_some() { #[expect(clippy::unnecessary_unwrap)] - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); #[expect(clippy::unnecessary_unwrap)] - x.expect("an error message"); // unnecessary + // unnecessary + x.expect("an error message"); } else { #[expect(clippy::panicking_unwrap)] - x.unwrap(); // will panic + // will panic + x.unwrap(); #[expect(clippy::panicking_unwrap)] - x.expect("an error message"); // will panic + // will panic + x.expect("an error message"); } } diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index dae7c88126268..0c5a64979241f 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:45:9 + --> $DIR/simple_conditionals.rs:47:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -13,21 +14,21 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:46:9 + --> $DIR/simple_conditionals.rs:49:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary -LL | x.expect("an error message"); // unnecessary +... +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:48:9 + --> $DIR/simple_conditionals.rs:52:9 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -37,37 +38,39 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:49:9 + --> $DIR/simple_conditionals.rs:54:9 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.expect("an error message"); // will panic +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:52:9 + --> $DIR/simple_conditionals.rs:58:9 | LL | if x.is_none() { | ----------- because of this check -LL | x.unwrap(); // will panic +LL | // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> $DIR/simple_conditionals.rs:54:9 + --> $DIR/simple_conditionals.rs:61:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` ... -LL | x.unwrap(); // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:13:13 + --> $DIR/simple_conditionals.rs:14:13 | LL | if $a.is_some() { | --------------- help: try: `if let Some(..) = x` -LL | $a.unwrap(); // unnecessary +LL | // unnecessary +LL | $a.unwrap(); | ^^^^^^^^^^^ ... LL | m!(x); @@ -76,91 +79,93 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:62:9 + --> $DIR/simple_conditionals.rs:73:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:63:9 + --> $DIR/simple_conditionals.rs:75:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` -LL | x.unwrap(); // unnecessary -LL | x.expect("an error message"); // unnecessary +... +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:64:9 + --> $DIR/simple_conditionals.rs:77:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.unwrap_err(); // will panic +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:66:9 + --> $DIR/simple_conditionals.rs:80:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:67:9 + --> $DIR/simple_conditionals.rs:82:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.expect("an error message"); // will panic +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:68:9 + --> $DIR/simple_conditionals.rs:84:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:71:9 + --> $DIR/simple_conditionals.rs:88:9 | LL | if x.is_err() { | ---------- because of this check -LL | x.unwrap(); // will panic +LL | // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:72:9 + --> $DIR/simple_conditionals.rs:90:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` -LL | x.unwrap(); // will panic -LL | x.unwrap_err(); // unnecessary +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:74:9 + --> $DIR/simple_conditionals.rs:93:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` ... -LL | x.unwrap(); // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:75:9 + --> $DIR/simple_conditionals.rs:95:9 | LL | if x.is_err() { | ---------- because of this check ... -LL | x.unwrap_err(); // will panic +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: aborting due to 17 previous errors diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs index e02c1c57230ad..f7ba68fd8948e 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -18,7 +18,7 @@ fn no_access_at_all() { fn write_without_read() { // The main use case for `collection_is_never_read`. - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); x.insert(1, 2); } @@ -57,7 +57,7 @@ fn read_in_closure() { } fn write_in_closure() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; let _ = || { x.push(4); }; @@ -72,12 +72,12 @@ fn read_in_format() { fn shadowing_1() { let x = HashMap::::new(); // Ok let _ = x.len(); - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); x.insert(1, 2); } fn shadowing_2() { - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); x.insert(1, 2); let x = HashMap::::new(); // Ok let _ = x.len(); @@ -85,26 +85,26 @@ fn shadowing_2() { #[allow(clippy::let_unit_value)] fn fake_read_1() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; x.reverse(); let _: () = x.clear(); } fn fake_read_2() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; x.reverse(); println!("{:?}", x.push(5)); } fn assignment() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; let y = vec![4, 5, 6]; // Ok x = y; } #[allow(clippy::self_assignment)] fn self_assignment() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; x = x; } @@ -121,7 +121,7 @@ fn method_argument_but_not_target() { } fn insert_is_not_a_read() { - let mut x = HashSet::new(); // WARNING + let mut x = HashSet::new(); x.insert(5); } @@ -135,7 +135,7 @@ fn insert_is_a_read() { fn not_read_if_return_value_not_used() { // `is_empty` does not modify the set, so it's a query. But since the return value is not used, the // lint does not consider it a read here. - let x = vec![1, 2, 3]; // WARNING + let x = vec![1, 2, 3]; x.is_empty(); } @@ -170,34 +170,34 @@ fn function_argument() { } fn supported_types() { - let mut x = std::collections::BTreeMap::new(); // WARNING + let mut x = std::collections::BTreeMap::new(); x.insert(true, 1); - let mut x = std::collections::BTreeSet::new(); // WARNING + let mut x = std::collections::BTreeSet::new(); x.insert(1); - let mut x = std::collections::BinaryHeap::new(); // WARNING + let mut x = std::collections::BinaryHeap::new(); x.push(1); - let mut x = std::collections::HashMap::new(); // WARNING + let mut x = std::collections::HashMap::new(); x.insert(1, 2); - let mut x = std::collections::HashSet::new(); // WARNING + let mut x = std::collections::HashSet::new(); x.insert(1); - let mut x = std::collections::LinkedList::new(); // WARNING + let mut x = std::collections::LinkedList::new(); x.push_front(1); - let mut x = Some(true); // WARNING + let mut x = Some(true); x.insert(false); - let mut x = String::from("hello"); // WARNING + let mut x = String::from("hello"); x.push('!'); - let mut x = Vec::new(); // WARNING + let mut x = Vec::new(); x.clear(); x.push(1); - let mut x = std::collections::VecDeque::new(); // WARNING + let mut x = std::collections::VecDeque::new(); x.push_front(1); } diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 982cb445534a2..32ba6b9bc2738 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -1,7 +1,7 @@ error: collection is never read --> $DIR/collection_is_never_read.rs:21:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::collection-is-never-read` implied by `-D warnings` @@ -9,115 +9,115 @@ LL | let mut x = HashMap::new(); // WARNING error: collection is never read --> $DIR/collection_is_never_read.rs:60:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:75:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:80:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:88:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:94:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:100:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:107:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:124:5 | -LL | let mut x = HashSet::new(); // WARNING +LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:138:5 | -LL | let x = vec![1, 2, 3]; // WARNING +LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:173:5 | -LL | let mut x = std::collections::BTreeMap::new(); // WARNING +LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:176:5 | -LL | let mut x = std::collections::BTreeSet::new(); // WARNING +LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:179:5 | -LL | let mut x = std::collections::BinaryHeap::new(); // WARNING +LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:182:5 | -LL | let mut x = std::collections::HashMap::new(); // WARNING +LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:185:5 | -LL | let mut x = std::collections::HashSet::new(); // WARNING +LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:188:5 | -LL | let mut x = std::collections::LinkedList::new(); // WARNING +LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:191:5 | -LL | let mut x = Some(true); // WARNING +LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:194:5 | -LL | let mut x = String::from("hello"); // WARNING +LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:197:5 | -LL | let mut x = Vec::new(); // WARNING +LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:201:5 | -LL | let mut x = std::collections::VecDeque::new(); // WARNING +LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 20 previous errors diff --git a/tests/ui/disallowed_script_idents.rs b/tests/ui/disallowed_script_idents.rs index cfdda35971fb6..6fc6f9988ebe4 100644 --- a/tests/ui/disallowed_script_idents.rs +++ b/tests/ui/disallowed_script_idents.rs @@ -2,9 +2,13 @@ #![allow(dead_code)] fn main() { - let counter = 10; // OK, latin is allowed. - let zähler = 10; // OK, it's still latin. + // OK, latin is allowed. + let counter = 10; + // OK, it's still latin. + let zähler = 10; - let счётчик = 10; // Cyrillic is not allowed by default. - let カウンタ = 10; // Same for japanese. + // Cyrillic is not allowed by default. + let счётчик = 10; + // Same for japanese. + let カウンタ = 10; } diff --git a/tests/ui/disallowed_script_idents.stderr b/tests/ui/disallowed_script_idents.stderr index cc84dc1d43c59..7b91d8c426b27 100644 --- a/tests/ui/disallowed_script_idents.stderr +++ b/tests/ui/disallowed_script_idents.stderr @@ -1,7 +1,7 @@ error: identifier `счётчик` has a Unicode script that is not allowed by configuration: Cyrillic - --> $DIR/disallowed_script_idents.rs:8:9 + --> $DIR/disallowed_script_idents.rs:11:9 | -LL | let счётчик = 10; // Cyrillic is not allowed by default. +LL | let счётчик = 10; | ^^^^^^^ | note: the lint level is defined here @@ -11,9 +11,9 @@ LL | #![deny(clippy::disallowed_script_idents)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana - --> $DIR/disallowed_script_idents.rs:9:9 + --> $DIR/disallowed_script_idents.rs:13:9 | -LL | let カウンタ = 10; // Same for japanese. +LL | let カウンタ = 10; | ^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed index c63a657142026..d0349e68622a6 100644 --- a/tests/ui/eprint_with_newline.fixed +++ b/tests/ui/eprint_with_newline.fixed @@ -20,16 +20,20 @@ fn main() { eprint!("\n\n"); eprint!("like eof\n\n"); eprint!("Hello {} {}\n\n", "world", "#2"); - eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - eprintln!("\nbla\n\n"); // #3126 + // #3126 + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + eprintln!("\nbla\n\n"); // Escaping - eprint!("\\n"); // #3514 - eprintln!("\\"); // should fail + // #3514 + eprint!("\\n"); + eprintln!("\\"); eprint!("\\\\n"); // Raw strings - eprint!(r"\n"); // #3778 + // #3778 + eprint!(r"\n"); // Literal newlines should also fail eprintln!( diff --git a/tests/ui/eprint_with_newline.rs b/tests/ui/eprint_with_newline.rs index 8389806c838e1..9446d5d651a17 100644 --- a/tests/ui/eprint_with_newline.rs +++ b/tests/ui/eprint_with_newline.rs @@ -20,16 +20,20 @@ fn main() { eprint!("\n\n"); eprint!("like eof\n\n"); eprint!("Hello {} {}\n\n", "world", "#2"); - eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - eprintln!("\nbla\n\n"); // #3126 + // #3126 + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + eprintln!("\nbla\n\n"); // Escaping - eprint!("\\n"); // #3514 - eprint!("\\\n"); // should fail + // #3514 + eprint!("\\n"); + eprint!("\\\n"); eprint!("\\\\n"); // Raw strings - eprint!(r"\n"); // #3778 + // #3778 + eprint!(r"\n"); // Literal newlines should also fail eprint!( diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 080f6c2a60542..e92b1ba672fe7 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -60,19 +60,19 @@ LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:28:5 + --> $DIR/eprint_with_newline.rs:31:5 | -LL | eprint!("\\\n"); // should fail +LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("\\\n"); // should fail -LL + eprintln!("\\"); // should fail +LL - eprint!("\\\n"); +LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:35:5 + --> $DIR/eprint_with_newline.rs:39:5 | LL | / eprint!( LL | | " @@ -87,7 +87,7 @@ LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:39:5 + --> $DIR/eprint_with_newline.rs:43:5 | LL | / eprint!( LL | | r" @@ -102,7 +102,7 @@ LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:47:5 + --> $DIR/eprint_with_newline.rs:51:5 | LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 16f9e47e8532c..f7f7ea4103534 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -25,29 +25,43 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; x[index]; - x[4]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[1 << 3]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[4]; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[1 << 3]; - x[0]; // Ok, should not produce stderr. - x[3]; // Ok, should not produce stderr. - x[const { idx() }]; // Ok, should not produce stderr. - x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. - const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. + // Ok, should not produce stderr. + x[0]; + // Ok, should not produce stderr. + x[3]; + // Ok, should not produce stderr. + x[const { idx() }]; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[const { idx4() }]; + // This should be linted, since `suppress-restriction-lint-in-const` default is false. + const { &ARR[idx()] }; + // This should be linted, since `suppress-restriction-lint-in-const` default is false. + const { &ARR[idx4()] }; let y = &x; - y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021 - y[4]; // Ok, rustc will handle references too. + // Ok, referencing shouldn't affect this lint. See the issue 6021 + y[0]; + // Ok, rustc will handle references too. + y[4]; let v = vec![0; 5]; v[0]; v[10]; v[1 << 3]; - const N: usize = 15; // Out of bounds - const M: usize = 3; // In bounds - x[N]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[M]; // Ok, should not produce stderr. + // Out of bounds + const N: usize = 15; + // In bounds + const M: usize = 3; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[N]; + // Ok, should not produce stderr. + x[M]; v[N]; v[M]; } diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index f4357c1d592d0..1db2eb1397cde 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -18,15 +18,15 @@ LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. = note: the suggestion might not be applicable in constant blocks error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:36:14 + --> $DIR/indexing_slicing_index.rs:44:14 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant used - --> $DIR/indexing_slicing_index.rs:36:5 + --> $DIR/indexing_slicing_index.rs:44:5 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic @@ -38,25 +38,25 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:35:14 + --> $DIR/indexing_slicing_index.rs:42:14 | -LL | const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx()] }; | ^^^^^^^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:36:14 + --> $DIR/indexing_slicing_index.rs:44:14 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:43:5 + --> $DIR/indexing_slicing_index.rs:53:5 | LL | v[0]; | ^^^^ @@ -64,7 +64,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:44:5 + --> $DIR/indexing_slicing_index.rs:54:5 | LL | v[10]; | ^^^^^ @@ -72,7 +72,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:45:5 + --> $DIR/indexing_slicing_index.rs:55:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -80,7 +80,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:51:5 + --> $DIR/indexing_slicing_index.rs:65:5 | LL | v[N]; | ^^^^ @@ -88,7 +88,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:52:5 + --> $DIR/indexing_slicing_index.rs:66:5 | LL | v[M]; | ^^^^ diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs index 939b6ac36bde8..ea111a48b29fe 100644 --- a/tests/ui/indexing_slicing_slice.rs +++ b/tests/ui/indexing_slicing_slice.rs @@ -12,8 +12,8 @@ fn main() { &x[index..]; &x[..index]; &x[index_from..index_to]; - &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. - &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. + &x[index_from..][..index_to]; + &x[5..][..10]; &x[0..][..3]; &x[1..][..5]; @@ -29,7 +29,7 @@ fn main() { let v = vec![0; 5]; &v[10..100]; - &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. + &x[10..][..100]; &v[10..]; &v[..100]; diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index dc54bd41365d3..6a75d57453797 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -26,7 +26,7 @@ LL | &x[index_from..index_to]; error: slicing may panic --> $DIR/indexing_slicing_slice.rs:15:6 | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. +LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead @@ -34,7 +34,7 @@ LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from. error: slicing may panic --> $DIR/indexing_slicing_slice.rs:15:6 | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. +LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^ | = help: consider using `.get(n..)` or .get_mut(n..)` instead @@ -42,7 +42,7 @@ LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from. error: slicing may panic --> $DIR/indexing_slicing_slice.rs:16:6 | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. +LL | &x[5..][..10]; | ^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead @@ -50,7 +50,7 @@ LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and ano error: range is out of bounds --> $DIR/indexing_slicing_slice.rs:16:8 | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. +LL | &x[5..][..10]; | ^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` @@ -94,7 +94,7 @@ LL | &v[10..100]; error: slicing may panic --> $DIR/indexing_slicing_slice.rs:32:6 | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. +LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead @@ -102,7 +102,7 @@ LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [. error: range is out of bounds --> $DIR/indexing_slicing_slice.rs:32:8 | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. +LL | &x[10..][..100]; | ^^ error: slicing may panic diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 622644f675d35..7821dd44812df 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -8,42 +8,60 @@ fn square_is_lower_64(x: &u32) -> bool { #[allow(clippy::maybe_infinite_iter)] #[deny(clippy::infinite_iter)] fn infinite_iters() { - repeat(0_u8).collect::>(); // infinite iter - (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter - (0..8_u64).chain(0..).max(); // infinite iter + repeat(0_u8).collect::>(); + // infinite iter + (0..8_u32).take_while(square_is_lower_64).cycle().count(); + // infinite iter + (0..8_u64).chain(0..).max(); + // infinite iter (0_usize..) .chain([0usize, 1, 2].iter().cloned()) .skip_while(|x| *x != 42) - .min(); // infinite iter + .min(); + // infinite iter (0..8_u32) .rev() .cycle() .map(|x| x + 1_u32) - .for_each(|x| println!("{}", x)); // infinite iter - (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter - (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter - (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter - (0..42_u64).by_ref().last(); // not an infinite, because ranges are double-ended - (0..).next(); // iterator is not exhausted + .for_each(|x| println!("{}", x)); + // infinite iter + (0..3_u32).flat_map(|x| x..).sum::(); + // infinite iter + (0_usize..).flat_map(|x| 0..x).product::(); + // infinite iter + (0_u64..).filter(|x| x % 2 == 0).last(); + // not an infinite, because ranges are double-ended + (0..42_u64).by_ref().last(); + // iterator is not exhausted + (0..).next(); } #[deny(clippy::maybe_infinite_iter)] fn potential_infinite_iters() { - (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter - repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter + // maybe infinite iter + (0..).zip((0..).take_while(square_is_lower_64)).count(); + // maybe infinite iter + repeat(42).take_while(|x| *x == 42).chain(0..42).max(); + // maybe infinite iter (1..) .scan(0, |state, x| { *state += x; Some(*state) }) - .min(); // maybe infinite iter - (0..).find(|x| *x == 24); // maybe infinite iter - (0..).position(|x| x == 24); // maybe infinite iter - (0..).any(|x| x == 24); // maybe infinite iter - (0..).all(|x| x == 24); // maybe infinite iter + .min(); + // maybe infinite iter + (0..).find(|x| *x == 24); + // maybe infinite iter + (0..).position(|x| x == 24); + // maybe infinite iter + (0..).any(|x| x == 24); + // maybe infinite iter + (0..).all(|x| x == 24); - (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); // not infinite - repeat(42).take_while(|x| *x == 42).next(); // iterator is not exhausted + // not infinite + (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); + // iterator is not exhausted + repeat(42).take_while(|x| *x == 42).next(); } fn main() { @@ -62,7 +80,8 @@ mod finite_collect { } fn check_collect() { - let _: HashSet = (0..).collect(); // Infinite iter + // Infinite iter + let _: HashSet = (0..).collect(); // Some data structures don't collect infinitely, such as `ArrayVec` let _: C = (0..).collect(); diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index b911163f715e7..39d2fcc71aa69 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -1,7 +1,7 @@ error: infinite iteration detected --> $DIR/infinite_iter.rs:11:5 | -LL | repeat(0_u8).collect::>(); // infinite iter +LL | repeat(0_u8).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here @@ -11,96 +11,96 @@ LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:12:5 + --> $DIR/infinite_iter.rs:13:5 | -LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter +LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:13:5 + --> $DIR/infinite_iter.rs:15:5 | -LL | (0..8_u64).chain(0..).max(); // infinite iter +LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:18:5 + --> $DIR/infinite_iter.rs:22:5 | LL | / (0..8_u32) LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) -LL | | .for_each(|x| println!("{}", x)); // infinite iter +LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:24:5 + --> $DIR/infinite_iter.rs:30:5 | -LL | (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter +LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:25:5 + --> $DIR/infinite_iter.rs:32:5 | -LL | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter +LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:32:5 + --> $DIR/infinite_iter.rs:42:5 | -LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter +LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/infinite_iter.rs:30:8 + --> $DIR/infinite_iter.rs:39:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:33:5 + --> $DIR/infinite_iter.rs:44:5 | -LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter +LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:34:5 + --> $DIR/infinite_iter.rs:46:5 | LL | / (1..) LL | | .scan(0, |state, x| { LL | | *state += x; LL | | Some(*state) LL | | }) -LL | | .min(); // maybe infinite iter +LL | | .min(); | |______________^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:40:5 + --> $DIR/infinite_iter.rs:53:5 | -LL | (0..).find(|x| *x == 24); // maybe infinite iter +LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:41:5 + --> $DIR/infinite_iter.rs:55:5 | -LL | (0..).position(|x| x == 24); // maybe infinite iter +LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:42:5 + --> $DIR/infinite_iter.rs:57:5 | -LL | (0..).any(|x| x == 24); // maybe infinite iter +LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:43:5 + --> $DIR/infinite_iter.rs:59:5 | -LL | (0..).all(|x| x == 24); // maybe infinite iter +LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:65:31 + --> $DIR/infinite_iter.rs:84:31 | -LL | let _: HashSet = (0..).collect(); // Infinite iter +LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ | = note: `#[deny(clippy::infinite_iter)]` on by default diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index 07f8e3888c998..c5cf97d3cd655 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -16,7 +16,8 @@ mod module {} // ok pub mod pub_module {} // ok fn foo() {} -pub fn pub_foo() {} // missing #[inline] +// missing #[inline] +pub fn pub_foo() {} #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -32,7 +33,8 @@ trait Bar { pub trait PubBar { fn PubBar_a(); // ok - fn PubBar_b() {} // missing #[inline] + // missing #[inline] + fn PubBar_b() {} #[inline] fn PubBar_c() {} // ok } @@ -46,9 +48,12 @@ impl PubBar for Foo { // all of these need inline because PubFoo is exported impl PubBar for PubFoo { - fn PubBar_a() {} // missing #[inline] - fn PubBar_b() {} // missing #[inline] - fn PubBar_c() {} // missing #[inline] + // missing #[inline] + fn PubBar_a() {} + // missing #[inline] + fn PubBar_b() {} + // missing #[inline] + fn PubBar_c() {} } // do not need inline because Foo is not exported @@ -58,7 +63,8 @@ impl Foo { // need inline because PubFoo is exported impl PubFoo { - pub fn PubFooImpl() {} // missing #[inline] + // missing #[inline] + pub fn PubFooImpl() {} } // do not lint this since users cannot control the external code diff --git a/tests/ui/missing_inline.stderr b/tests/ui/missing_inline.stderr index 40b92b7647bf7..73f876c1d1a31 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -1,39 +1,39 @@ error: missing `#[inline]` for a function - --> $DIR/missing_inline.rs:19:1 + --> $DIR/missing_inline.rs:20:1 | -LL | pub fn pub_foo() {} // missing #[inline] +LL | pub fn pub_foo() {} | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` error: missing `#[inline]` for a default trait method - --> $DIR/missing_inline.rs:35:5 + --> $DIR/missing_inline.rs:37:5 | -LL | fn PubBar_b() {} // missing #[inline] +LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:49:5 + --> $DIR/missing_inline.rs:52:5 | -LL | fn PubBar_a() {} // missing #[inline] +LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:50:5 + --> $DIR/missing_inline.rs:54:5 | -LL | fn PubBar_b() {} // missing #[inline] +LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:51:5 + --> $DIR/missing_inline.rs:56:5 | -LL | fn PubBar_c() {} // missing #[inline] +LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:61:5 + --> $DIR/missing_inline.rs:67:5 | -LL | pub fn PubFooImpl() {} // missing #[inline] +LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index adff08e5d1e8b..656b0b5cedcc2 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -8,16 +8,21 @@ fn main() { 10 % 1; 10 % -1; 10 % 2; - i32::MIN % (-1); // also caught by rustc + // also caught by rustc + i32::MIN % (-1); const ONE: u32 = 1 * 1; const NEG_ONE: i64 = 1 - 2; const INT_MIN: i64 = i64::MIN; 2 % ONE; - 5 % STATIC_ONE; // NOT caught by lint + // NOT caught by lint + 5 % STATIC_ONE; 2 % NEG_ONE; - 5 % STATIC_NEG_ONE; // NOT caught by lint - INT_MIN % NEG_ONE; // also caught by rustc - INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc + // NOT caught by lint + 5 % STATIC_NEG_ONE; + // also caught by rustc + INT_MIN % NEG_ONE; + // ONLY caught by rustc + INT_MIN % STATIC_NEG_ONE; } diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 83a76f81d4e78..0793e6386930b 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -1,21 +1,21 @@ error: this operation will panic at runtime - --> $DIR/modulo_one.rs:11:5 + --> $DIR/modulo_one.rs:12:5 | -LL | i32::MIN % (-1); // also caught by rustc +LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow | = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:25:5 | -LL | INT_MIN % NEG_ONE; // also caught by rustc +LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: this operation will panic at runtime - --> $DIR/modulo_one.rs:22:5 + --> $DIR/modulo_one.rs:27:5 | -LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc +LL | INT_MIN % STATIC_NEG_ONE; | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: any number modulo 1 will be 0 @@ -33,27 +33,27 @@ LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:11:5 + --> $DIR/modulo_one.rs:12:5 | -LL | i32::MIN % (-1); // also caught by rustc +LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:17:5 + --> $DIR/modulo_one.rs:18:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:19:5 + --> $DIR/modulo_one.rs:21:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:25:5 | -LL | INT_MIN % NEG_ONE; // also caught by rustc +LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ error: aborting due to 9 previous errors diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index 7fdeb27ed988f..2c0d71ef0dd15 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -6,14 +6,14 @@ fn mut_range_bound_upper() { let mut m = 4; for i in 0..m { m = 5; - } // warning + } } fn mut_range_bound_lower() { let mut m = 4; for i in m..10 { m *= 2; - } // warning + } } fn mut_range_bound_both() { @@ -22,7 +22,7 @@ fn mut_range_bound_both() { for i in m..n { m = 5; n = 7; - } // warning (1 for each mutated bound) + } } fn mut_range_bound_no_mutation() { @@ -35,7 +35,7 @@ fn mut_range_bound_no_mutation() { fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &mut m; // warning + let n = &mut m; *n += 1; } } @@ -43,7 +43,7 @@ fn mut_borrow_range_bound() { fn immut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &m; // should be no warning? + let n = &m; } } @@ -67,7 +67,8 @@ fn mut_range_bound_break() { fn mut_range_bound_no_immediate_break() { let mut m = 4; for i in 0..m { - m = 2; // warning because it is not immediately followed by break + // warning because it is not immediately followed by break + m = 2; if m == 4 { break; } @@ -76,7 +77,8 @@ fn mut_range_bound_no_immediate_break() { let mut n = 3; for i in n..10 { if n == 4 { - n = 1; // FIXME: warning because it is not immediately followed by break + // FIXME: warning because it is not immediately followed by break + n = 1; let _ = 2; break; } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index b679b7a0aaf82..6183135fc9c13 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -34,23 +34,23 @@ LL | n = 7; error: attempt to mutate range bound within loop --> $DIR/mut_range_bound.rs:38:22 | -LL | let n = &mut m; // warning +LL | let n = &mut m; | ^ | = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:70:9 + --> $DIR/mut_range_bound.rs:71:9 | -LL | m = 2; // warning because it is not immediately followed by break +LL | m = 2; | ^ | = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:79:13 + --> $DIR/mut_range_bound.rs:81:13 | -LL | n = 1; // FIXME: warning because it is not immediately followed by break +LL | n = 1; | ^ | = note: the range of the loop is unchanged diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index c891c9de3aeca..12e6c7deb9c20 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -55,21 +55,21 @@ fn main() { fn simple_loop() { loop { - continue; // should lint here + continue; } } fn simple_loop2() { loop { println!("bleh"); - continue; // should lint here + continue; } } #[rustfmt::skip] fn simple_loop3() { loop { - continue // should lint here + continue } } @@ -77,7 +77,7 @@ fn simple_loop3() { fn simple_loop4() { loop { println!("bleh"); - continue // should lint here + continue } } @@ -128,13 +128,13 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { - continue 'inner; // should lint here + continue 'inner; } println!("bar-4"); update_condition(); if condition() { - continue; // should lint here + continue; } else { println!("bar-5"); } diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index d99989b54fc25..7f9f644643f97 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -57,7 +57,7 @@ LL | | } error: this `continue` expression is redundant --> $DIR/needless_continue.rs:58:9 | -LL | continue; // should lint here +LL | continue; | ^^^^^^^^^ | = help: consider dropping the `continue` expression @@ -65,7 +65,7 @@ LL | continue; // should lint here error: this `continue` expression is redundant --> $DIR/needless_continue.rs:65:9 | -LL | continue; // should lint here +LL | continue; | ^^^^^^^^^ | = help: consider dropping the `continue` expression @@ -73,7 +73,7 @@ LL | continue; // should lint here error: this `continue` expression is redundant --> $DIR/needless_continue.rs:72:9 | -LL | continue // should lint here +LL | continue | ^^^^^^^^ | = help: consider dropping the `continue` expression @@ -81,7 +81,7 @@ LL | continue // should lint here error: this `continue` expression is redundant --> $DIR/needless_continue.rs:80:9 | -LL | continue // should lint here +LL | continue | ^^^^^^^^ | = help: consider dropping the `continue` expression @@ -91,7 +91,7 @@ error: this `else` block is redundant | LL | } else { | ________________________^ -LL | | continue 'inner; // should lint here +LL | | continue 'inner; LL | | } | |_________________^ | @@ -102,7 +102,7 @@ LL | | } println!("bar-4"); update_condition(); if condition() { - continue; // should lint here + continue; } else { println!("bar-5"); } @@ -113,7 +113,7 @@ error: there is no need for an explicit `else` block for this `if` expression --> $DIR/needless_continue.rs:136:17 | LL | / if condition() { -LL | | continue; // should lint here +LL | | continue; LL | | } else { LL | | println!("bar-5"); LL | | } @@ -121,7 +121,7 @@ LL | | } | = help: consider dropping the `else` clause if condition() { - continue; // should lint here + continue; } { println!("bar-5"); diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index edd2123d48a55..a5605cc14d484 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -6,6 +6,6 @@ fn main() { // issue 3102 let num = 1; - &x[num..10]; // should trigger out of bounds error - &x[10..num]; // should trigger out of bounds error + &x[num..10]; + &x[10..num]; } diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 516c1df40be0a..8a09688a90ceb 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -1,7 +1,7 @@ error: range is out of bounds --> $DIR/issue-3102.rs:9:13 | -LL | &x[num..10]; // should trigger out of bounds error +LL | &x[num..10]; | ^^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` @@ -9,7 +9,7 @@ LL | &x[num..10]; // should trigger out of bounds error error: range is out of bounds --> $DIR/issue-3102.rs:10:8 | -LL | &x[10..num]; // should trigger out of bounds error +LL | &x[10..num]; | ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index 73e73984cdd2d..c9c3b925aa699 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -22,16 +22,20 @@ fn main() { print!("\n\n"); print!("like eof\n\n"); print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 + // #3126 + println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + println!("\nbla\n\n"); // Escaping - print!("\\n"); // #3514 - println!("\\"); // should fail + // #3514 + print!("\\n"); + println!("\\"); print!("\\\\n"); // Raw strings - print!(r"\n"); // #3778 + // #3778 + print!(r"\n"); // Literal newlines should also fail println!( @@ -44,7 +48,8 @@ fn main() { // Don't warn on CRLF (#4208) print!("\r\n"); print!("foo\r\n"); - println!("\\r"); // should fail + // should fail + println!("\\r"); print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index c3ea26ad74efe..aaddbcd4be824 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -22,16 +22,20 @@ fn main() { print!("\n\n"); print!("like eof\n\n"); print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 + // #3126 + println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + println!("\nbla\n\n"); // Escaping - print!("\\n"); // #3514 - print!("\\\n"); // should fail + // #3514 + print!("\\n"); + print!("\\\n"); print!("\\\\n"); // Raw strings - print!(r"\n"); // #3778 + // #3778 + print!(r"\n"); // Literal newlines should also fail print!( @@ -46,7 +50,8 @@ fn main() { // Don't warn on CRLF (#4208) print!("\r\n"); print!("foo\r\n"); - print!("\\r\n"); // should fail + // should fail + print!("\\r\n"); print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 7130edaa7f458..16cec220f8346 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -60,19 +60,19 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:30:5 + --> $DIR/print_with_newline.rs:33:5 | -LL | print!("\\\n"); // should fail +LL | print!("\\\n"); | ^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("\\\n"); // should fail -LL + println!("\\"); // should fail +LL - print!("\\\n"); +LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:37:5 + --> $DIR/print_with_newline.rs:41:5 | LL | / print!( LL | | " @@ -87,7 +87,7 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:41:5 + --> $DIR/print_with_newline.rs:45:5 | LL | / print!( LL | | r" @@ -102,15 +102,15 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:49:5 + --> $DIR/print_with_newline.rs:54:5 | -LL | print!("\\r\n"); // should fail +LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("\\r\n"); // should fail -LL + println!("\\r"); // should fail +LL - print!("\\r\n"); +LL + println!("\\r"); | error: aborting due to 9 previous errors diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index 60db3c07ce90b..8aceb76ddd851 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -3,8 +3,8 @@ fn main() { let x: i32 = 42; - let _ = x.trailing_zeros() >= 4; // suggest trailing_zeros - let _ = x.trailing_zeros() >= 5; // suggest trailing_zeros + let _ = x.trailing_zeros() >= 4; + let _ = x.trailing_zeros() >= 5; let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index fbdc977b769a4..888f0587fe348 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -3,8 +3,8 @@ fn main() { let x: i32 = 42; - let _ = (x & 0b1111 == 0); // suggest trailing_zeros - let _ = x & 0b1_1111 == 0; // suggest trailing_zeros + let _ = (x & 0b1111 == 0); + let _ = x & 0b1_1111 == 0; let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 798551118309e..7c44f139c0952 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -1,7 +1,7 @@ error: bit mask could be simplified with a call to `trailing_zeros` --> $DIR/trailing_zeros.rs:6:13 | -LL | let _ = (x & 0b1111 == 0); // suggest trailing_zeros +LL | let _ = (x & 0b1111 == 0); | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4` | = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` @@ -9,7 +9,7 @@ LL | let _ = (x & 0b1111 == 0); // suggest trailing_zeros error: bit mask could be simplified with a call to `trailing_zeros` --> $DIR/trailing_zeros.rs:7:13 | -LL | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros +LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` error: aborting due to 2 previous errors diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index 5aad0b44270a3..6afb1915e7e58 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -25,102 +25,160 @@ fn main() { let _: Ty = transmute(value::()); let _: Ty = transmute(value::()); - let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered - let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered + // Lint, Ty2 is unordered + let _: Ty2C = transmute(value::>()); + // Lint, Ty2 is unordered + let _: Ty2 = transmute(value::>()); - let _: Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Ty> = transmute(value::>()); // Ok, Ty2 types are the same + // Ok, Ty2 types are the same + let _: Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Ty> = transmute(value::>()); - let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances + // Lint, different Ty2 instances + let _: Ty2 = transmute(value::>>()); + // Lint, different Ty2 instances + let _: Ty> = transmute(value::>()); let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); - let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances + // Lint, different Ty2 instances + let _: &Ty2 = transmute(value::>>()); + // Lint, different Ty2 instances + let _: Ty<&Ty2> = transmute(value::<&Ty2>()); - let _: Ty = transmute(value::<&Ty2>()); // Ok, pointer to usize conversion - let _: &Ty2 = transmute(value::>()); // Ok, pointer to usize conversion + // Ok, pointer to usize conversion + let _: Ty = transmute(value::<&Ty2>()); + // Ok, pointer to usize conversion + let _: &Ty2 = transmute(value::>()); - let _: Ty<[u8; 8]> = transmute(value::>()); // Ok, transmute to byte array - let _: Ty2 = transmute(value::>()); // Ok, transmute from byte array + // Ok, transmute to byte array + let _: Ty<[u8; 8]> = transmute(value::>()); + // Ok, transmute from byte array + let _: Ty2 = transmute(value::>()); // issue #8417 - let _: Ty2C, ()> = transmute(value::>()); // Ok, Ty2 types are the same - let _: Ty2 = transmute(value::, ()>>()); // Ok, Ty2 types are the same - - let _: &'static mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Box> = transmute(value::<&'static mut Ty2>()); // Ok, Ty2 types are the same - let _: *mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Box> = transmute(value::<*mut Ty2>()); // Ok, Ty2 types are the same - - let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances - - let _: *const () = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const ()>()); // Ok, reverse type erasure - - let _: *const c_void = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const c_void>()); // Ok, reverse type erasure + // Ok, Ty2 types are the same + let _: Ty2C, ()> = transmute(value::>()); + // Ok, Ty2 types are the same + let _: Ty2 = transmute(value::, ()>>()); + + // Ok, Ty2 types are the same + let _: &'static mut Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Box> = transmute(value::<&'static mut Ty2>()); + // Ok, Ty2 types are the same + let _: *mut Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Box> = transmute(value::<*mut Ty2>()); + + // Lint, different Ty2 instances + let _: &'static mut Ty2 = transmute(value::>>()); + // Lint, different Ty2 instances + let _: Box> = transmute(value::<&'static mut Ty2>()); + + // Ok, type erasure + let _: *const () = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const ()>()); + + // Ok, type erasure + let _: *const c_void = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const c_void>()); enum Erase {} - let _: *const Erase = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const Erase>()); // Ok, reverse type erasure + // Ok, type erasure + let _: *const Erase = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const Erase>()); struct Erase2( [u8; 0], core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, ); - let _: *const Erase2 = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); // Ok, reverse type erasure - - let _: *const () = transmute(value::<&&[u8]>()); // Ok, type erasure - let _: &&[u8] = transmute(value::<*const ()>()); // Ok, reverse type erasure - - let _: *mut c_void = transmute(value::<&mut &[u8]>()); // Ok, type erasure - let _: &mut &[u8] = transmute(value::<*mut c_void>()); // Ok, reverse type erasure - - let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); // Ok, transmute to byte array - let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); // Ok, transmute from byte array - - let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array - let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from int array - - let _: *const [u8] = transmute(value::>()); // Ok - let _: Box<[u8]> = transmute(value::<*mut [u8]>()); // Ok - - let _: Ty2 = transmute(value::<(Ty2,)>()); // Ok - let _: (Ty2,) = transmute(value::>()); // Ok - - let _: Ty2 = transmute(value::<(Ty2, ())>()); // Ok - let _: (Ty2, ()) = transmute(value::>()); // Ok - - let _: Ty2 = transmute(value::<((), Ty2)>()); // Ok - let _: ((), Ty2) = transmute(value::>()); // Ok - - let _: (usize, usize) = transmute(value::<&[u8]>()); // Ok - let _: &[u8] = transmute(value::<(usize, usize)>()); // Ok + // Ok, type erasure + let _: *const Erase2 = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); + + // Ok, type erasure + let _: *const () = transmute(value::<&&[u8]>()); + // Ok, reverse type erasure + let _: &&[u8] = transmute(value::<*const ()>()); + + // Ok, type erasure + let _: *mut c_void = transmute(value::<&mut &[u8]>()); + // Ok, reverse type erasure + let _: &mut &[u8] = transmute(value::<*mut c_void>()); + + // Ok, transmute to byte array + let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); + // Ok, transmute from byte array + let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); + + // Ok, transmute to int array + let _: [usize; 2] = transmute(value::<&[u8]>()); + // Ok, transmute from int array + let _: &[u8] = transmute(value::<[usize; 2]>()); + + // Ok + let _: *const [u8] = transmute(value::>()); + // Ok + let _: Box<[u8]> = transmute(value::<*mut [u8]>()); + + // Ok + let _: Ty2 = transmute(value::<(Ty2,)>()); + // Ok + let _: (Ty2,) = transmute(value::>()); + + // Ok + let _: Ty2 = transmute(value::<(Ty2, ())>()); + // Ok + let _: (Ty2, ()) = transmute(value::>()); + + // Ok + let _: Ty2 = transmute(value::<((), Ty2)>()); + // Ok + let _: ((), Ty2) = transmute(value::>()); + + // Ok + let _: (usize, usize) = transmute(value::<&[u8]>()); + // Ok + let _: &[u8] = transmute(value::<(usize, usize)>()); trait Trait {} - let _: (isize, isize) = transmute(value::<&dyn Trait>()); // Ok - let _: &dyn Trait = transmute(value::<(isize, isize)>()); // Ok - - let _: MaybeUninit> = transmute(value::>()); // Ok - let _: Ty2 = transmute(value::>>()); // Ok - - let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec>()); // Ok - - let _: *const Ty2 = transmute(value::<*const Ty2C, u32>>()); // Ok - let _: *const Ty2C, u32> = transmute(value::<*const Ty2>()); // Ok - let _: *const Ty2 = transmute(value::<*const Ty2C<(), Ty2>>()); // Ok - let _: *const Ty2C<(), Ty2> = transmute(value::<*const Ty2>()); // Ok - - let _: *const Ty2 = transmute(value::<*const Ty2C>>()); // Err - let _: *const Ty2C> = transmute(value::<*const Ty2>()); // Err - - let _: NonNull = transmute(value::>()); // Ok - let _: NonNull<(String, String)> = transmute(value::>()); // Ok + // Ok + let _: (isize, isize) = transmute(value::<&dyn Trait>()); + let _: &dyn Trait = transmute(value::<(isize, isize)>()); + + // Ok + let _: MaybeUninit> = transmute(value::>()); + // Ok + let _: Ty2 = transmute(value::>>()); + + // Ok + let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec>()); + + // Ok + let _: *const Ty2 = transmute(value::<*const Ty2C, u32>>()); + // Ok + let _: *const Ty2C, u32> = transmute(value::<*const Ty2>()); + // Ok + let _: *const Ty2 = transmute(value::<*const Ty2C<(), Ty2>>()); + // Ok + let _: *const Ty2C<(), Ty2> = transmute(value::<*const Ty2>()); + + // Err + let _: *const Ty2 = transmute(value::<*const Ty2C>>()); + // Err + let _: *const Ty2C> = transmute(value::<*const Ty2>()); + + // Ok + let _: NonNull = transmute(value::>()); + // Ok + let _: NonNull<(String, String)> = transmute(value::>()); } } @@ -129,28 +187,44 @@ fn _with_generics() { return; } unsafe { - let _: &u32 = transmute(value::<&T>()); // Ok - let _: &T = transmute(value::<&u32>()); // Ok - - let _: Vec = transmute(value::>()); // Ok - let _: Vec = transmute(value::>()); // Ok - - let _: Ty<&u32> = transmute(value::<&T>()); // Ok - let _: Ty<&T> = transmute(value::<&u32>()); // Ok - - let _: Vec = transmute(value::>()); // Ok - let _: Vec = transmute(value::>()); // Ok - - let _: &Ty2 = transmute(value::<&Ty2>()); // Ok - let _: &Ty2 = transmute(value::<&Ty2>()); // Ok - - let _: Vec> = transmute(value::>>()); // Ok - let _: Vec> = transmute(value::>>()); // Ok - - let _: Vec> = transmute(value::>>()); // Err - let _: Vec> = transmute(value::>>()); // Err - - let _: *const u32 = transmute(value::>()); // Ok - let _: Box = transmute(value::<*const u32>()); // Ok + // Ok + let _: &u32 = transmute(value::<&T>()); + // Ok + let _: &T = transmute(value::<&u32>()); + + // Ok + let _: Vec = transmute(value::>()); + // Ok + let _: Vec = transmute(value::>()); + + // Ok + let _: Ty<&u32> = transmute(value::<&T>()); + // Ok + let _: Ty<&T> = transmute(value::<&u32>()); + + // Ok + let _: Vec = transmute(value::>()); + // Ok + let _: Vec = transmute(value::>()); + + // Ok + let _: &Ty2 = transmute(value::<&Ty2>()); + // Ok + let _: &Ty2 = transmute(value::<&Ty2>()); + + // Ok + let _: Vec> = transmute(value::>>()); + // Ok + let _: Vec> = transmute(value::>>()); + + // Err + let _: Vec> = transmute(value::>>()); + // Err + let _: Vec> = transmute(value::>>()); + + // Ok + let _: *const u32 = transmute(value::>()); + // Ok + let _: Box = transmute(value::<*const u32>()); } } diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index e50a773290e17..220bcb5b528dc 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -1,93 +1,93 @@ error: transmute from `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:28:33 + --> $DIR/transmute_undefined_repr.rs:29:33 | -LL | let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered +LL | let _: Ty2C = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::transmute-undefined-repr` implied by `-D warnings` error: transmute into `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:29:32 + --> $DIR/transmute_undefined_repr.rs:31:32 | -LL | let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered +LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:34:32 + --> $DIR/transmute_undefined_repr.rs:39:32 | -LL | let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty2` to `Ty>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:35:36 + --> $DIR/transmute_undefined_repr.rs:41:36 | -LL | let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances +LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty<&Ty2>` to `&Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:40:33 + --> $DIR/transmute_undefined_repr.rs:47:33 | -LL | let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&Ty2` to `Ty<&Ty2>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:41:37 + --> $DIR/transmute_undefined_repr.rs:49:37 | -LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances +LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `std::boxed::Box>` to `&mut Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:58:45 + --> $DIR/transmute_undefined_repr.rs:77:45 | -LL | let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&mut Ty2` to `std::boxed::Box>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:59:37 + --> $DIR/transmute_undefined_repr.rs:79:37 | -LL | let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances +LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute into `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:119:39 + --> $DIR/transmute_undefined_repr.rs:174:39 | -LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); // Err +LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the contained type `Ty2` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:120:50 + --> $DIR/transmute_undefined_repr.rs:176:50 | -LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); // Err +LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the contained type `Ty2` has an undefined layout error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:150:35 + --> $DIR/transmute_undefined_repr.rs:221:35 | -LL | let _: Vec> = transmute(value::>>()); // Err +LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Vec`) may have different layouts error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:151:35 + --> $DIR/transmute_undefined_repr.rs:223:35 | -LL | let _: Vec> = transmute(value::>>()); // Err +LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Vec`) may have different layouts diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 903c240bfcaba..c9585e519883c 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -1,4 +1,4 @@ -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:11 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} @@ -10,13 +10,13 @@ note: the lint level is defined here LL | #![deny(clippy::trivially_copy_pass_by_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:20 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:29 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index a250de30d5c42..c71a4cb6f7a7f 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -30,6 +30,8 @@ fn main() { writeln!(v, r#"{}"#, "\\"); writeln!(v, "{}", r"\"); writeln!(v, "{}", "\r"); - writeln!(v, r#"{}{}"#, '#', '"'); // hard mode - writeln!(v, r"{}", "\r"); // should not lint + // hard mode + writeln!(v, r#"{}{}"#, '#', '"'); + // should not lint + writeln!(v, r"{}", "\r"); } diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index b28bee56dc248..c78a92f56eeff 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -183,15 +183,15 @@ LL + writeln!(v, "\r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:33:28 + --> $DIR/write_literal_2.rs:34:28 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:33:33 + --> $DIR/write_literal_2.rs:34:33 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: aborting due to 18 previous errors diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index f1daeb1324045..c0e6c2a826405 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -27,16 +27,20 @@ fn main() { write!(v, "\n\n"); write!(v, "like eof\n\n"); write!(v, "Hello {} {}\n\n", "world", "#2"); - writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(v, "\nbla\n\n"); // #3126 + // #3126 + writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + writeln!(v, "\nbla\n\n"); // Escaping - write!(v, "\\n"); // #3514 - writeln!(v, "\\"); // should fail + // #3514 + write!(v, "\\n"); + writeln!(v, "\\"); write!(v, "\\\\n"); // Raw strings - write!(v, r"\n"); // #3778 + // #3778 + write!(v, r"\n"); // Literal newlines should also fail writeln!( diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index f8f3002fed6ab..bacafdc8ad4ea 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -27,16 +27,20 @@ fn main() { write!(v, "\n\n"); write!(v, "like eof\n\n"); write!(v, "Hello {} {}\n\n", "world", "#2"); - writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(v, "\nbla\n\n"); // #3126 + // #3126 + writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + writeln!(v, "\nbla\n\n"); // Escaping - write!(v, "\\n"); // #3514 - write!(v, "\\\n"); // should fail + // #3514 + write!(v, "\\n"); + write!(v, "\\\n"); write!(v, "\\\\n"); // Raw strings - write!(v, r"\n"); // #3778 + // #3778 + write!(v, r"\n"); // Literal newlines should also fail write!( diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index cec236038eb02..4ab6919b6b214 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -60,19 +60,19 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:35:5 + --> $DIR/write_with_newline.rs:38:5 | -LL | write!(v, "\\\n"); // should fail +LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "\\\n"); // should fail -LL + writeln!(v, "\\"); // should fail +LL - write!(v, "\\\n"); +LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:42:5 + --> $DIR/write_with_newline.rs:46:5 | LL | / write!( LL | | v, @@ -88,7 +88,7 @@ LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:47:5 + --> $DIR/write_with_newline.rs:51:5 | LL | / write!( LL | | v, @@ -104,7 +104,7 @@ LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:56:5 + --> $DIR/write_with_newline.rs:60:5 | LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ From a05d3a41377f72eb87d7789e96575bd0e445397c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 28 Jul 2023 21:35:48 +0200 Subject: [PATCH 3/4] Automatic generation of error annotations for ui tests --- tests/ui/absurd-extreme-comparisons.rs | 19 ++ tests/ui/absurd-extreme-comparisons.stderr | 34 +-- tests/ui/approx_const.rs | 23 ++ tests/ui/approx_const.stderr | 44 ++-- tests/ui/as_ptr_cast_mut.rs | 3 + tests/ui/as_ptr_cast_mut.stderr | 2 +- tests/ui/asm_syntax.rs | 5 + tests/ui/asm_syntax.stderr | 8 +- tests/ui/assertions_on_constants.rs | 9 + tests/ui/assertions_on_constants.stderr | 16 +- tests/ui/assign_ops2.rs | 12 ++ tests/ui/assign_ops2.stderr | 18 +- tests/ui/attrs.rs | 5 + tests/ui/attrs.stderr | 4 +- tests/ui/await_holding_lock.rs | 13 ++ tests/ui/await_holding_lock.stderr | 63 +++--- tests/ui/await_holding_refcell_ref.rs | 6 + tests/ui/await_holding_refcell_ref.stderr | 28 +-- tests/ui/bit_masks.rs | 20 ++ tests/ui/bit_masks.stderr | 30 +-- tests/ui/blanket_clippy_restriction_lints.rs | 3 + .../blanket_clippy_restriction_lints.stderr | 4 +- tests/ui/blocks_in_if_conditions_closure.rs | 3 + .../ui/blocks_in_if_conditions_closure.stderr | 5 +- tests/ui/borrow_box.rs | 10 + tests/ui/borrow_box.stderr | 18 +- tests/ui/borrow_deref_ref_unfixable.rs | 2 + tests/ui/box_collection.rs | 9 + tests/ui/box_collection.stderr | 16 +- tests/ui/boxed_local.rs | 5 + tests/ui/boxed_local.stderr | 6 +- .../branches_sharing_code/shared_at_bottom.rs | 12 ++ .../shared_at_bottom.stderr | 32 ++- .../ui/branches_sharing_code/shared_at_top.rs | 7 + .../shared_at_top.stderr | 21 +- .../shared_at_top_and_bottom.rs | 5 + .../shared_at_top_and_bottom.stderr | 23 +- .../branches_sharing_code/valid_if_blocks.rs | 5 + .../valid_if_blocks.stderr | 22 +- tests/ui/bytecount.rs | 3 + tests/ui/bytecount.stderr | 4 +- tests/ui/cast.rs | 57 +++++ tests/ui/cast.stderr | 100 ++++----- tests/ui/cast_alignment.rs | 5 + tests/ui/cast_alignment.stderr | 6 +- tests/ui/cast_enum_constructor.rs | 3 + tests/ui/cast_enum_constructor.stderr | 2 +- tests/ui/cast_nan_to_int.rs | 12 ++ tests/ui/cast_nan_to_int.stderr | 10 +- tests/ui/cast_size.rs | 20 ++ tests/ui/cast_size.stderr | 34 +-- tests/ui/cast_size_32bit.rs | 21 ++ tests/ui/cast_slice_different_sizes.rs | 15 ++ tests/ui/cast_slice_different_sizes.stderr | 36 ++-- tests/ui/cfg_features.fixed | 5 + tests/ui/cfg_features.rs | 5 + tests/ui/cfg_features.stderr | 6 +- tests/ui/char_lit_as_u8.rs | 2 + .../ui/checked_unwrap/complex_conditionals.rs | 20 ++ .../complex_conditionals.stderr | 38 ++-- .../complex_conditionals_nested.rs | 2 + .../complex_conditionals_nested.stderr | 2 +- .../ui/checked_unwrap/simple_conditionals.rs | 16 ++ .../checked_unwrap/simple_conditionals.stderr | 30 +-- tests/ui/cmp_null.rs | 3 + tests/ui/cmp_null.stderr | 2 +- tests/ui/cmp_owned/without_suggestion.rs | 4 + tests/ui/cmp_owned/without_suggestion.stderr | 4 +- tests/ui/cognitive_complexity.rs | 20 ++ tests/ui/cognitive_complexity.stderr | 38 ++-- tests/ui/cognitive_complexity_attr_used.rs | 1 + tests/ui/collapsible_match.rs | 12 ++ tests/ui/collapsible_match.stderr | 64 +++--- tests/ui/collapsible_match2.rs | 4 + tests/ui/collapsible_match2.stderr | 24 ++- tests/ui/collection_is_never_read.rs | 21 ++ tests/ui/collection_is_never_read.stderr | 38 ++-- tests/ui/comparison_chain.rs | 7 + tests/ui/comparison_chain.stderr | 34 +-- tests/ui/const_comparisons.rs | 44 ++++ tests/ui/const_comparisons.stderr | 60 +++--- tests/ui/copy_iterator.rs | 2 + tests/ui/copy_iterator.stderr | 4 +- tests/ui/crashes/ice-10912.rs | 6 +- tests/ui/crashes/ice-10912.stderr | 4 +- tests/ui/crashes/ice-2774.fixed | 2 + tests/ui/crashes/ice-2774.rs | 2 + tests/ui/crashes/ice-360.rs | 3 + tests/ui/crashes/ice-360.stderr | 10 +- tests/ui/crashes/ice-3717.fixed | 1 + tests/ui/crashes/ice-3717.rs | 1 + tests/ui/crashes/ice-3891.rs | 1 + tests/ui/crashes/ice-3969.rs | 6 + tests/ui/crashes/ice-3969.stderr | 8 +- tests/ui/crashes/ice-5835.fixed | 2 + tests/ui/crashes/ice-5835.rs | 2 + tests/ui/crashes/ice-5872.fixed | 2 + tests/ui/crashes/ice-5872.rs | 2 + tests/ui/crashes/ice-6254.rs | 2 + tests/ui/crashes/ice-7169.fixed | 2 + tests/ui/crashes/ice-7169.rs | 2 + tests/ui/crashes/ice-7869.rs | 1 + tests/ui/crashes/ice-7869.stderr | 1 + tests/ui/crashes/ice-8250.fixed | 2 + tests/ui/crashes/ice-8250.rs | 2 + tests/ui/crashes/ice-8821.fixed | 2 + tests/ui/crashes/ice-8821.rs | 2 + tests/ui/crashes/ice-8850.fixed | 4 + tests/ui/crashes/ice-8850.rs | 4 + tests/ui/crashes/ice-8850.stderr | 4 +- tests/ui/crashes/ice-9041.rs | 2 + tests/ui/crashes/ice-9445.rs | 2 + tests/ui/crashes/ice-9463.rs | 4 + tests/ui/crashes/ice-9463.stderr | 4 +- .../needless_lifetimes_impl_trait.fixed | 1 + .../crashes/needless_lifetimes_impl_trait.rs | 1 + .../needless_pass_by_value-w-late-bound.fixed | 1 + .../needless_pass_by_value-w-late-bound.rs | 1 + tests/ui/crate_level_checks/no_std_swap.rs | 2 + .../ui/crate_level_checks/no_std_swap.stderr | 2 + .../crate_level_checks/std_main_recursion.rs | 1 + tests/ui/dbg_macro.rs | 19 ++ tests/ui/dbg_macro.stderr | 34 +-- tests/ui/debug_assert_with_mut_call.rs | 29 +++ tests/ui/debug_assert_with_mut_call.stderr | 54 ++--- tests/ui/def_id_nocore.rs | 1 + tests/ui/default_union_representation.rs | 4 + tests/ui/default_union_representation.stderr | 10 +- tests/ui/deprecated_old.rs | 4 + tests/ui/deprecated_old.stderr | 4 +- tests/ui/deref_addrof_double_trigger.rs | 4 + tests/ui/deref_addrof_double_trigger.stderr | 4 +- tests/ui/derive.rs | 5 + tests/ui/derive.stderr | 26 ++- tests/ui/derive_ord_xor_partial_ord.rs | 4 + tests/ui/derive_ord_xor_partial_ord.stderr | 16 +- tests/ui/derived_hash_with_manual_eq.rs | 2 + tests/ui/derived_hash_with_manual_eq.stderr | 6 +- tests/ui/disallowed_names.rs | 15 ++ tests/ui/disallowed_names.stderr | 26 +-- tests/ui/disallowed_script_idents.rs | 2 + tests/ui/disallowed_script_idents.stderr | 2 +- tests/ui/diverging_sub_expression.rs | 12 ++ tests/ui/diverging_sub_expression.stderr | 20 +- tests/ui/doc/unbalanced_ticks.rs | 8 + tests/ui/doc/unbalanced_ticks.stderr | 15 +- tests/ui/doc_errors.rs | 8 + tests/ui/doc_errors.stderr | 12 +- tests/ui/doc_link_with_quotes.rs | 2 + tests/ui/double_must_use.rs | 4 + tests/ui/double_must_use.stderr | 6 +- tests/ui/double_neg.rs | 2 + tests/ui/double_parens.rs | 7 + tests/ui/double_parens.stderr | 10 +- tests/ui/drop_non_drop.rs | 2 + tests/ui/drop_non_drop.stderr | 4 +- tests/ui/duplicate_underscore_argument.rs | 2 + tests/ui/empty_enum.rs | 1 + tests/ui/empty_loop_no_std.rs | 2 + tests/ui/empty_loop_no_std.stderr | 2 +- tests/ui/enum_clike_unportable_variant.rs | 10 + tests/ui/enum_variants.rs | 15 ++ tests/ui/enum_variants.stderr | 44 ++-- tests/ui/eprint_with_newline.fixed | 10 + tests/ui/eprint_with_newline.rs | 10 + tests/ui/eprint_with_newline.stderr | 20 +- tests/ui/eq_op.rs | 31 +++ tests/ui/eq_op.stderr | 56 ++--- tests/ui/eq_op_macros.rs | 8 + tests/ui/eq_op_macros.stderr | 14 +- tests/ui/erasing_op.rs | 6 + tests/ui/erasing_op.stderr | 8 +- tests/ui/error_impl_error.rs | 4 + tests/ui/error_impl_error.stderr | 12 +- tests/ui/exit1.rs | 2 + tests/ui/exit2.rs | 2 + tests/ui/expect.rs | 3 + tests/ui/expect.stderr | 4 +- tests/ui/expect_tool_lint_rfc_2383.rs | 7 + tests/ui/expect_tool_lint_rfc_2383.stderr | 10 +- tests/ui/explicit_counter_loop.rs | 11 + tests/ui/explicit_counter_loop.stderr | 16 +- .../extra_unused_type_parameters_unfixable.rs | 3 + ...ra_unused_type_parameters_unfixable.stderr | 4 +- tests/ui/fallible_impl_from.rs | 4 + tests/ui/fallible_impl_from.stderr | 21 +- tests/ui/filetype_is_file.rs | 3 + tests/ui/filetype_is_file.stderr | 4 +- tests/ui/filter_map_next.rs | 2 + tests/ui/filter_map_next.stderr | 4 +- tests/ui/float_arithmetic.rs | 18 ++ tests/ui/float_arithmetic.stderr | 32 +-- tests/ui/float_cmp.rs | 12 ++ tests/ui/float_cmp.stderr | 10 +- tests/ui/float_cmp_const.rs | 16 ++ tests/ui/float_cmp_const.stderr | 14 +- tests/ui/float_equality_without_abs.rs | 12 ++ tests/ui/float_equality_without_abs.stderr | 20 +- tests/ui/fn_address_comparisons.rs | 3 + tests/ui/fn_address_comparisons.stderr | 2 +- tests/ui/fn_params_excessive_bools.rs | 7 + tests/ui/fn_params_excessive_bools.stderr | 14 +- tests/ui/fn_to_numeric_cast.rs | 25 +++ tests/ui/fn_to_numeric_cast.stderr | 44 ++-- tests/ui/fn_to_numeric_cast_32bit.rs | 25 +++ tests/ui/fn_to_numeric_cast_any.rs | 18 ++ tests/ui/fn_to_numeric_cast_any.stderr | 32 +-- tests/ui/for_kv_map.fixed | 6 + tests/ui/for_kv_map.rs | 6 + tests/ui/for_kv_map.stderr | 8 +- tests/ui/forget_non_drop.rs | 2 + tests/ui/forget_non_drop.stderr | 4 +- tests/ui/format_args_unfixable.rs | 18 ++ tests/ui/format_args_unfixable.stderr | 36 ++-- tests/ui/format_collect.rs | 3 + tests/ui/format_collect.stderr | 13 +- tests/ui/format_push_string.rs | 5 + tests/ui/format_push_string.stderr | 11 +- tests/ui/formatting.rs | 12 ++ tests/ui/formatting.stderr | 10 +- tests/ui/from_over_into_unfixable.rs | 4 + tests/ui/from_over_into_unfixable.stderr | 6 +- tests/ui/from_raw_with_void_ptr.rs | 5 + tests/ui/from_raw_with_void_ptr.stderr | 16 +- tests/ui/from_str_radix_10.fixed | 9 + tests/ui/from_str_radix_10.rs | 9 + tests/ui/from_str_radix_10.stderr | 14 +- tests/ui/functions.rs | 18 ++ tests/ui/functions.stderr | 32 +-- tests/ui/functions_maxlines.rs | 2 + tests/ui/functions_maxlines.stderr | 4 +- tests/ui/future_not_send.rs | 8 + tests/ui/future_not_send.stderr | 39 ++-- tests/ui/if_let_mutex.rs | 3 + tests/ui/if_let_mutex.stderr | 7 +- tests/ui/if_not_else.rs | 2 + tests/ui/if_not_else.stderr | 4 +- tests/ui/if_then_some_else_none.rs | 5 + tests/ui/if_then_some_else_none.stderr | 11 +- tests/ui/impl.rs | 4 + tests/ui/impl.stderr | 13 +- tests/ui/impl_trait_in_params.rs | 3 + tests/ui/impl_trait_in_params.stderr | 2 +- ...partial_ord_impl_on_ord_type_fully_qual.rs | 3 + ...ial_ord_impl_on_ord_type_fully_qual.stderr | 5 +- .../if_let_slice_binding.fixed | 10 + .../if_let_slice_binding.rs | 10 + .../if_let_slice_binding.stderr | 18 +- .../slice_indexing_in_macro.fixed | 1 + .../slice_indexing_in_macro.rs | 1 + tests/ui/indexing_slicing_index.rs | 10 + tests/ui/indexing_slicing_index.stderr | 24 +-- tests/ui/indexing_slicing_slice.rs | 17 ++ tests/ui/indexing_slicing_slice.stderr | 30 +-- tests/ui/infinite_iter.rs | 15 ++ tests/ui/infinite_iter.stderr | 30 +-- tests/ui/infinite_loop.rs | 24 +++ tests/ui/infinite_loop.stderr | 22 +- tests/ui/inherent_to_string.rs | 2 + tests/ui/inherent_to_string.stderr | 4 +- tests/ui/inspect_for_each.rs | 1 + tests/ui/inspect_for_each.stderr | 1 + tests/ui/integer_division.rs | 3 + tests/ui/integer_division.stderr | 4 +- tests/ui/invalid_upcast_comparisons.rs | 28 +++ tests/ui/invalid_upcast_comparisons.stderr | 52 ++--- tests/ui/issue-7447.rs | 3 + tests/ui/issue-7447.stderr | 2 +- tests/ui/issue_4266.rs | 4 + tests/ui/issue_4266.stderr | 4 +- tests/ui/items_after_statement.rs | 3 + tests/ui/items_after_statement.stderr | 7 +- tests/ui/iter_not_returning_iterator.rs | 4 + tests/ui/iter_not_returning_iterator.stderr | 4 +- tests/ui/iter_skip_next_unfixable.rs | 3 + tests/ui/iter_skip_next_unfixable.stderr | 8 +- tests/ui/iterator_step_by_zero.rs | 8 + tests/ui/iterator_step_by_zero.stderr | 12 +- tests/ui/large_futures.fixed | 8 + tests/ui/large_futures.rs | 8 + tests/ui/large_futures.stderr | 16 +- tests/ui/large_stack_arrays.rs | 7 + tests/ui/large_stack_arrays.stderr | 12 +- tests/ui/large_stack_frames.rs | 6 + tests/ui/large_stack_frames.stderr | 12 +- tests/ui/len_without_is_empty.rs | 16 ++ tests/ui/len_without_is_empty.stderr | 40 ++-- tests/ui/let_and_return.fixed | 5 + tests/ui/let_and_return.rs | 5 + tests/ui/let_and_return.stderr | 6 +- tests/ui/let_if_seq.rs | 7 + tests/ui/let_if_seq.stderr | 17 +- tests/ui/let_underscore_future.rs | 5 + tests/ui/let_underscore_future.stderr | 6 +- tests/ui/let_underscore_lock.rs | 4 + tests/ui/let_underscore_lock.stderr | 6 +- tests/ui/let_underscore_must_use.rs | 12 ++ tests/ui/let_underscore_must_use.stderr | 22 +- tests/ui/linkedlist.rs | 9 + tests/ui/linkedlist.stderr | 16 +- tests/ui/literals.rs | 26 +++ tests/ui/literals.stderr | 38 ++-- tests/ui/manual_clamp.fixed | 36 ++++ tests/ui/manual_clamp.rs | 70 +++++++ tests/ui/manual_clamp.stderr | 145 +++++++------ tests/ui/manual_find.rs | 4 + tests/ui/manual_find.stderr | 12 +- tests/ui/manual_flatten.rs | 9 + tests/ui/manual_flatten.stderr | 45 ++-- tests/ui/manual_let_else.rs | 26 +++ tests/ui/manual_let_else.stderr | 75 ++++--- tests/ui/manual_let_else_match.rs | 10 + tests/ui/manual_let_else_match.stderr | 26 ++- tests/ui/manual_memcpy/with_loop_counters.rs | 12 ++ .../manual_memcpy/with_loop_counters.stderr | 32 ++- .../ui/manual_memcpy/without_loop_counters.rs | 14 ++ .../without_loop_counters.stderr | 38 ++-- tests/ui/manual_non_exhaustive_enum.rs | 2 + tests/ui/manual_non_exhaustive_enum.stderr | 8 +- tests/ui/manual_non_exhaustive_struct.rs | 4 + tests/ui/manual_non_exhaustive_struct.stderr | 16 +- tests/ui/manual_strip.rs | 8 + tests/ui/manual_strip.stderr | 32 +-- tests/ui/many_single_char_names.rs | 6 + tests/ui/many_single_char_names.stderr | 7 +- tests/ui/map_err.rs | 1 + tests/ui/map_flatten.rs | 5 + tests/ui/map_flatten.stderr | 21 +- tests/ui/match_bool.rs | 10 + tests/ui/match_bool.stderr | 27 ++- tests/ui/match_on_vec_items.rs | 9 + tests/ui/match_on_vec_items.stderr | 14 +- tests/ui/match_overlapping_arm.rs | 8 + tests/ui/match_overlapping_arm.stderr | 30 +-- tests/ui/match_same_arms_non_exhaustive.rs | 2 + .../ui/match_same_arms_non_exhaustive.stderr | 6 +- tests/ui/match_wild_err_arm.rs | 8 + tests/ui/match_wild_err_arm.stderr | 6 +- tests/ui/mem_forget.rs | 8 + tests/ui/mem_forget.stderr | 6 +- tests/ui/methods_unfixable.rs | 1 + tests/ui/min_max.rs | 14 ++ tests/ui/min_max.stderr | 24 +-- tests/ui/min_rust_version_attr.rs | 6 + tests/ui/min_rust_version_attr.stderr | 10 +- tests/ui/min_rust_version_invalid_attr.rs | 5 + tests/ui/min_rust_version_invalid_attr.stderr | 14 +- tests/ui/mismatching_type_param_order.rs | 10 + tests/ui/mismatching_type_param_order.stderr | 16 +- tests/ui/misnamed_getters.fixed | 19 ++ tests/ui/misnamed_getters.rs | 19 ++ tests/ui/misnamed_getters.stderr | 53 +++-- tests/ui/missing_assert_message.rs | 16 ++ tests/ui/missing_assert_message.stderr | 30 +-- .../ui/missing_const_for_fn/could_be_const.rs | 12 ++ .../could_be_const.stderr | 32 ++- tests/ui/missing_doc_crate_missing.rs | 2 + tests/ui/missing_doc_crate_missing.stderr | 2 + tests/ui/missing_fields_in_debug.rs | 3 + tests/ui/missing_fields_in_debug.stderr | 20 +- tests/ui/missing_inline.rs | 7 + tests/ui/missing_inline.stderr | 10 +- tests/ui/missing_trait_methods.rs | 2 + tests/ui/missing_trait_methods.stderr | 2 +- tests/ui/mixed_read_write_in_expression.rs | 4 + .../ui/mixed_read_write_in_expression.stderr | 12 +- tests/ui/module_inception.rs | 5 + tests/ui/module_inception.stderr | 11 +- tests/ui/module_name_repetitions.rs | 6 + tests/ui/module_name_repetitions.stderr | 8 +- tests/ui/modulo_arithmetic_float.rs | 20 ++ tests/ui/modulo_arithmetic_float.stderr | 18 +- tests/ui/modulo_arithmetic_integral.rs | 34 +++ tests/ui/modulo_arithmetic_integral.stderr | 32 +-- tests/ui/modulo_arithmetic_integral_const.rs | 34 +++ .../modulo_arithmetic_integral_const.stderr | 32 +-- tests/ui/modulo_one.rs | 11 + tests/ui/modulo_one.stderr | 16 +- tests/ui/multi_assignments.rs | 7 + tests/ui/multi_assignments.stderr | 10 +- tests/ui/mut_from_ref.rs | 6 + tests/ui/mut_from_ref.stderr | 20 +- tests/ui/mut_key.rs | 20 ++ tests/ui/mut_key.stderr | 30 +-- tests/ui/mut_range_bound.rs | 14 ++ tests/ui/mut_range_bound.stderr | 12 +- tests/ui/mut_reference.rs | 6 + tests/ui/mut_reference.stderr | 6 +- tests/ui/mutex_atomic.rs | 9 + tests/ui/mutex_atomic.stderr | 12 +- tests/ui/needless_borrow_pat.fixed | 13 ++ tests/ui/needless_borrow_pat.rs | 13 ++ tests/ui/needless_borrow_pat.stderr | 26 ++- tests/ui/needless_collect_indirect.rs | 17 ++ tests/ui/needless_collect_indirect.stderr | 65 ++++-- tests/ui/needless_continue.rs | 8 + tests/ui/needless_continue.stderr | 22 +- tests/ui/needless_doc_main.rs | 11 +- tests/ui/needless_doc_main.stderr | 6 +- tests/ui/needless_for_each_unfixable.rs | 2 + tests/ui/needless_for_each_unfixable.stderr | 8 +- tests/ui/needless_pass_by_value.rs | 23 ++ tests/ui/needless_pass_by_value.stderr | 50 ++--- tests/ui/needless_range_loop.rs | 15 ++ tests/ui/needless_range_loop.stderr | 26 +-- tests/ui/needless_range_loop2.rs | 9 + tests/ui/needless_range_loop2.stderr | 14 +- tests/ui/needless_update.rs | 2 + tests/ui/neg_cmp_op_on_partial_ord.rs | 5 + tests/ui/neg_cmp_op_on_partial_ord.stderr | 6 +- tests/ui/never_loop.rs | 16 ++ tests/ui/never_loop.stderr | 57 ++--- tests/ui/new_ret_no_self.rs | 13 ++ tests/ui/new_ret_no_self.stderr | 33 ++- tests/ui/new_without_default.fixed | 8 + tests/ui/new_without_default.rs | 8 + tests/ui/new_without_default.stderr | 22 +- tests/ui/no_effect.rs | 31 +++ tests/ui/no_effect.stderr | 56 ++--- tests/ui/no_effect_replace.rs | 9 + tests/ui/no_effect_replace.stderr | 14 +- tests/ui/no_effect_return.rs | 10 + tests/ui/no_effect_return.stderr | 16 +- tests/ui/no_mangle_with_rust_abi.rs | 6 + tests/ui/no_mangle_with_rust_abi.stderr | 9 +- tests/ui/non_minimal_cfg2.rs | 2 + tests/ui/non_send_fields_in_send_ty.rs | 12 ++ tests/ui/non_send_fields_in_send_ty.stderr | 48 ++--- tests/ui/nonminimal_bool.rs | 14 ++ tests/ui/nonminimal_bool.stderr | 24 +-- tests/ui/octal_escapes.rs | 9 + tests/ui/octal_escapes.stderr | 16 +- tests/ui/ok_expect.rs | 5 + tests/ui/ok_expect.stderr | 8 +- tests/ui/only_used_in_recursion.rs | 16 ++ tests/ui/only_used_in_recursion.stderr | 62 +++--- tests/ui/only_used_in_recursion2.rs | 5 + tests/ui/only_used_in_recursion2.stderr | 18 +- tests/ui/op_ref.fixed | 5 + tests/ui/op_ref.rs | 5 + tests/ui/op_ref.stderr | 6 +- tests/ui/open_options.rs | 8 + tests/ui/open_options.stderr | 12 +- tests/ui/option_option.rs | 12 ++ tests/ui/option_option.stderr | 22 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 3 + .../out_of_bounds_indexing/issue-3102.stderr | 2 +- tests/ui/out_of_bounds_indexing/simple.rs | 7 + tests/ui/out_of_bounds_indexing/simple.stderr | 10 +- tests/ui/overflow_check_conditional.rs | 9 + tests/ui/overflow_check_conditional.stderr | 14 +- tests/ui/overly_complex_bool_expr.fixed | 5 + tests/ui/overly_complex_bool_expr.rs | 5 + tests/ui/overly_complex_bool_expr.stderr | 16 +- tests/ui/panic_in_result_fn.rs | 2 + tests/ui/panic_in_result_fn.stderr | 8 +- tests/ui/panic_in_result_fn_assertions.rs | 3 + tests/ui/panic_in_result_fn_assertions.stderr | 13 +- tests/ui/panicking_macros.rs | 20 ++ tests/ui/panicking_macros.stderr | 30 +-- tests/ui/partial_pub_fields.rs | 4 + tests/ui/partial_pub_fields.stderr | 6 +- tests/ui/partialeq_ne_impl.rs | 2 + tests/ui/partialeq_ne_impl.stderr | 2 + tests/ui/pattern_type_mismatch/mutability.rs | 2 + .../pattern_type_mismatch/mutability.stderr | 2 +- .../pattern_alternatives.rs | 3 + .../pattern_alternatives.stderr | 4 +- .../pattern_type_mismatch/pattern_structs.rs | 8 + .../pattern_structs.stderr | 14 +- .../pattern_type_mismatch/pattern_tuples.rs | 10 + .../pattern_tuples.stderr | 18 +- tests/ui/pattern_type_mismatch/syntax.rs | 8 + tests/ui/pattern_type_mismatch/syntax.stderr | 16 +- tests/ui/permissions_set_readonly_false.rs | 2 + tests/ui/print.rs | 10 + tests/ui/print.stderr | 14 +- tests/ui/print_in_format_impl.rs | 8 + tests/ui/print_in_format_impl.stderr | 12 +- tests/ui/print_literal.fixed | 13 ++ tests/ui/print_literal.rs | 13 ++ tests/ui/print_literal.stderr | 22 +- tests/ui/print_stderr.rs | 3 + tests/ui/print_stderr.stderr | 2 +- tests/ui/print_with_newline.fixed | 10 + tests/ui/print_with_newline.rs | 10 + tests/ui/print_with_newline.stderr | 20 +- tests/ui/proc_macro.rs | 1 + tests/ui/ptr_arg.rs | 24 +++ tests/ui/ptr_arg.stderr | 51 +++-- tests/ui/pub_use.rs | 1 + tests/ui/question_mark_used.rs | 1 + tests/ui/range.rs | 2 + tests/ui/rc_clone_in_vec_init/arc.rs | 8 + tests/ui/rc_clone_in_vec_init/arc.stderr | 14 +- tests/ui/rc_clone_in_vec_init/rc.rs | 8 + tests/ui/rc_clone_in_vec_init/rc.stderr | 14 +- tests/ui/rc_clone_in_vec_init/weak.rs | 16 ++ tests/ui/rc_clone_in_vec_init/weak.stderr | 22 +- tests/ui/rc_mutex.rs | 4 + tests/ui/rc_mutex.stderr | 6 +- tests/ui/read_zero_byte_vec.rs | 11 + tests/ui/read_zero_byte_vec.stderr | 18 +- tests/ui/readonly_write_lock.fixed | 3 + tests/ui/readonly_write_lock.rs | 3 + tests/ui/readonly_write_lock.stderr | 2 +- tests/ui/recursive_format_impl.rs | 11 + tests/ui/recursive_format_impl.stderr | 18 +- tests/ui/redundant_allocation.rs | 40 ++++ tests/ui/redundant_allocation.stderr | 38 ++-- tests/ui/redundant_closure_call_early.rs | 3 + tests/ui/redundant_closure_call_early.stderr | 2 +- tests/ui/redundant_closure_call_late.rs | 4 + tests/ui/redundant_closure_call_late.stderr | 4 +- tests/ui/redundant_else.rs | 7 + tests/ui/redundant_else.stderr | 19 +- .../ui/redundant_static_lifetimes_multiple.rs | 11 + ...redundant_static_lifetimes_multiple.stderr | 16 +- tests/ui/redundant_type_annotations.rs | 18 ++ tests/ui/redundant_type_annotations.stderr | 32 +-- tests/ui/ref_binding_to_reference.rs | 8 + tests/ui/ref_binding_to_reference.stderr | 17 +- tests/ui/ref_option_ref.rs | 12 ++ tests/ui/ref_option_ref.stderr | 20 +- tests/ui/ref_patterns.rs | 3 + tests/ui/ref_patterns.stderr | 4 +- tests/ui/regex.rs | 19 ++ tests/ui/regex.stderr | 46 ++-- tests/ui/repl_uninit.rs | 5 + tests/ui/repl_uninit.stderr | 6 +- tests/ui/rest_pat_in_fully_bound_structs.rs | 5 +- .../ui/rest_pat_in_fully_bound_structs.stderr | 6 +- tests/ui/result_large_err.rs | 12 ++ tests/ui/result_large_err.stderr | 22 +- tests/ui/result_map_unit_fn_unfixable.rs | 7 + tests/ui/result_map_unit_fn_unfixable.stderr | 11 +- tests/ui/result_unit_error.rs | 5 + tests/ui/result_unit_error.stderr | 8 +- tests/ui/return_self_not_must_use.rs | 3 + tests/ui/return_self_not_must_use.stderr | 6 +- .../reversed_empty_ranges_loops_unfixable.rs | 3 + ...versed_empty_ranges_loops_unfixable.stderr | 2 +- tests/ui/reversed_empty_ranges_unfixable.rs | 4 + .../ui/reversed_empty_ranges_unfixable.stderr | 4 +- tests/ui/same_item_push.rs | 5 + tests/ui/same_item_push.stderr | 8 +- tests/ui/same_name_method.rs | 5 + tests/ui/same_name_method.stderr | 18 +- tests/ui/self_assignment.rs | 12 ++ tests/ui/self_assignment.stderr | 20 +- tests/ui/self_named_constructors.rs | 2 + tests/ui/self_named_constructors.stderr | 2 + tests/ui/serde.rs | 2 + tests/ui/serde.stderr | 5 +- tests/ui/should_impl_trait/method_list_1.rs | 15 ++ .../ui/should_impl_trait/method_list_1.stderr | 43 ++-- tests/ui/should_impl_trait/method_list_2.rs | 17 ++ .../ui/should_impl_trait/method_list_2.stderr | 47 +++-- tests/ui/significant_drop_in_scrutinee.rs | 52 +++++ tests/ui/significant_drop_in_scrutinee.stderr | 85 ++++---- tests/ui/similar_names.rs | 7 + tests/ui/similar_names.stderr | 22 +- tests/ui/single_char_lifetime_names.rs | 5 + tests/ui/single_char_lifetime_names.stderr | 6 +- ...gle_component_path_imports_nested_first.rs | 4 + ...component_path_imports_nested_first.stderr | 4 +- .../size_of_in_element_count/expressions.rs | 4 + .../expressions.stderr | 6 +- .../ui/size_of_in_element_count/functions.rs | 21 ++ .../size_of_in_element_count/functions.stderr | 40 ++-- tests/ui/size_of_ref.rs | 3 + tests/ui/size_of_ref.stderr | 4 +- tests/ui/slow_vector_initialization.rs | 15 ++ tests/ui/slow_vector_initialization.stderr | 24 +-- tests/ui/std_instead_of_core.rs | 12 ++ tests/ui/std_instead_of_core.stderr | 22 +- tests/ui/str_to_string.rs | 2 + tests/ui/str_to_string.stderr | 2 +- tests/ui/string_slice.rs | 4 + tests/ui/string_slice.stderr | 4 +- tests/ui/string_to_string.rs | 1 + tests/ui/struct_excessive_bools.rs | 2 + tests/ui/struct_excessive_bools.stderr | 4 +- tests/ui/suspicious_arithmetic_impl.rs | 11 + tests/ui/suspicious_arithmetic_impl.stderr | 16 +- tests/ui/suspicious_command_arg_space.fixed | 3 + tests/ui/suspicious_command_arg_space.rs | 3 + tests/ui/suspicious_command_arg_space.stderr | 2 +- tests/ui/suspicious_doc_comments_unfixable.rs | 3 + .../suspicious_doc_comments_unfixable.stderr | 8 +- tests/ui/suspicious_map.rs | 2 + tests/ui/suspicious_map.stderr | 2 +- tests/ui/suspicious_splitn.rs | 18 ++ tests/ui/suspicious_splitn.stderr | 16 +- tests/ui/suspicious_to_owned.rs | 8 + tests/ui/suspicious_to_owned.stderr | 10 +- tests/ui/suspicious_unary_op_formatting.rs | 4 + .../ui/suspicious_unary_op_formatting.stderr | 6 +- tests/ui/suspicious_xor_used_as_pow.rs | 7 + tests/ui/suspicious_xor_used_as_pow.stderr | 10 +- tests/ui/swap_ptr_to_ref_unfixable.rs | 4 + tests/ui/swap_ptr_to_ref_unfixable.stderr | 4 +- tests/ui/temporary_assignment.rs | 5 + tests/ui/temporary_assignment.stderr | 7 +- tests/ui/tests_outside_test_module.rs | 2 + tests/ui/trailing_empty_array.rs | 11 + tests/ui/trailing_empty_array.stderr | 30 ++- tests/ui/trailing_zeros.fixed | 3 + tests/ui/trailing_zeros.rs | 3 + tests/ui/trailing_zeros.stderr | 2 +- .../trait_duplication_in_bounds_unfixable.rs | 8 + ...ait_duplication_in_bounds_unfixable.stderr | 12 +- tests/ui/transmute.rs | 45 ++++ tests/ui/transmute.stderr | 74 +++---- tests/ui/transmute_64bit.rs | 3 + tests/ui/transmute_64bit.stderr | 2 +- tests/ui/transmute_collection.rs | 19 ++ tests/ui/transmute_collection.stderr | 34 +-- tests/ui/transmute_float_to_int.fixed | 7 + tests/ui/transmute_float_to_int.rs | 7 + tests/ui/transmute_float_to_int.stderr | 10 +- tests/ui/transmute_int_to_non_zero.fixed | 11 + tests/ui/transmute_int_to_non_zero.rs | 11 + tests/ui/transmute_int_to_non_zero.stderr | 18 +- tests/ui/transmute_null_to_fn.rs | 3 + tests/ui/transmute_null_to_fn.stderr | 4 +- tests/ui/transmute_ptr_to_ptr.fixed | 7 + tests/ui/transmute_ptr_to_ptr.rs | 7 + tests/ui/transmute_ptr_to_ptr.stderr | 10 +- tests/ui/transmute_undefined_repr.rs | 23 ++ tests/ui/transmute_undefined_repr.stderr | 22 +- tests/ui/transmuting_null.rs | 4 + tests/ui/transmuting_null.stderr | 4 +- tests/ui/type_complexity.rs | 16 ++ tests/ui/type_complexity.stderr | 28 +-- tests/ui/type_repetition_in_bounds.rs | 5 + tests/ui/type_repetition_in_bounds.stderr | 8 +- tests/ui/uninit.rs | 4 + tests/ui/uninit.stderr | 4 +- tests/ui/uninit_vec.rs | 11 + tests/ui/uninit_vec.stderr | 38 ++-- tests/ui/unit_cmp.rs | 7 + tests/ui/unit_cmp.stderr | 21 +- tests/ui/unit_hash.fixed | 6 + tests/ui/unit_hash.rs | 6 + tests/ui/unit_hash.stderr | 4 +- tests/ui/unit_return_expecting_ord.rs | 4 + tests/ui/unit_return_expecting_ord.stderr | 10 +- tests/ui/unknown_attribute.rs | 1 + tests/ui/unnecessary_box_returns.rs | 4 + tests/ui/unnecessary_box_returns.stderr | 6 +- tests/ui/unnecessary_cast_unfixable.rs | 3 + tests/ui/unnecessary_cast_unfixable.stderr | 2 +- tests/ui/unnecessary_clone.rs | 11 + tests/ui/unnecessary_clone.stderr | 16 +- tests/ui/unnecessary_filter_map.rs | 5 + tests/ui/unnecessary_filter_map.stderr | 10 +- tests/ui/unnecessary_find_map.rs | 5 + tests/ui/unnecessary_find_map.stderr | 10 +- tests/ui/unnecessary_lazy_eval_unfixable.rs | 4 + .../ui/unnecessary_lazy_eval_unfixable.stderr | 4 +- .../unnecessary_literal_unwrap_unfixable.rs | 52 +++++ ...nnecessary_literal_unwrap_unfixable.stderr | 198 +++++++++--------- tests/ui/unnecessary_safety_comment.rs | 8 + tests/ui/unnecessary_safety_comment.stderr | 32 +-- tests/ui/unnecessary_wraps.rs | 8 + tests/ui/unnecessary_wraps.stderr | 24 ++- tests/ui/unsafe_derive_deserialize.rs | 4 + tests/ui/unsafe_derive_deserialize.stderr | 6 +- tests/ui/unsafe_removed_from_name.rs | 6 + tests/ui/unsafe_removed_from_name.stderr | 8 +- tests/ui/unused_async.rs | 4 + tests/ui/unused_async.stderr | 11 +- tests/ui/unused_format_specs_unfixable.rs | 5 + tests/ui/unused_format_specs_unfixable.stderr | 6 +- tests/ui/unused_io_amount.rs | 20 ++ tests/ui/unused_io_amount.stderr | 39 ++-- tests/ui/unused_peekable.rs | 8 + tests/ui/unused_peekable.stderr | 14 +- tests/ui/unused_self.rs | 9 + tests/ui/unused_self.stderr | 16 +- tests/ui/unwrap.rs | 3 + tests/ui/unwrap.stderr | 4 +- tests/ui/unwrap_expect_used.rs | 6 + tests/ui/unwrap_expect_used.stderr | 10 +- tests/ui/unwrap_in_result.rs | 2 + tests/ui/unwrap_in_result.stderr | 12 +- tests/ui/unwrap_or.fixed | 3 + tests/ui/unwrap_or.rs | 3 + tests/ui/unwrap_or.stderr | 2 +- tests/ui/upper_case_acronyms.fixed | 12 ++ tests/ui/upper_case_acronyms.rs | 12 ++ tests/ui/upper_case_acronyms.stderr | 20 +- tests/ui/useless_conversion_try.rs | 9 + tests/ui/useless_conversion_try.stderr | 16 +- tests/ui/vec_init_then_push.rs | 9 + tests/ui/vec_init_then_push.stderr | 25 ++- tests/ui/vec_resize_to_zero.fixed | 1 + tests/ui/vec_resize_to_zero.rs | 1 + tests/ui/verbose_file_reads.rs | 2 + tests/ui/verbose_file_reads.stderr | 2 +- tests/ui/vtable_address_comparisons.rs | 8 + tests/ui/vtable_address_comparisons.stderr | 14 +- tests/ui/while_let_loop.rs | 6 + tests/ui/while_let_loop.stderr | 21 +- tests/ui/wild_in_or_pats.rs | 4 + tests/ui/wild_in_or_pats.stderr | 6 +- tests/ui/write_literal.fixed | 13 ++ tests/ui/write_literal.rs | 13 ++ tests/ui/write_literal.stderr | 22 +- tests/ui/write_literal_2.rs | 22 +- tests/ui/write_literal_2.stderr | 53 ++--- tests/ui/write_with_newline.fixed | 10 + tests/ui/write_with_newline.rs | 10 + tests/ui/write_with_newline.stderr | 20 +- tests/ui/wrong_self_convention.rs | 24 +++ tests/ui/wrong_self_convention.stderr | 46 ++-- tests/ui/wrong_self_convention2.rs | 2 + tests/ui/wrong_self_convention2.stderr | 2 +- tests/ui/wrong_self_conventions_mut.rs | 2 + tests/ui/wrong_self_conventions_mut.stderr | 2 +- tests/ui/zero_div_zero.rs | 4 + tests/ui/zero_div_zero.stderr | 6 +- tests/ui/zero_offset.rs | 9 + tests/ui/zero_offset.stderr | 14 +- tests/ui/zero_sized_btreemap_values.rs | 14 +- tests/ui/zero_sized_btreemap_values.stderr | 24 +-- tests/ui/zero_sized_hashmap_values.rs | 14 +- tests/ui/zero_sized_hashmap_values.stderr | 24 +-- 729 files changed, 6743 insertions(+), 2780 deletions(-) diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index f682b280c1b80..60f2ba4abcff3 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -12,27 +12,46 @@ fn main() { const Z: u32 = 0; let u: u32 = 42; u <= 0; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u <= Z; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u < Z; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con Z >= u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con Z > u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u > u32::MAX; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u >= u32::MAX; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u32::MAX < u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u32::MAX <= u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con 1-1 > u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u >= !0; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u <= 12 - 2*6; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con let i: i8 = 0; i < -127 - 1; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con i8::MAX >= i; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con 3-7 < i32::MIN; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con let b = false; b >= true; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con false > b; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u > 0; // ok // this is handled by clippy::unit_cmp () < {}; + //~^ ERROR: <-comparison of unit values detected. This will always be false + //~| NOTE: `#[deny(clippy::unit_cmp)]` on by default } use std::cmp::{Ordering, PartialEq, PartialOrd}; diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index 21cb11fa1bb84..a7843e2b349e2 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -8,7 +8,7 @@ LL | u <= 0; = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:15:5 + --> $DIR/absurd-extreme-comparisons.rs:16:5 | LL | u <= Z; | ^^^^^^ @@ -16,7 +16,7 @@ LL | u <= Z; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:16:5 + --> $DIR/absurd-extreme-comparisons.rs:18:5 | LL | u < Z; | ^^^^^ @@ -24,7 +24,7 @@ LL | u < Z; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:17:5 + --> $DIR/absurd-extreme-comparisons.rs:20:5 | LL | Z >= u; | ^^^^^^ @@ -32,7 +32,7 @@ LL | Z >= u; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:18:5 + --> $DIR/absurd-extreme-comparisons.rs:22:5 | LL | Z > u; | ^^^^^ @@ -40,7 +40,7 @@ LL | Z > u; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:19:5 + --> $DIR/absurd-extreme-comparisons.rs:24:5 | LL | u > u32::MAX; | ^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | u > u32::MAX; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:20:5 + --> $DIR/absurd-extreme-comparisons.rs:26:5 | LL | u >= u32::MAX; | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | u >= u32::MAX; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == u32::MAX` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:21:5 + --> $DIR/absurd-extreme-comparisons.rs:28:5 | LL | u32::MAX < u; | ^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::MAX < u; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:22:5 + --> $DIR/absurd-extreme-comparisons.rs:30:5 | LL | u32::MAX <= u; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | u32::MAX <= u; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u32::MAX == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:23:5 + --> $DIR/absurd-extreme-comparisons.rs:32:5 | LL | 1-1 > u; | ^^^^^^^ @@ -80,7 +80,7 @@ LL | 1-1 > u; = help: because `1-1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:24:5 + --> $DIR/absurd-extreme-comparisons.rs:34:5 | LL | u >= !0; | ^^^^^^^ @@ -88,7 +88,7 @@ LL | u >= !0; = help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:25:5 + --> $DIR/absurd-extreme-comparisons.rs:36:5 | LL | u <= 12 - 2*6; | ^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | u <= 12 - 2*6; = help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:27:5 + --> $DIR/absurd-extreme-comparisons.rs:39:5 | LL | i < -127 - 1; | ^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | i < -127 - 1; = help: because `-127 - 1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:28:5 + --> $DIR/absurd-extreme-comparisons.rs:41:5 | LL | i8::MAX >= i; | ^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | i8::MAX >= i; = help: because `i8::MAX` is the maximum value for this type, this comparison is always true error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:29:5 + --> $DIR/absurd-extreme-comparisons.rs:43:5 | LL | 3-7 < i32::MIN; | ^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | 3-7 < i32::MIN; = help: because `i32::MIN` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:31:5 + --> $DIR/absurd-extreme-comparisons.rs:46:5 | LL | b >= true; | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | b >= true; = help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:32:5 + --> $DIR/absurd-extreme-comparisons.rs:48:5 | LL | false > b; | ^^^^^^^^^ @@ -136,7 +136,7 @@ LL | false > b; = help: because `false` is the minimum value for this type, this comparison is always false error: <-comparison of unit values detected. This will always be false - --> $DIR/absurd-extreme-comparisons.rs:35:5 + --> $DIR/absurd-extreme-comparisons.rs:52:5 | LL | () < {}; | ^^^^^^^ diff --git a/tests/ui/approx_const.rs b/tests/ui/approx_const.rs index ccdbd34f7ec7b..2c3e0978c528e 100644 --- a/tests/ui/approx_const.rs +++ b/tests/ui/approx_const.rs @@ -2,63 +2,86 @@ #[allow(clippy::similar_names)] fn main() { let my_e = 2.7182; + //~^ ERROR: approximate value of `f{32, 64}::consts::E` found let almost_e = 2.718; + //~^ ERROR: approximate value of `f{32, 64}::consts::E` found let no_e = 2.71; let my_1_frac_pi = 0.3183; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_PI` found let no_1_frac_pi = 0.31; let my_frac_1_sqrt_2 = 0.70710678; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found let almost_frac_1_sqrt_2 = 0.70711; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found let my_frac_1_sqrt_2 = 0.707; let my_frac_2_pi = 0.63661977; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_PI` found let no_frac_2_pi = 0.636; let my_frac_2_sq_pi = 1.128379; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found let no_frac_2_sq_pi = 1.128; let my_frac_pi_2 = 1.57079632679; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_2` found let no_frac_pi_2 = 1.5705; let my_frac_pi_3 = 1.04719755119; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_3` found let no_frac_pi_3 = 1.047; let my_frac_pi_4 = 0.785398163397; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_4` found let no_frac_pi_4 = 0.785; let my_frac_pi_6 = 0.523598775598; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_6` found let no_frac_pi_6 = 0.523; let my_frac_pi_8 = 0.3926990816987; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_8` found let no_frac_pi_8 = 0.392; let my_ln_10 = 2.302585092994046; + //~^ ERROR: approximate value of `f{32, 64}::consts::LN_10` found let no_ln_10 = 2.303; let my_ln_2 = 0.6931471805599453; + //~^ ERROR: approximate value of `f{32, 64}::consts::LN_2` found let no_ln_2 = 0.693; let my_log10_e = 0.4342944819032518; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_E` found let no_log10_e = 0.434; let my_log2_e = 1.4426950408889634; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_E` found let no_log2_e = 1.442; let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found let no_log2_10 = 3.321; let log10_2 = 0.301029995663981; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_2` found let no_log10_2 = 0.301; let my_pi = 3.1415; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found let almost_pi = 3.14; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found let no_pi = 3.15; let my_sq2 = 1.4142; + //~^ ERROR: approximate value of `f{32, 64}::consts::SQRT_2` found let no_sq2 = 1.414; let my_tau = 6.2832; + //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found let almost_tau = 6.28; + //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found let no_tau = 6.3; } diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr index 0932a2eec520f..28d2d317155bb 100644 --- a/tests/ui/approx_const.stderr +++ b/tests/ui/approx_const.stderr @@ -8,7 +8,7 @@ LL | let my_e = 2.7182; = note: `-D clippy::approx-constant` implied by `-D warnings` error: approximate value of `f{32, 64}::consts::E` found - --> $DIR/approx_const.rs:5:20 + --> $DIR/approx_const.rs:6:20 | LL | let almost_e = 2.718; | ^^^^^ @@ -16,7 +16,7 @@ LL | let almost_e = 2.718; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found - --> $DIR/approx_const.rs:8:24 + --> $DIR/approx_const.rs:10:24 | LL | let my_1_frac_pi = 0.3183; | ^^^^^^ @@ -24,7 +24,7 @@ LL | let my_1_frac_pi = 0.3183; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found - --> $DIR/approx_const.rs:11:28 + --> $DIR/approx_const.rs:14:28 | LL | let my_frac_1_sqrt_2 = 0.70710678; | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let my_frac_1_sqrt_2 = 0.70710678; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found - --> $DIR/approx_const.rs:12:32 + --> $DIR/approx_const.rs:16:32 | LL | let almost_frac_1_sqrt_2 = 0.70711; | ^^^^^^^ @@ -40,7 +40,7 @@ LL | let almost_frac_1_sqrt_2 = 0.70711; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found - --> $DIR/approx_const.rs:15:24 + --> $DIR/approx_const.rs:20:24 | LL | let my_frac_2_pi = 0.63661977; | ^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let my_frac_2_pi = 0.63661977; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found - --> $DIR/approx_const.rs:18:27 + --> $DIR/approx_const.rs:24:27 | LL | let my_frac_2_sq_pi = 1.128379; | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | let my_frac_2_sq_pi = 1.128379; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found - --> $DIR/approx_const.rs:21:24 + --> $DIR/approx_const.rs:28:24 | LL | let my_frac_pi_2 = 1.57079632679; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let my_frac_pi_2 = 1.57079632679; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found - --> $DIR/approx_const.rs:24:24 + --> $DIR/approx_const.rs:32:24 | LL | let my_frac_pi_3 = 1.04719755119; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let my_frac_pi_3 = 1.04719755119; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found - --> $DIR/approx_const.rs:27:24 + --> $DIR/approx_const.rs:36:24 | LL | let my_frac_pi_4 = 0.785398163397; | ^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | let my_frac_pi_4 = 0.785398163397; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found - --> $DIR/approx_const.rs:30:24 + --> $DIR/approx_const.rs:40:24 | LL | let my_frac_pi_6 = 0.523598775598; | ^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | let my_frac_pi_6 = 0.523598775598; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found - --> $DIR/approx_const.rs:33:24 + --> $DIR/approx_const.rs:44:24 | LL | let my_frac_pi_8 = 0.3926990816987; | ^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let my_frac_pi_8 = 0.3926990816987; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LN_10` found - --> $DIR/approx_const.rs:36:20 + --> $DIR/approx_const.rs:48:20 | LL | let my_ln_10 = 2.302585092994046; | ^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | let my_ln_10 = 2.302585092994046; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LN_2` found - --> $DIR/approx_const.rs:39:19 + --> $DIR/approx_const.rs:52:19 | LL | let my_ln_2 = 0.6931471805599453; | ^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let my_ln_2 = 0.6931471805599453; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_E` found - --> $DIR/approx_const.rs:42:22 + --> $DIR/approx_const.rs:56:22 | LL | let my_log10_e = 0.4342944819032518; | ^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | let my_log10_e = 0.4342944819032518; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_E` found - --> $DIR/approx_const.rs:45:21 + --> $DIR/approx_const.rs:60:21 | LL | let my_log2_e = 1.4426950408889634; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | let my_log2_e = 1.4426950408889634; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/approx_const.rs:48:19 + --> $DIR/approx_const.rs:64:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_2` found - --> $DIR/approx_const.rs:51:19 + --> $DIR/approx_const.rs:68:19 | LL | let log10_2 = 0.301029995663981; | ^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let log10_2 = 0.301029995663981; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> $DIR/approx_const.rs:54:17 + --> $DIR/approx_const.rs:72:17 | LL | let my_pi = 3.1415; | ^^^^^^ @@ -152,7 +152,7 @@ LL | let my_pi = 3.1415; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> $DIR/approx_const.rs:55:21 + --> $DIR/approx_const.rs:74:21 | LL | let almost_pi = 3.14; | ^^^^ @@ -160,7 +160,7 @@ LL | let almost_pi = 3.14; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::SQRT_2` found - --> $DIR/approx_const.rs:58:18 + --> $DIR/approx_const.rs:78:18 | LL | let my_sq2 = 1.4142; | ^^^^^^ @@ -168,7 +168,7 @@ LL | let my_sq2 = 1.4142; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> $DIR/approx_const.rs:61:18 + --> $DIR/approx_const.rs:82:18 | LL | let my_tau = 6.2832; | ^^^^^^ @@ -176,7 +176,7 @@ LL | let my_tau = 6.2832; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> $DIR/approx_const.rs:62:22 + --> $DIR/approx_const.rs:84:22 | LL | let almost_tau = 6.28; | ^^^^ diff --git a/tests/ui/as_ptr_cast_mut.rs b/tests/ui/as_ptr_cast_mut.rs index 74dad7a493577..297a53b1bbfb4 100644 --- a/tests/ui/as_ptr_cast_mut.rs +++ b/tests/ui/as_ptr_cast_mut.rs @@ -20,7 +20,10 @@ impl Covariant { fn main() { let mut string = String::new(); let _ = string.as_ptr() as *mut u8; + //~^ ERROR: casting the result of `as_ptr` to *mut u8 + //~| NOTE: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` let _: *mut i8 = string.as_ptr() as *mut _; + //~^ ERROR: casting the result of `as_ptr` to *mut i8 let _ = string.as_ptr() as *const i8; let _ = string.as_mut_ptr(); let _ = string.as_mut_ptr() as *mut u8; diff --git a/tests/ui/as_ptr_cast_mut.stderr b/tests/ui/as_ptr_cast_mut.stderr index 9255f4e048b26..1cd57dd6d1653 100644 --- a/tests/ui/as_ptr_cast_mut.stderr +++ b/tests/ui/as_ptr_cast_mut.stderr @@ -7,7 +7,7 @@ LL | let _ = string.as_ptr() as *mut u8; = note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` error: casting the result of `as_ptr` to *mut i8 - --> $DIR/as_ptr_cast_mut.rs:23:22 + --> $DIR/as_ptr_cast_mut.rs:25:22 | LL | let _: *mut i8 = string.as_ptr() as *mut _; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` diff --git a/tests/ui/asm_syntax.rs b/tests/ui/asm_syntax.rs index af02e202b17bb..0a7eb86bc03f3 100644 --- a/tests/ui/asm_syntax.rs +++ b/tests/ui/asm_syntax.rs @@ -6,8 +6,11 @@ mod warn_intel { pub(super) unsafe fn use_asm() { use std::arch::asm; asm!(""); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options()); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options(nostack)); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options(att_syntax)); asm!("", options(nostack, att_syntax)); } @@ -21,7 +24,9 @@ mod warn_att { asm!("", options()); asm!("", options(nostack)); asm!("", options(att_syntax)); + //~^ ERROR: AT&T x86 assembly syntax used asm!("", options(nostack, att_syntax)); + //~^ ERROR: AT&T x86 assembly syntax used } } diff --git a/tests/ui/asm_syntax.stderr b/tests/ui/asm_syntax.stderr index 9c7c3ba7d87e6..8ee3c97ae2c6c 100644 --- a/tests/ui/asm_syntax.stderr +++ b/tests/ui/asm_syntax.stderr @@ -8,7 +8,7 @@ LL | asm!(""); = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:9:9 + --> $DIR/asm_syntax.rs:10:9 | LL | asm!("", options()); | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | asm!("", options()); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:10:9 + --> $DIR/asm_syntax.rs:12:9 | LL | asm!("", options(nostack)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | asm!("", options(nostack)); = help: use AT&T x86 assembly syntax error: AT&T x86 assembly syntax used - --> $DIR/asm_syntax.rs:23:9 + --> $DIR/asm_syntax.rs:26:9 | LL | asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | asm!("", options(att_syntax)); = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` error: AT&T x86 assembly syntax used - --> $DIR/asm_syntax.rs:24:9 + --> $DIR/asm_syntax.rs:28:9 | LL | asm!("", options(nostack, att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index 7bea9563d47d3..10809a6d247a2 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -8,21 +8,30 @@ macro_rules! assert_const { } fn main() { assert!(true); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler assert!(false); + //~^ ERROR: `assert!(false)` should probably be replaced assert!(true, "true message"); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler assert!(false, "false message"); + //~^ ERROR: `assert!(false, ..)` should probably be replaced let msg = "panic message"; assert!(false, "{}", msg.to_uppercase()); + //~^ ERROR: `assert!(false, ..)` should probably be replaced const B: bool = true; assert!(B); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler const C: bool = false; assert!(C); + //~^ ERROR: `assert!(false)` should probably be replaced assert!(C, "C message"); + //~^ ERROR: `assert!(false, ..)` should probably be replaced debug_assert!(true); + //~^ ERROR: `debug_assert!(true)` will be optimized out by the compiler // Don't lint this, since there is no better way for expressing "Only panic in debug mode". debug_assert!(false); // #3948 assert_const!(3); diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index 29fe009035f16..fc1c7671ffc72 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -8,7 +8,7 @@ LL | assert!(true); = note: `-D clippy::assertions-on-constants` implied by `-D warnings` error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:11:5 + --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(false); | ^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | assert!(false); = help: use `panic!()` or `unreachable!()` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:12:5 + --> $DIR/assertions_on_constants.rs:14:5 | LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | assert!(true, "true message"); = help: remove it error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:13:5 + --> $DIR/assertions_on_constants.rs:16:5 | LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | assert!(false, "false message"); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:16:5 + --> $DIR/assertions_on_constants.rs:20:5 | LL | assert!(false, "{}", msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | assert!(false, "{}", msg.to_uppercase()); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:19:5 + --> $DIR/assertions_on_constants.rs:24:5 | LL | assert!(B); | ^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | assert!(B); = help: remove it error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:22:5 + --> $DIR/assertions_on_constants.rs:28:5 | LL | assert!(C); | ^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | assert!(C); = help: use `panic!()` or `unreachable!()` error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:23:5 + --> $DIR/assertions_on_constants.rs:30:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | assert!(C, "C message"); = help: use `panic!(..)` or `unreachable!(..)` error: `debug_assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:25:5 + --> $DIR/assertions_on_constants.rs:33:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index 2be333df09902..a53556425849b 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -6,14 +6,24 @@ fn main() { let mut a = 5; a += a + 1; + //~^ ERROR: variable appears on both sides of an assignment operation + //~| NOTE: `-D clippy::misrefactored-assign-op` implied by `-D warnings` a += 1 + a; + //~^ ERROR: variable appears on both sides of an assignment operation a -= a - 1; + //~^ ERROR: variable appears on both sides of an assignment operation a *= a * 99; + //~^ ERROR: variable appears on both sides of an assignment operation a *= 42 * a; + //~^ ERROR: variable appears on both sides of an assignment operation a /= a / 2; + //~^ ERROR: variable appears on both sides of an assignment operation a %= a % 5; + //~^ ERROR: variable appears on both sides of an assignment operation a &= a & 1; + //~^ ERROR: variable appears on both sides of an assignment operation a *= a * a; + //~^ ERROR: variable appears on both sides of an assignment operation a = a * a * a; a = a * 42 * a; a = a * 2 + a; @@ -51,6 +61,8 @@ fn cow_add_assign() { // this can be linted buf = buf + cows.clone(); + //~^ ERROR: manual implementation of an assign operation + //~| NOTE: `-D clippy::assign-op-pattern` implied by `-D warnings` // this should not as cow Add is not commutative buf = cows + buf; diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index e5ff3ff3a477a..b392d1c690bb6 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -15,7 +15,7 @@ LL | a = a + a + 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:9:5 + --> $DIR/assign_ops2.rs:11:5 | LL | a += 1 + a; | ^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | a = a + 1 + a; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:10:5 + --> $DIR/assign_ops2.rs:13:5 | LL | a -= a - 1; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | a = a - (a - 1); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:11:5 + --> $DIR/assign_ops2.rs:15:5 | LL | a *= a * 99; | ^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | a = a * a * 99; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:12:5 + --> $DIR/assign_ops2.rs:17:5 | LL | a *= 42 * a; | ^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | a = a * 42 * a; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:13:5 + --> $DIR/assign_ops2.rs:19:5 | LL | a /= a / 2; | ^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | a = a / (a / 2); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:14:5 + --> $DIR/assign_ops2.rs:21:5 | LL | a %= a % 5; | ^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | a = a % (a % 5); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:15:5 + --> $DIR/assign_ops2.rs:23:5 | LL | a &= a & 1; | ^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | a = a & a & 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:16:5 + --> $DIR/assign_ops2.rs:25:5 | LL | a *= a * a; | ^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | a = a * a * a; | ~~~~~~~~~~~~~ error: manual implementation of an assign operation - --> $DIR/assign_ops2.rs:53:5 + --> $DIR/assign_ops2.rs:63:5 | LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 8df6e19421ec5..05ee48d17b1ef 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -3,6 +3,8 @@ #![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)] #[inline(always)] +//~^ ERROR: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a b +//~| NOTE: `-D clippy::inline-always` implied by `-D warnings` fn test_attr_lint() { assert!(true) } @@ -23,9 +25,12 @@ fn empty_and_false_positive_stmt() { } #[deprecated(since = "forever")] +//~^ ERROR: the since field must contain a semver-compliant version +//~| NOTE: `-D clippy::deprecated-semver` implied by `-D warnings` pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] +//~^ ERROR: the since field must contain a semver-compliant version pub const ANOTHER_CONST: u8 = 23; #[deprecated(since = "0.1.1")] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index df4e9e20b649c..0139717f54861 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -7,7 +7,7 @@ LL | #[inline(always)] = note: `-D clippy::inline-always` implied by `-D warnings` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:25:14 + --> $DIR/attrs.rs:27:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | #[deprecated(since = "forever")] = note: `-D clippy::deprecated-semver` implied by `-D warnings` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:28:14 + --> $DIR/attrs.rs:32:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ diff --git a/tests/ui/await_holding_lock.rs b/tests/ui/await_holding_lock.rs index 57e5b55045b95..27b57b6481368 100644 --- a/tests/ui/await_holding_lock.rs +++ b/tests/ui/await_holding_lock.rs @@ -7,6 +7,7 @@ mod std_mutex { pub async fn bad(x: &Mutex) -> u32 { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -22,11 +23,13 @@ mod std_mutex { pub async fn bad_rw(x: &RwLock) -> u32 { let guard = x.read().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } pub async fn bad_rw_write(x: &RwLock) -> u32 { let mut guard = x.write().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -48,6 +51,7 @@ mod std_mutex { let first = baz().await; let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point let second = baz().await; @@ -61,6 +65,7 @@ mod std_mutex { let second = { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await }; @@ -73,6 +78,7 @@ mod std_mutex { pub fn block_bad(x: &Mutex) -> impl std::future::Future + '_ { async move { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } } @@ -85,6 +91,7 @@ mod parking_lot_mutex { pub async fn bad(x: &Mutex) -> u32 { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -100,11 +107,13 @@ mod parking_lot_mutex { pub async fn bad_rw(x: &RwLock) -> u32 { let guard = x.read(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } pub async fn bad_rw_write(x: &RwLock) -> u32 { let mut guard = x.write(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -126,6 +135,7 @@ mod parking_lot_mutex { let first = baz().await; let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point let second = baz().await; @@ -139,6 +149,7 @@ mod parking_lot_mutex { let second = { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await }; @@ -151,6 +162,7 @@ mod parking_lot_mutex { pub fn block_bad(x: &Mutex) -> impl std::future::Future + '_ { async move { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } } @@ -171,6 +183,7 @@ async fn no_await(x: std::sync::Mutex) { // `*guard += 1` is removed it is picked up. async fn dropped_before_await(x: std::sync::Mutex) { let mut guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point *guard += 1; drop(guard); baz().await; diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr index 81a2d05243839..d360c757158b0 100644 --- a/tests/ui/await_holding_lock.stderr +++ b/tests/ui/await_holding_lock.stderr @@ -9,195 +9,206 @@ note: these are all the `await` points this lock is held through --> $DIR/await_holding_lock.rs:9:9 | LL | / let guard = x.lock().unwrap(); +LL | | LL | | baz().await LL | | } | |_____^ = note: `-D clippy::await-holding-lock` implied by `-D warnings` error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:24:13 + --> $DIR/await_holding_lock.rs:25:13 | LL | let guard = x.read().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:24:9 + --> $DIR/await_holding_lock.rs:25:9 | LL | / let guard = x.read().unwrap(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:29:13 + --> $DIR/await_holding_lock.rs:31:13 | LL | let mut guard = x.write().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:29:9 + --> $DIR/await_holding_lock.rs:31:9 | LL | / let mut guard = x.write().unwrap(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:50:13 + --> $DIR/await_holding_lock.rs:53:13 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:50:9 + --> $DIR/await_holding_lock.rs:53:9 | LL | / let guard = x.lock().unwrap(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:63:17 + --> $DIR/await_holding_lock.rs:67:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:63:13 + --> $DIR/await_holding_lock.rs:67:13 | LL | / let guard = x.lock().unwrap(); +LL | | LL | | baz().await LL | | }; | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:75:17 + --> $DIR/await_holding_lock.rs:80:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:75:13 + --> $DIR/await_holding_lock.rs:80:13 | LL | / let guard = x.lock().unwrap(); +LL | | LL | | baz().await LL | | } | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:87:13 + --> $DIR/await_holding_lock.rs:93:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:87:9 + --> $DIR/await_holding_lock.rs:93:9 | LL | / let guard = x.lock(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:102:13 + --> $DIR/await_holding_lock.rs:109:13 | LL | let guard = x.read(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:102:9 + --> $DIR/await_holding_lock.rs:109:9 | LL | / let guard = x.read(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:107:13 + --> $DIR/await_holding_lock.rs:115:13 | LL | let mut guard = x.write(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:107:9 + --> $DIR/await_holding_lock.rs:115:9 | LL | / let mut guard = x.write(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:128:13 + --> $DIR/await_holding_lock.rs:137:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:128:9 + --> $DIR/await_holding_lock.rs:137:9 | LL | / let guard = x.lock(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:141:17 + --> $DIR/await_holding_lock.rs:151:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:141:13 + --> $DIR/await_holding_lock.rs:151:13 | LL | / let guard = x.lock(); +LL | | LL | | baz().await LL | | }; | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:153:17 + --> $DIR/await_holding_lock.rs:164:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:153:13 + --> $DIR/await_holding_lock.rs:164:13 | LL | / let guard = x.lock(); +LL | | LL | | baz().await LL | | } | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:173:9 + --> $DIR/await_holding_lock.rs:185:9 | LL | let mut guard = x.lock().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:173:5 + --> $DIR/await_holding_lock.rs:185:5 | LL | / let mut guard = x.lock().unwrap(); +LL | | LL | | *guard += 1; LL | | drop(guard); LL | | baz().await; diff --git a/tests/ui/await_holding_refcell_ref.rs b/tests/ui/await_holding_refcell_ref.rs index 23b7095de3a39..5bd26c6283627 100644 --- a/tests/ui/await_holding_refcell_ref.rs +++ b/tests/ui/await_holding_refcell_ref.rs @@ -4,11 +4,13 @@ use std::cell::RefCell; async fn bad(x: &RefCell) -> u32 { let b = x.borrow(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } async fn bad_mut(x: &RefCell) -> u32 { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } @@ -30,6 +32,7 @@ async fn also_bad(x: &RefCell) -> u32 { let first = baz().await; let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point let second = baz().await; @@ -42,6 +45,7 @@ async fn less_bad(x: &RefCell) -> u32 { let first = baz().await; let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point let second = baz().await; @@ -57,6 +61,7 @@ async fn not_good(x: &RefCell) -> u32 { let second = { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await }; @@ -69,6 +74,7 @@ async fn not_good(x: &RefCell) -> u32 { fn block_bad(x: &RefCell) -> impl std::future::Future + '_ { async move { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } } diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index 25c15ab80602e..266f8f39028a5 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -9,90 +9,94 @@ note: these are all the `await` points this reference is held through --> $DIR/await_holding_refcell_ref.rs:6:5 | LL | / let b = x.borrow(); +LL | | LL | | baz().await LL | | } | |_^ = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:11:9 + --> $DIR/await_holding_refcell_ref.rs:12:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:11:5 + --> $DIR/await_holding_refcell_ref.rs:12:5 | LL | / let b = x.borrow_mut(); +LL | | LL | | baz().await LL | | } | |_^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:32:9 + --> $DIR/await_holding_refcell_ref.rs:34:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:32:5 + --> $DIR/await_holding_refcell_ref.rs:34:5 | LL | / let b = x.borrow_mut(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:44:9 + --> $DIR/await_holding_refcell_ref.rs:47:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:44:5 + --> $DIR/await_holding_refcell_ref.rs:47:5 | LL | / let b = x.borrow_mut(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:59:13 + --> $DIR/await_holding_refcell_ref.rs:63:13 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:59:9 + --> $DIR/await_holding_refcell_ref.rs:63:9 | LL | / let b = x.borrow_mut(); +LL | | LL | | baz().await LL | | }; | |_____^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:71:13 + --> $DIR/await_holding_refcell_ref.rs:76:13 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:71:9 + --> $DIR/await_holding_refcell_ref.rs:76:9 | LL | / let b = x.borrow_mut(); +LL | | LL | | baz().await LL | | } | |_____^ diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs index cfb493fb52afb..8e1d066c25e49 100644 --- a/tests/ui/bit_masks.rs +++ b/tests/ui/bit_masks.rs @@ -12,19 +12,27 @@ fn main() { let x = 5; x & 0 == 0; + //~^ ERROR: &-masking with zero + //~| NOTE: `-D clippy::bad-bit-mask` implied by `-D warnings` + //~| ERROR: this operation will always return zero. This is likely not the intended ou + //~| NOTE: `#[deny(clippy::erasing_op)]` on by default x & 1 == 1; //ok, distinguishes bit 0 x & 1 == 0; //ok, compared with zero x & 2 == 1; + //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` x | 0 == 0; //ok, equals x == 0 (maybe warn?) x | 1 == 3; //ok, equals x == 2 || x == 3 x | 3 == 3; //ok, equals x <= 3 x | 3 == 2; + //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` x & 1 > 1; + //~^ ERROR: incompatible bit mask: `_ & 1` will never be higher than `1` x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 x | 1 > 1; // ok (if a bit silly), equals x > 1 x | 2 > 1; + //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` x | 2 <= 2; // ok (if a bit silly), equals x <= 2 x & 192 == 128; // ok, tests for bit 7 and not bit 6 @@ -32,15 +40,22 @@ fn main() { // this also now works with constants x & THREE_BITS == 8; + //~^ ERROR: incompatible bit mask: `_ & 7` can never be equal to `8` x | EVEN_MORE_REDIRECTION < 7; + //~^ ERROR: incompatible bit mask: `_ | 7` will never be lower than `7` 0 & x == 0; + //~^ ERROR: &-masking with zero + //~| ERROR: this operation will always return zero. This is likely not the intended ou 1 | x > 1; // and should now also match uncommon usage 1 < 2 | x; + //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` 2 == 3 | x; + //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` 1 == x & 2; + //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` x | 1 > 2; // no error, because we allowed ineffective bit masks ineffective(); @@ -52,9 +67,14 @@ fn ineffective() { let x = 5; x | 1 > 3; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d + //~| NOTE: `-D clippy::ineffective-bit-mask` implied by `-D warnings` x | 1 < 4; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared d x | 1 <= 3; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d x | 1 >= 8; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared d x | 1 > 2; // not an error (yet), better written as x >= 2 x | 1 >= 7; // not an error (yet), better written as x >= 6 diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index dc5ad6dfbdff9..d0cb3a263fca8 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -15,73 +15,73 @@ LL | x & 0 == 0; = note: `#[deny(clippy::erasing_op)]` on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> $DIR/bit_masks.rs:17:5 + --> $DIR/bit_masks.rs:21:5 | LL | x & 2 == 1; | ^^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> $DIR/bit_masks.rs:21:5 + --> $DIR/bit_masks.rs:26:5 | LL | x | 3 == 2; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 1` will never be higher than `1` - --> $DIR/bit_masks.rs:23:5 + --> $DIR/bit_masks.rs:29:5 | LL | x & 1 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> $DIR/bit_masks.rs:27:5 + --> $DIR/bit_masks.rs:34:5 | LL | x | 2 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ & 7` can never be equal to `8` - --> $DIR/bit_masks.rs:34:5 + --> $DIR/bit_masks.rs:42:5 | LL | x & THREE_BITS == 8; | ^^^^^^^^^^^^^^^^^^^ error: incompatible bit mask: `_ | 7` will never be lower than `7` - --> $DIR/bit_masks.rs:35:5 + --> $DIR/bit_masks.rs:44:5 | LL | x | EVEN_MORE_REDIRECTION < 7; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: &-masking with zero - --> $DIR/bit_masks.rs:37:5 + --> $DIR/bit_masks.rs:47:5 | LL | 0 & x == 0; | ^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/bit_masks.rs:37:5 + --> $DIR/bit_masks.rs:47:5 | LL | 0 & x == 0; | ^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> $DIR/bit_masks.rs:41:5 + --> $DIR/bit_masks.rs:53:5 | LL | 1 < 2 | x; | ^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> $DIR/bit_masks.rs:42:5 + --> $DIR/bit_masks.rs:55:5 | LL | 2 == 3 | x; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> $DIR/bit_masks.rs:43:5 + --> $DIR/bit_masks.rs:57:5 | LL | 1 == x & 2; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> $DIR/bit_masks.rs:54:5 + --> $DIR/bit_masks.rs:69:5 | LL | x | 1 > 3; | ^^^^^^^^^ @@ -89,19 +89,19 @@ LL | x | 1 > 3; = note: `-D clippy::ineffective-bit-mask` implied by `-D warnings` error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly - --> $DIR/bit_masks.rs:55:5 + --> $DIR/bit_masks.rs:72:5 | LL | x | 1 < 4; | ^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> $DIR/bit_masks.rs:56:5 + --> $DIR/bit_masks.rs:74:5 | LL | x | 1 <= 3; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly - --> $DIR/bit_masks.rs:57:5 + --> $DIR/bit_masks.rs:76:5 | LL | x | 1 >= 8; | ^^^^^^^^^^ diff --git a/tests/ui/blanket_clippy_restriction_lints.rs b/tests/ui/blanket_clippy_restriction_lints.rs index e1ff25c54cfcb..2bfaadf8df94e 100644 --- a/tests/ui/blanket_clippy_restriction_lints.rs +++ b/tests/ui/blanket_clippy_restriction_lints.rs @@ -4,7 +4,10 @@ //! Test that the whole restriction group is not enabled #![warn(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group #![deny(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group #![forbid(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group fn main() {} diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index 2bf89ab69a40c..0f92fbebae99f 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -13,7 +13,7 @@ LL | #![warn(clippy::restriction)] = help: enable the restriction lints you need individually error: `clippy::restriction` is not meant to be enabled as a group - --> $DIR/blanket_clippy_restriction_lints.rs:7:9 + --> $DIR/blanket_clippy_restriction_lints.rs:8:9 | LL | #![deny(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | #![deny(clippy::restriction)] = help: enable the restriction lints you need individually error: `clippy::restriction` is not meant to be enabled as a group - --> $DIR/blanket_clippy_restriction_lints.rs:8:11 + --> $DIR/blanket_clippy_restriction_lints.rs:10:11 | LL | #![forbid(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/blocks_in_if_conditions_closure.rs b/tests/ui/blocks_in_if_conditions_closure.rs index d6d085d7fd14f..539f2df15bd85 100644 --- a/tests/ui/blocks_in_if_conditions_closure.rs +++ b/tests/ui/blocks_in_if_conditions_closure.rs @@ -21,6 +21,8 @@ fn pred_test() { && sky == "blue" && predicate( |x| { + //~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks + //~| NOTE: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` let target = 3; x == target }, @@ -30,6 +32,7 @@ fn pred_test() { if predicate( |x| { + //~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks; in let target = 3; x == target }, diff --git a/tests/ui/blocks_in_if_conditions_closure.stderr b/tests/ui/blocks_in_if_conditions_closure.stderr index 5ac02e7504e8a..34ebe5b6d1446 100644 --- a/tests/ui/blocks_in_if_conditions_closure.stderr +++ b/tests/ui/blocks_in_if_conditions_closure.stderr @@ -3,6 +3,8 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; inste | LL | |x| { | _________________^ +LL | | +LL | | LL | | let target = 3; LL | | x == target LL | | }, @@ -11,10 +13,11 @@ LL | | }, = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> $DIR/blocks_in_if_conditions_closure.rs:32:13 + --> $DIR/blocks_in_if_conditions_closure.rs:34:13 | LL | |x| { | _____________^ +LL | | LL | | let target = 3; LL | | x == target LL | | }, diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index 1c0fd470ddb04..e9994aac8454a 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -23,14 +23,17 @@ pub fn test1(foo: &mut Box) { pub fn test2() { let foo: &Box; + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } struct Test3<'a> { foo: &'a Box, + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } trait Test4 { fn test4(a: &Box); + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } impl<'a> Test4 for Test3<'a> { @@ -97,17 +100,24 @@ pub fn test13(boxed_slice: &mut Box<[i32]>) { // The suggestion should include proper parentheses to avoid a syntax error. pub fn test14(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test15(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test16<'a>(_display: &'a Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test17(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test18(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test19<'a>(_display: &'a Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` // This exists only to check what happens when parentheses are already present. // Even though the current implementation doesn't put extra parentheses, // it's fine that unnecessary parentheses appear in the future for some reason. pub fn test20(_display: &Box<(dyn Display + Send)>) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` fn main() { test1(&mut Box::new(false)); diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index 6f498d2338d99..a9773958a3778 100644 --- a/tests/ui/borrow_box.stderr +++ b/tests/ui/borrow_box.stderr @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:29:10 + --> $DIR/borrow_box.rs:30:10 | LL | foo: &'a Box, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:33:17 + --> $DIR/borrow_box.rs:35:17 | LL | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:99:25 + --> $DIR/borrow_box.rs:102:25 | LL | pub fn test14(_display: &Box) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:100:25 + --> $DIR/borrow_box.rs:104:25 | LL | pub fn test15(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:101:29 + --> $DIR/borrow_box.rs:106:29 | LL | pub fn test16<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:103:25 + --> $DIR/borrow_box.rs:109:25 | LL | pub fn test17(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:104:25 + --> $DIR/borrow_box.rs:111:25 | LL | pub fn test18(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:105:29 + --> $DIR/borrow_box.rs:113:29 | LL | pub fn test19<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:110:25 + --> $DIR/borrow_box.rs:119:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/tests/ui/borrow_deref_ref_unfixable.rs b/tests/ui/borrow_deref_ref_unfixable.rs index 5e7a8d514b546..be98873395978 100644 --- a/tests/ui/borrow_deref_ref_unfixable.rs +++ b/tests/ui/borrow_deref_ref_unfixable.rs @@ -7,5 +7,7 @@ mod should_lint { fn two_helps() { let s = &String::new(); let x: &str = &*s; + //~^ ERROR: deref on an immutable reference + //~| NOTE: `-D clippy::borrow-deref-ref` implied by `-D warnings` } } diff --git a/tests/ui/box_collection.rs b/tests/ui/box_collection.rs index 4c9947b9ae724..499625ea9c31a 100644 --- a/tests/ui/box_collection.rs +++ b/tests/ui/box_collection.rs @@ -19,6 +19,7 @@ fn test_macro() { } fn test1(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Vec<..>` fn test2(foo: Box)>) { // pass if #31 is fixed @@ -26,20 +27,28 @@ fn test2(foo: Box)>) { } fn test3(foo: Box) {} +//~^ ERROR: you seem to be trying to use `Box`. Consider using just `String` fn test4(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashMap< fn test5(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashSet< fn test6(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `VecDequ fn test7(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Linke fn test8(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeMa fn test9(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeSe fn test10(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Binar fn test_local_not_linted() { let _: Box>; diff --git a/tests/ui/box_collection.stderr b/tests/ui/box_collection.stderr index 40b6f9be61d59..7734271267534 100644 --- a/tests/ui/box_collection.stderr +++ b/tests/ui/box_collection.stderr @@ -8,7 +8,7 @@ LL | fn test1(foo: Box>) {} = note: `-D clippy::box-collection` implied by `-D warnings` error: you seem to be trying to use `Box`. Consider using just `String` - --> $DIR/box_collection.rs:28:15 + --> $DIR/box_collection.rs:29:15 | LL | fn test3(foo: Box) {} | ^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn test3(foo: Box) {} = help: `String` is already on the heap, `Box` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `HashMap<..>` - --> $DIR/box_collection.rs:30:15 + --> $DIR/box_collection.rs:32:15 | LL | fn test4(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn test4(foo: Box>) {} = help: `HashMap<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `HashSet<..>` - --> $DIR/box_collection.rs:32:15 + --> $DIR/box_collection.rs:35:15 | LL | fn test5(foo: Box>) {} | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn test5(foo: Box>) {} = help: `HashSet<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `VecDeque<..>` - --> $DIR/box_collection.rs:34:15 + --> $DIR/box_collection.rs:38:15 | LL | fn test6(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | fn test6(foo: Box>) {} = help: `VecDeque<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `LinkedList<..>` - --> $DIR/box_collection.rs:36:15 + --> $DIR/box_collection.rs:41:15 | LL | fn test7(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | fn test7(foo: Box>) {} = help: `LinkedList<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BTreeMap<..>` - --> $DIR/box_collection.rs:38:15 + --> $DIR/box_collection.rs:44:15 | LL | fn test8(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn test8(foo: Box>) {} = help: `BTreeMap<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BTreeSet<..>` - --> $DIR/box_collection.rs:40:15 + --> $DIR/box_collection.rs:47:15 | LL | fn test9(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn test9(foo: Box>) {} = help: `BTreeSet<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BinaryHeap<..>` - --> $DIR/box_collection.rs:42:16 + --> $DIR/box_collection.rs:50:16 | LL | fn test10(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/boxed_local.rs b/tests/ui/boxed_local.rs index 79b6d33fc77ca..e888154c46def 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -38,6 +38,8 @@ fn warn_call() { } fn warn_arg(x: Box) { + //~^ ERROR: local variable doesn't need to be boxed here + //~| NOTE: `-D clippy::boxed-local` implied by `-D warnings` x.foo(); } @@ -119,6 +121,7 @@ pub struct PeekableSeekable { } pub fn new(_needs_name: Box>) -> () {} +//~^ ERROR: local variable doesn't need to be boxed here /// Regression for #916, #1123 /// @@ -183,6 +186,7 @@ mod issue4804 { // warn on `x: Box` fn default_impl_x(self: Box, x: Box) -> u32 { + //~^ ERROR: local variable doesn't need to be boxed here 4 } } @@ -190,6 +194,7 @@ mod issue4804 { trait WarnTrait { // warn on `x: Box` fn foo(x: Box) {} + //~^ ERROR: local variable doesn't need to be boxed here } } diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 10d78fbc0abb5..11868605d9693 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box) { = note: `-D clippy::boxed-local` implied by `-D warnings` error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:121:12 + --> $DIR/boxed_local.rs:123:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:185:44 + --> $DIR/boxed_local.rs:188:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:192:16 + --> $DIR/boxed_local.rs:196:16 | LL | fn foo(x: Box) {} | ^ diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.rs b/tests/ui/branches_sharing_code/shared_at_bottom.rs index e2ce3f6ff28a5..d102efa7a5880 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_bottom.rs @@ -29,6 +29,8 @@ fn simple_examples() { // The rest is self contained and moveable => Only lint the rest let result = false; + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio println!("Block end!"); result }; @@ -47,6 +49,7 @@ fn simple_examples() { } else { println!("This is also eq with the else block"); println!("Same end of block"); + //~^ ERROR: all if blocks contain the same code at the end } // Use of outer scope value @@ -64,6 +67,7 @@ fn simple_examples() { println!("I'm a local because I use the value `z`: `{}`", z); println!( + //~^ ERROR: all if blocks contain the same code at the end "I'm moveable because I know: `outer_scope_value`: '{}'", outer_scope_value ); @@ -76,6 +80,7 @@ fn simple_examples() { println!("Hello World"); } else { println!("Hello World"); + //~^ ERROR: all if blocks contain the same code at the end } } } @@ -92,6 +97,7 @@ fn simple_but_suggestion_is_invalid() { println!("{}", later_used_value); } else { let later_used_value = "A string value"; + //~^ ERROR: all if blocks contain the same code at the end println!("{}", later_used_value); // I'm expecting a note about this } @@ -105,6 +111,7 @@ fn simple_but_suggestion_is_invalid() { println!("Separator print statement"); let simple_examples = "I now identify as a &str :)"; + //~^ ERROR: all if blocks contain the same code at the end println!("This is the new simple_example: {}", simple_examples); } simple_examples(); @@ -170,6 +177,8 @@ fn added_note_for_expression_use() -> u32 { } else { let _ = 6; x << 2 + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio }; if x == 9 { @@ -177,6 +186,8 @@ fn added_note_for_expression_use() -> u32 { } else { let _ = 17; x * 4 + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio } } @@ -189,6 +200,7 @@ fn test_suggestion_with_weird_formatting() { // The error message still looks weird tbh but this is the best I can do // for weird formatting if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } + //~^ ERROR: all if blocks contain the same code at the end } fn fp_test() { diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_bottom.stderr index b9b113dc0c6a0..d00717befc103 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -2,6 +2,8 @@ error: all if blocks contain the same code at the end --> $DIR/shared_at_bottom.rs:31:5 | LL | / let result = false; +LL | | +LL | | LL | | println!("Block end!"); LL | | result LL | | }; @@ -17,14 +19,17 @@ help: consider moving these statements after the if | LL ~ } LL + let result = false; +LL + +LL + LL + println!("Block end!"); LL ~ result; | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:49:5 + --> $DIR/shared_at_bottom.rs:51:5 | LL | / println!("Same end of block"); +LL | | LL | | } | |_____^ | @@ -35,9 +40,10 @@ LL + println!("Same end of block"); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:66:5 + --> $DIR/shared_at_bottom.rs:69:5 | LL | / println!( +LL | | LL | | "I'm moveable because I know: `outer_scope_value`: '{}'", LL | | outer_scope_value LL | | ); @@ -48,15 +54,17 @@ help: consider moving these statements after the if | LL ~ } LL + println!( +LL + LL + "I'm moveable because I know: `outer_scope_value`: '{}'", LL + outer_scope_value LL + ); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:78:9 + --> $DIR/shared_at_bottom.rs:82:9 | LL | / println!("Hello World"); +LL | | LL | | } | |_________^ | @@ -67,9 +75,10 @@ LL + println!("Hello World"); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:94:5 + --> $DIR/shared_at_bottom.rs:99:5 | LL | / let later_used_value = "A string value"; +LL | | LL | | println!("{}", later_used_value); LL | | // I'm expecting a note about this LL | | } @@ -80,13 +89,15 @@ help: consider moving these statements after the if | LL ~ } LL + let later_used_value = "A string value"; +LL + LL + println!("{}", later_used_value); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:107:5 + --> $DIR/shared_at_bottom.rs:113:5 | LL | / let simple_examples = "I now identify as a &str :)"; +LL | | LL | | println!("This is the new simple_example: {}", simple_examples); LL | | } | |_____^ @@ -96,13 +107,16 @@ help: consider moving these statements after the if | LL ~ } LL + let simple_examples = "I now identify as a &str :)"; +LL + LL + println!("This is the new simple_example: {}", simple_examples); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:172:5 + --> $DIR/shared_at_bottom.rs:179:5 | LL | / x << 2 +LL | | +LL | | LL | | }; | |_____^ | @@ -114,9 +128,11 @@ LL ~ x << 2; | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:179:5 + --> $DIR/shared_at_bottom.rs:188:5 | LL | / x * 4 +LL | | +LL | | LL | | } | |_____^ | @@ -128,7 +144,7 @@ LL + x * 4 | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:191:44 + --> $DIR/shared_at_bottom.rs:202:44 | LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } | ^^^^^^^^^^^ diff --git a/tests/ui/branches_sharing_code/shared_at_top.rs b/tests/ui/branches_sharing_code/shared_at_top.rs index ac206ac8741e9..44f8b2eabce3b 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.rs +++ b/tests/ui/branches_sharing_code/shared_at_top.rs @@ -9,6 +9,7 @@ fn simple_examples() { // Simple if true { + //~^ ERROR: all if blocks contain the same code at the start println!("Hello World!"); println!("I'm branch nr: 1"); } else { @@ -18,6 +19,7 @@ fn simple_examples() { // Else if if x == 0 { + //~^ ERROR: all if blocks contain the same code at the start let y = 9; println!("The value y was set to: `{}`", y); let _z = y; @@ -39,6 +41,7 @@ fn simple_examples() { // Return a value let _ = if x == 7 { + //~^ ERROR: all if blocks contain the same code at the start let y = 16; println!("What can I say except: \"you're welcome?\""); let _ = y; @@ -57,6 +60,7 @@ fn simple_but_suggestion_is_invalid() { // Can't be automatically moved because used_value_name is getting used again let used_value_name = 19; if x == 10 { + //~^ ERROR: all if blocks contain the same code at the start let used_value_name = "Different type"; println!("Str: {}", used_value_name); let _ = 1; @@ -71,6 +75,7 @@ fn simple_but_suggestion_is_invalid() { let can_be_overridden = 8; let _ = can_be_overridden; if x == 11 { + //~^ ERROR: all if blocks contain the same code at the start let can_be_overridden = "Move me"; println!("I'm also moveable"); let _ = 111; @@ -87,6 +92,7 @@ fn check_if_same_than_else_mask() { #[allow(clippy::if_same_then_else)] if x == 2020 { + //~^ ERROR: all if blocks contain the same code at the start println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); println!("Because `IF_SAME_THEN_ELSE` is allowed here"); } else { @@ -95,6 +101,7 @@ fn check_if_same_than_else_mask() { } if x == 2019 { + //~^ ERROR: this `if` has identical blocks println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); } else { println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); diff --git a/tests/ui/branches_sharing_code/shared_at_top.stderr b/tests/ui/branches_sharing_code/shared_at_top.stderr index 3e3242a75d303..9d4d42fb689e4 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top.stderr @@ -2,6 +2,7 @@ error: all if blocks contain the same code at the start --> $DIR/shared_at_top.rs:11:5 | LL | / if true { +LL | | LL | | println!("Hello World!"); | |_________________________________^ | @@ -17,9 +18,10 @@ LL + if true { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:20:5 + --> $DIR/shared_at_top.rs:21:5 | LL | / if x == 0 { +LL | | LL | | let y = 9; LL | | println!("The value y was set to: `{}`", y); LL | | let _z = y; @@ -35,9 +37,10 @@ LL + if x == 0 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:41:5 + --> $DIR/shared_at_top.rs:43:5 | LL | / let _ = if x == 7 { +LL | | LL | | let y = 16; | |___________________^ | @@ -48,9 +51,10 @@ LL + let _ = if x == 7 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:59:5 + --> $DIR/shared_at_top.rs:62:5 | LL | / if x == 10 { +LL | | LL | | let used_value_name = "Different type"; LL | | println!("Str: {}", used_value_name); | |_____________________________________________^ @@ -64,9 +68,10 @@ LL + if x == 10 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:73:5 + --> $DIR/shared_at_top.rs:77:5 | LL | / if x == 11 { +LL | | LL | | let can_be_overridden = "Move me"; LL | | println!("I'm also moveable"); | |______________________________________^ @@ -80,9 +85,10 @@ LL + if x == 11 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:89:5 + --> $DIR/shared_at_top.rs:94:5 | LL | / if x == 2020 { +LL | | LL | | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); LL | | println!("Because `IF_SAME_THEN_ELSE` is allowed here"); | |________________________________________________________________^ @@ -95,16 +101,17 @@ LL + if x == 2020 { | error: this `if` has identical blocks - --> $DIR/shared_at_top.rs:97:18 + --> $DIR/shared_at_top.rs:103:18 | LL | if x == 2019 { | __________________^ +LL | | LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); LL | | } else { | |_____^ | note: same as this - --> $DIR/shared_at_top.rs:99:12 + --> $DIR/shared_at_top.rs:106:12 | LL | } else { | ____________^ diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs index eb0b937e22089..36620ee1a9bf0 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs @@ -15,6 +15,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 7 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let t = 7; let _overlap_start = t * 2; let _overlap_end = 2 * t; @@ -31,6 +32,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 99 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let r = 7; let _overlap_start = r; let _overlap_middle = r * r; @@ -60,6 +62,7 @@ fn complexer_example() { let x = 8; let y = 9; if (x > 7 && y < 13) || (x + y) % 2 == 1 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let a = 0xcafe; let b = 0xffff00ff; let e_id = gen_id(a, b); @@ -93,6 +96,7 @@ fn added_note_for_expression_use() -> u32 { let x = 9; let _ = if x == 7 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let _ = 19; let _splitter = 6; @@ -105,6 +109,7 @@ fn added_note_for_expression_use() -> u32 { }; if x == 9 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let _ = 17; let _splitter = 6; diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr index ccd697a421551..74495fca8ab75 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr @@ -2,13 +2,14 @@ error: all if blocks contain the same code at both the start and the end --> $DIR/shared_at_top_and_bottom.rs:17:5 | LL | / if x == 7 { +LL | | LL | | let t = 7; LL | | let _overlap_start = t * 2; LL | | let _overlap_end = 2 * t; | |_________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:29:5 + --> $DIR/shared_at_top_and_bottom.rs:30:5 | LL | / let _u = 9; LL | | } @@ -32,16 +33,17 @@ LL + let _u = 9; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:33:5 + --> $DIR/shared_at_top_and_bottom.rs:34:5 | LL | / if x == 99 { +LL | | LL | | let r = 7; LL | | let _overlap_start = r; LL | | let _overlap_middle = r * r; | |____________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:44:5 + --> $DIR/shared_at_top_and_bottom.rs:46:5 | LL | / let _overlap_end = r * r * r; LL | | let z = "end"; @@ -63,16 +65,17 @@ LL + let z = "end"; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:62:5 + --> $DIR/shared_at_top_and_bottom.rs:64:5 | LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 { +LL | | LL | | let a = 0xcafe; LL | | let b = 0xffff00ff; LL | | let e_id = gen_id(a, b); | |________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:82:5 + --> $DIR/shared_at_top_and_bottom.rs:85:5 | LL | / let pack = DataPack { LL | | id: e_id, @@ -102,14 +105,15 @@ LL + process_data(pack); | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:95:5 + --> $DIR/shared_at_top_and_bottom.rs:98:5 | LL | / let _ = if x == 7 { +LL | | LL | | let _ = 19; | |___________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:104:5 + --> $DIR/shared_at_top_and_bottom.rs:108:5 | LL | / x << 2 LL | | }; @@ -127,14 +131,15 @@ LL ~ x << 2; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:107:5 + --> $DIR/shared_at_top_and_bottom.rs:111:5 | LL | / if x == 9 { +LL | | LL | | let _ = 17; | |___________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:116:5 + --> $DIR/shared_at_top_and_bottom.rs:121:5 | LL | / x * 4 LL | | } diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.rs b/tests/ui/branches_sharing_code/valid_if_blocks.rs index 5780ea0893777..2aeacb89c0cb6 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.rs +++ b/tests/ui/branches_sharing_code/valid_if_blocks.rs @@ -107,6 +107,7 @@ fn valid_examples() { // Let's test empty blocks if false { + //~^ ERROR: this `if` has identical blocks } else { } } @@ -118,6 +119,7 @@ fn trigger_other_lint() { // Same block if x == 0 { + //~^ ERROR: this `if` has identical blocks let u = 19; println!("How are u today?"); let _ = "This is a string"; @@ -129,12 +131,14 @@ fn trigger_other_lint() { // Only same expression let _ = if x == 6 { 7 } else { 7 }; + //~^ ERROR: this `if` has identical blocks // Same in else if block let _ = if x == 67 { println!("Well I'm the most important block"); "I'm a pretty string" } else if x == 68 { + //~^ ERROR: this `if` has identical blocks println!("I'm a doppelgänger"); // Don't listen to my clone below @@ -149,6 +153,7 @@ fn trigger_other_lint() { if x == 0 { println!("I'm single"); } else if x == 68 { + //~^ ERROR: this `if` has identical blocks println!("I'm a doppelgänger"); // Don't listen to my clone below } else { diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/tests/ui/branches_sharing_code/valid_if_blocks.stderr index a7e72b780affc..fcbf12235aa16 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.stderr +++ b/tests/ui/branches_sharing_code/valid_if_blocks.stderr @@ -3,11 +3,12 @@ error: this `if` has identical blocks | LL | if false { | ______________^ +LL | | LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:110:12 + --> $DIR/valid_if_blocks.rs:111:12 | LL | } else { | ____________^ @@ -20,10 +21,11 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:120:15 + --> $DIR/valid_if_blocks.rs:121:15 | LL | if x == 0 { | _______________^ +LL | | LL | | let u = 19; LL | | println!("How are u today?"); LL | | let _ = "This is a string"; @@ -31,7 +33,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:124:12 + --> $DIR/valid_if_blocks.rs:126:12 | LL | } else { | ____________^ @@ -42,22 +44,23 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:131:23 + --> $DIR/valid_if_blocks.rs:133:23 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ | note: same as this - --> $DIR/valid_if_blocks.rs:131:34 + --> $DIR/valid_if_blocks.rs:133:34 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:137:23 + --> $DIR/valid_if_blocks.rs:140:23 | LL | } else if x == 68 { | _______________________^ +LL | | LL | | println!("I'm a doppelgänger"); LL | | // Don't listen to my clone below LL | | @@ -66,7 +69,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:142:12 + --> $DIR/valid_if_blocks.rs:146:12 | LL | } else { | ____________^ @@ -78,17 +81,18 @@ LL | | }; | |_____^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:151:23 + --> $DIR/valid_if_blocks.rs:155:23 | LL | } else if x == 68 { | _______________________^ +LL | | LL | | println!("I'm a doppelgänger"); LL | | // Don't listen to my clone below LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:154:12 + --> $DIR/valid_if_blocks.rs:159:12 | LL | } else { | ____________^ diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index ba1ef6e49168e..3794fc5d441c6 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -8,9 +8,11 @@ fn main() { // naive byte count let _ = x.iter().filter(|&&a| a == 0).count(); + //~^ ERROR: you appear to be counting bytes the naive way // naive byte count let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); + //~^ ERROR: you appear to be counting bytes the naive way // not an equality count, OK. let _ = x.iter().filter(|a| **a > 0).count(); @@ -28,6 +30,7 @@ fn main() { // naive byte count let _ = x.iter().filter(|a| b + 1 == **a).count(); + //~^ ERROR: you appear to be counting bytes the naive way let y = vec![0_u16; 3]; diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 680b7b2bda8b9..39007f9d10aa2 100644 --- a/tests/ui/bytecount.stderr +++ b/tests/ui/bytecount.stderr @@ -11,13 +11,13 @@ LL | #[deny(clippy::naive_bytecount)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:13:13 + --> $DIR/bytecount.rs:14:13 | LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)` error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:30:13 + --> $DIR/bytecount.rs:32:13 | LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)` diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index d2cfa41611844..d0a092093f3e0 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -14,56 +14,101 @@ fn main() { // Test clippy::cast_precision_loss let x0 = 1i32; x0 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` let x1 = 1i64; x1 as f32; + //~^ ERROR: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, x1 as f64; + //~^ ERROR: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, let x2 = 1u32; x2 as f32; + //~^ ERROR: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, let x3 = 1u64; x3 as f32; + //~^ ERROR: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, x3 as f64; + //~^ ERROR: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, // Test clippy::cast_possible_truncation 1f32 as i32; + //~^ ERROR: casting `f32` to `i32` may truncate the value 1f32 as u32; + //~^ ERROR: casting `f32` to `u32` may truncate the value + //~| ERROR: casting `f32` to `u32` may lose the sign of the value + //~| NOTE: `-D clippy::cast-sign-loss` implied by `-D warnings` 1f64 as f32; + //~^ ERROR: casting `f64` to `f32` may truncate the value 1i32 as i8; + //~^ ERROR: casting `i32` to `i8` may truncate the value 1i32 as u8; + //~^ ERROR: casting `i32` to `u8` may truncate the value 1f64 as isize; + //~^ ERROR: casting `f64` to `isize` may truncate the value 1f64 as usize; + //~^ ERROR: casting `f64` to `usize` may truncate the value + //~| ERROR: casting `f64` to `usize` may lose the sign of the value 1f32 as u32 as u16; + //~^ ERROR: casting `u32` to `u16` may truncate the value + //~| ERROR: casting `f32` to `u32` may truncate the value + //~| ERROR: casting `f32` to `u32` may lose the sign of the value { let _x: i8 = 1i32 as _; + //~^ ERROR: casting `i32` to `i8` may truncate the value 1f32 as i32; + //~^ ERROR: casting `f32` to `i32` may truncate the value 1f64 as i32; + //~^ ERROR: casting `f64` to `i32` may truncate the value 1f32 as u8; + //~^ ERROR: casting `f32` to `u8` may truncate the value + //~| ERROR: casting `f32` to `u8` may lose the sign of the value } // Test clippy::cast_possible_wrap 1u8 as i8; + //~^ ERROR: casting `u8` to `i8` may wrap around the value + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` 1u16 as i16; + //~^ ERROR: casting `u16` to `i16` may wrap around the value 1u32 as i32; + //~^ ERROR: casting `u32` to `i32` may wrap around the value 1u64 as i64; + //~^ ERROR: casting `u64` to `i64` may wrap around the value 1usize as isize; + //~^ ERROR: casting `usize` to `isize` may wrap around the value // should not wrap, usize is never 8 bits 1usize as i8; + //~^ ERROR: casting `usize` to `i8` may truncate the value // wraps on 16 bit ptr size 1usize as i16; + //~^ ERROR: casting `usize` to `i16` may truncate the value + //~| ERROR: casting `usize` to `i16` may wrap around the value on targets with 16-bit + //~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms // wraps on 32 bit ptr size 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit // wraps on 64 bit ptr size 1usize as i64; + //~^ ERROR: casting `usize` to `i64` may wrap around the value on targets with 64-bit // should not wrap, isize is never 8 bits 1u8 as isize; // wraps on 16 bit ptr size 1u16 as isize; + //~^ ERROR: casting `u16` to `isize` may wrap around the value on targets with 16-bit + //~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms // wraps on 32 bit ptr size 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit // wraps on 64 bit ptr size 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; + //~^ ERROR: casting `i32` to `u32` may lose the sign of the value 1isize as usize; -1isize as usize; + //~^ ERROR: casting `isize` to `usize` may lose the sign of the value 0i8 as u8; i8::MAX as u8; i16::MAX as u16; @@ -132,6 +177,7 @@ fn main() { // Test for signed min // should be linted because signed (-99999999999i64).min(1) as i8; + //~^ ERROR: casting `i64` to `i8` may truncate the value // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; @@ -145,6 +191,7 @@ fn main() { 999999u64.clamp(0, 255) as u8; // should still be linted 999999u64.clamp(0, 256) as u8; + //~^ ERROR: casting `u64` to `u8` may truncate the value #[derive(Clone, Copy)] enum E1 { @@ -167,7 +214,10 @@ fn main() { impl E2 { fn test(self) { let _ = self as u8; + //~^ ERROR: casting `main::E2` to `u8` may truncate the value let _ = Self::B as u8; + //~^ ERROR: casting `main::E2::B` to `u8` will truncate the value + //~| NOTE: `-D clippy::cast-enum-truncation` implied by `-D warnings` // Don't lint. `255..=256` fits in i16 let _ = self as i16; // Don't lint. @@ -208,7 +258,9 @@ fn main() { impl E5 { fn test(self) { let _ = self as i8; + //~^ ERROR: casting `main::E5` to `i8` may truncate the value let _ = Self::A as i8; + //~^ ERROR: casting `main::E5::A` to `i8` will truncate the value // Don't lint. `-129..=127` fits in i16 let _ = self as i16; // Don't lint. @@ -225,6 +277,7 @@ fn main() { impl E6 { fn test(self) { let _ = self as i16; + //~^ ERROR: casting `main::E6` to `i16` may truncate the value // Don't lint. `2^16-1` fits in u16 let _ = Self::A as u16; // Don't lint. `2^16-1..=2^16` fits in u32 @@ -243,6 +296,7 @@ fn main() { impl E7 { fn test(self) { let _ = self as usize; + //~^ ERROR: casting `main::E7` to `usize` may truncate the value on targets wi // Don't lint. let _ = Self::A as usize; // Don't lint. `2^32-1..=2^32` fits in u64 @@ -289,6 +343,7 @@ fn main() { impl E10 { fn test(self) { let _ = self as u16; + //~^ ERROR: casting `main::E10` to `u16` may truncate the value // Don't lint. let _ = Self::B as u32; // Don't lint. @@ -299,8 +354,10 @@ fn main() { fn avoid_subtract_overflow(q: u32) { let c = (q >> 16) as u8; + //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; let c = (q / 1000) as u8; + //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index f0630743aa75c..5442ef5db16d2 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -7,37 +7,37 @@ LL | x0 as f32; = note: `-D clippy::cast-precision-loss` implied by `-D warnings` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:18:5 + --> $DIR/cast.rs:20:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:19:5 + --> $DIR/cast.rs:22:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:21:5 + --> $DIR/cast.rs:25:5 | LL | x2 as f32; | ^^^^^^^^^ error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:23:5 + --> $DIR/cast.rs:28:5 | LL | x3 as f32; | ^^^^^^^^^ error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:24:5 + --> $DIR/cast.rs:30:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:26:5 + --> $DIR/cast.rs:33:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | 1f32 as i32; = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:27:5 + --> $DIR/cast.rs:35:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | 1f32 as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:27:5 + --> $DIR/cast.rs:35:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | 1f32 as u32; = note: `-D clippy::cast-sign-loss` implied by `-D warnings` error: casting `f64` to `f32` may truncate the value - --> $DIR/cast.rs:28:5 + --> $DIR/cast.rs:39:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | 1f64 as f32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:29:5 + --> $DIR/cast.rs:41:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> $DIR/cast.rs:30:5 + --> $DIR/cast.rs:43:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:45:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -102,7 +102,7 @@ LL | 1f64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may truncate the value - --> $DIR/cast.rs:32:5 + --> $DIR/cast.rs:47:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -110,13 +110,13 @@ LL | 1f64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may lose the sign of the value - --> $DIR/cast.rs:32:5 + --> $DIR/cast.rs:47:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> $DIR/cast.rs:33:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:33:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -136,13 +136,13 @@ LL | 1f32 as u32 as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:33:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:35:22 + --> $DIR/cast.rs:55:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -154,7 +154,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:36:9 + --> $DIR/cast.rs:57:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | 1f32 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `i32` may truncate the value - --> $DIR/cast.rs:37:9 + --> $DIR/cast.rs:59:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -170,7 +170,7 @@ LL | 1f64 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may truncate the value - --> $DIR/cast.rs:38:9 + --> $DIR/cast.rs:61:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -178,13 +178,13 @@ LL | 1f32 as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may lose the sign of the value - --> $DIR/cast.rs:38:9 + --> $DIR/cast.rs:61:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> $DIR/cast.rs:41:5 + --> $DIR/cast.rs:66:5 | LL | 1u8 as i8; | ^^^^^^^^^ @@ -192,31 +192,31 @@ LL | 1u8 as i8; = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` error: casting `u16` to `i16` may wrap around the value - --> $DIR/cast.rs:42:5 + --> $DIR/cast.rs:69:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> $DIR/cast.rs:43:5 + --> $DIR/cast.rs:71:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> $DIR/cast.rs:44:5 + --> $DIR/cast.rs:73:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> $DIR/cast.rs:45:5 + --> $DIR/cast.rs:75:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:78:5 | LL | 1usize as i8; | ^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:81:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:81:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -249,7 +249,7 @@ LL | 1usize as i16; = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:86:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -261,19 +261,19 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:86:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:53:5 + --> $DIR/cast.rs:90:5 | LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:57:5 + --> $DIR/cast.rs:95:5 | LL | 1u16 as isize; | ^^^^^^^^^^^^^ @@ -282,13 +282,13 @@ LL | 1u16 as isize; = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:59:5 + --> $DIR/cast.rs:99:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:61:5 + --> $DIR/cast.rs:102:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -300,25 +300,25 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:61:5 + --> $DIR/cast.rs:102:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:64:5 + --> $DIR/cast.rs:107:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:66:5 + --> $DIR/cast.rs:110:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:134:5 + --> $DIR/cast.rs:179:5 | LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -330,7 +330,7 @@ LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> $DIR/cast.rs:147:5 + --> $DIR/cast.rs:193:5 | LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -342,7 +342,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> $DIR/cast.rs:169:21 + --> $DIR/cast.rs:216:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -354,7 +354,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> $DIR/cast.rs:170:21 + --> $DIR/cast.rs:218:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | let _ = Self::B as u8; = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` error: casting `main::E5` to `i8` may truncate the value - --> $DIR/cast.rs:210:21 + --> $DIR/cast.rs:260:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -374,13 +374,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> $DIR/cast.rs:211:21 + --> $DIR/cast.rs:262:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:227:21 + --> $DIR/cast.rs:279:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -392,7 +392,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:245:21 + --> $DIR/cast.rs:298:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -404,7 +404,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> $DIR/cast.rs:291:21 + --> $DIR/cast.rs:345:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -416,7 +416,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:301:13 + --> $DIR/cast.rs:356:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -428,7 +428,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:304:13 + --> $DIR/cast.rs:360:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_alignment.rs b/tests/ui/cast_alignment.rs index 95bb883df1bf1..98ef5e36f9488 100644 --- a/tests/ui/cast_alignment.rs +++ b/tests/ui/cast_alignment.rs @@ -17,11 +17,16 @@ fn main() { // cast to more-strictly-aligned type (&1u8 as *const u8) as *const u16; + //~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) + //~| NOTE: `-D clippy::cast-ptr-alignment` implied by `-D warnings` (&mut 1u8 as *mut u8) as *mut u16; + //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 // cast to more-strictly-aligned type, but with the `pointer::cast` function. (&1u8 as *const u8).cast::(); + //~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (&mut 1u8 as *mut u8).cast::(); + //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 /* These should be ok */ diff --git a/tests/ui/cast_alignment.stderr b/tests/ui/cast_alignment.stderr index 5df2b5b1094be..70510eaf6345a 100644 --- a/tests/ui/cast_alignment.stderr +++ b/tests/ui/cast_alignment.stderr @@ -7,19 +7,19 @@ LL | (&1u8 as *const u8) as *const u16; = note: `-D clippy::cast-ptr-alignment` implied by `-D warnings` error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:20:5 + --> $DIR/cast_alignment.rs:22:5 | LL | (&mut 1u8 as *mut u8) as *mut u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:23:5 + --> $DIR/cast_alignment.rs:26:5 | LL | (&1u8 as *const u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:24:5 + --> $DIR/cast_alignment.rs:28:5 | LL | (&mut 1u8 as *mut u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_enum_constructor.rs b/tests/ui/cast_enum_constructor.rs index 0193454ad144c..3226f487b3aff 100644 --- a/tests/ui/cast_enum_constructor.rs +++ b/tests/ui/cast_enum_constructor.rs @@ -11,7 +11,10 @@ fn main() { } let _ = Foo::Y as usize; + //~^ ERROR: cast of an enum tuple constructor to an integer + //~| NOTE: `-D clippy::cast-enum-constructor` implied by `-D warnings` let _ = Foo::Y as isize; + //~^ ERROR: cast of an enum tuple constructor to an integer let _ = Foo::Y as fn(u32) -> Foo; let _ = Bar::X as usize; } diff --git a/tests/ui/cast_enum_constructor.stderr b/tests/ui/cast_enum_constructor.stderr index 710909dd26fa8..f0489f08f9105 100644 --- a/tests/ui/cast_enum_constructor.stderr +++ b/tests/ui/cast_enum_constructor.stderr @@ -7,7 +7,7 @@ LL | let _ = Foo::Y as usize; = note: `-D clippy::cast-enum-constructor` implied by `-D warnings` error: cast of an enum tuple constructor to an integer - --> $DIR/cast_enum_constructor.rs:14:13 + --> $DIR/cast_enum_constructor.rs:16:13 | LL | let _ = Foo::Y as isize; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_nan_to_int.rs b/tests/ui/cast_nan_to_int.rs index 287c5aa216bd3..2d7467ff0400d 100644 --- a/tests/ui/cast_nan_to_int.rs +++ b/tests/ui/cast_nan_to_int.rs @@ -3,12 +3,24 @@ fn main() { let _ = (0.0_f32 / -0.0) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f64::INFINITY * -0.0) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (0.0 * f32::INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f32::INFINITY - f32::INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 // those won't be linted: let _ = (1.0_f32 / 0.0) as usize; diff --git a/tests/ui/cast_nan_to_int.stderr b/tests/ui/cast_nan_to_int.stderr index 3539be75a19db..678db89954e51 100644 --- a/tests/ui/cast_nan_to_int.stderr +++ b/tests/ui/cast_nan_to_int.stderr @@ -8,7 +8,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize; = note: `-D clippy::cast-nan-to-int` implied by `-D warnings` error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:6:13 + --> $DIR/cast_nan_to_int.rs:8:13 | LL | let _ = (f64::INFINITY * -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:7:13 + --> $DIR/cast_nan_to_int.rs:11:13 | LL | let _ = (0.0 * f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:9:13 + --> $DIR/cast_nan_to_int.rs:15:13 | LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:10:13 + --> $DIR/cast_nan_to_int.rs:18:13 | LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:11:13 + --> $DIR/cast_nan_to_int.rs:21:13 | LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index 4d4341ab55cf3..95626b20b27bf 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -10,27 +10,47 @@ fn main() { // Casting from *size 1isize as i8; + //~^ ERROR: casting `isize` to `i8` may truncate the value let x0 = 1isize; let x1 = 1usize; x0 as f64; + //~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` x1 as f64; + //~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit x0 as f32; + //~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b x1 as f32; + //~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b 1isize as i32; + //~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid 1isize as u32; + //~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid 1usize as u32; + //~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` // Casting to *size 1i64 as isize; + //~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid 1i64 as usize; + //~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit 1u64 as usize; + //~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; // Big integer literal to float 999_999_999 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, 9_999_999_999_999_999usize as f64; + //~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit } //@no-rustfix diff --git a/tests/ui/cast_size.stderr b/tests/ui/cast_size.stderr index 6d2d49d9ed208..6c7459b3abaee 100644 --- a/tests/ui/cast_size.stderr +++ b/tests/ui/cast_size.stderr @@ -12,7 +12,7 @@ LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:15:5 + --> $DIR/cast_size.rs:16:5 | LL | x0 as f64; | ^^^^^^^^^ @@ -20,25 +20,25 @@ LL | x0 as f64; = note: `-D clippy::cast-precision-loss` implied by `-D warnings` error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:16:5 + --> $DIR/cast_size.rs:19:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:17:5 + --> $DIR/cast_size.rs:21:5 | LL | x0 as f32; | ^^^^^^^^^ error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:18:5 + --> $DIR/cast_size.rs:23:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:19:5 + --> $DIR/cast_size.rs:25:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:20:5 + --> $DIR/cast_size.rs:27:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:21:5 + --> $DIR/cast_size.rs:29:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:22:5 + --> $DIR/cast_size.rs:31:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:22:5 + --> $DIR/cast_size.rs:31:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | 1usize as i32; = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:24:5 + --> $DIR/cast_size.rs:36:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:25:5 + --> $DIR/cast_size.rs:38:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:26:5 + --> $DIR/cast_size.rs:40:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -130,13 +130,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:26:5 + --> $DIR/cast_size.rs:40:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:27:5 + --> $DIR/cast_size.rs:43:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -148,19 +148,19 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:28:5 + --> $DIR/cast_size.rs:45:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:33:5 + --> $DIR/cast_size.rs:51:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:34:5 + --> $DIR/cast_size.rs:53:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size_32bit.rs b/tests/ui/cast_size_32bit.rs index 7ca20d3ca4a76..5a06e34bdb8fb 100644 --- a/tests/ui/cast_size_32bit.rs +++ b/tests/ui/cast_size_32bit.rs @@ -10,26 +10,47 @@ fn main() { // Casting from *size 1isize as i8; + //~^ ERROR: casting `isize` to `i8` may truncate the value let x0 = 1isize; let x1 = 1usize; x0 as f64; + //~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` x1 as f64; + //~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit x0 as f32; + //~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b x1 as f32; + //~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b 1isize as i32; + //~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid 1isize as u32; + //~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid 1usize as u32; + //~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` // Casting to *size 1i64 as isize; + //~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid 1i64 as usize; + //~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit 1u64 as usize; + //~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; // Big integer literal to float 999_999_999 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, 3_999_999_999usize as f64; + //~^ ERROR: casting integer literal to `f64` is unnecessary + //~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings` } diff --git a/tests/ui/cast_slice_different_sizes.rs b/tests/ui/cast_slice_different_sizes.rs index 6d2f99b7db5d2..d8101030a8a2d 100644 --- a/tests/ui/cast_slice_different_sizes.rs +++ b/tests/ui/cast_slice_different_sizes.rs @@ -8,10 +8,14 @@ fn main() { // Because it's separate, it does not check the cast back to something of the same size let a = r_x as *const [i32]; let b = a as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme + //~| NOTE: `#[deny(clippy::cast_slice_different_sizes)]` on by default let c = b as *const [u32]; + //~^ ERROR: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (eleme // loses data let loss = r_x as *const [i32] as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme // Cast back to same size but different type loses no data, just type conversion // This is weird code but there's no reason for this lint specifically to fire *twice* on it @@ -19,7 +23,9 @@ fn main() { // Check casting through blocks is detected let loss_block_1 = { r_x as *const [i32] } as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let loss_block_2 = { + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let _ = (); r_x as *const [i32] } as *const [u8]; @@ -37,6 +43,7 @@ fn main() { // Check that the result of a long chain of casts is detected let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let long_chain_restore = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8] as *const [u32]; } @@ -52,32 +59,40 @@ fn foo2(x: *mut [u8]) -> *mut [u8] { // Test that casts as part of function returns work fn bar(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as *mut [u8] } fn uwu(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as *mut _ } fn bar2(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // constify fn bar3(x: *mut [u16]) -> *const [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // unconstify fn bar4(x: *const [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // function returns plus blocks fn blocks(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s ({ x }) as _ } fn more_blocks(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s { ({ x }) as _ } + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (eleme } diff --git a/tests/ui/cast_slice_different_sizes.stderr b/tests/ui/cast_slice_different_sizes.stderr index cd2cdfff32582..a5c38e310f67a 100644 --- a/tests/ui/cast_slice_different_sizes.stderr +++ b/tests/ui/cast_slice_different_sizes.stderr @@ -7,28 +7,29 @@ LL | let b = a as *const [u8]; = note: `#[deny(clippy::cast_slice_different_sizes)]` on by default error: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (element size 4) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:11:13 + --> $DIR/cast_slice_different_sizes.rs:13:13 | LL | let c = b as *const [u32]; | ^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(b as *const u32, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:14:16 + --> $DIR/cast_slice_different_sizes.rs:17:16 | LL | let loss = r_x as *const [i32] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:21:24 + --> $DIR/cast_slice_different_sizes.rs:25:24 | LL | let loss_block_1 = { r_x as *const [i32] } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts({ r_x as *const [i32] } as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:22:24 + --> $DIR/cast_slice_different_sizes.rs:27:24 | LL | let loss_block_2 = { | ________________________^ +LL | | LL | | let _ = (); LL | | r_x as *const [i32] LL | | } as *const [u8]; @@ -37,82 +38,91 @@ LL | | } as *const [u8]; help: replace with `ptr::slice_from_raw_parts` | LL ~ let loss_block_2 = core::ptr::slice_from_raw_parts({ +LL + LL + let _ = (); LL + r_x as *const [i32] LL ~ } as *const u8, ..); | error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:39:27 + --> $DIR/cast_slice_different_sizes.rs:45:27 | LL | let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:54:36 + --> $DIR/cast_slice_different_sizes.rs:61:36 | LL | fn bar(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ +LL | | LL | | x as *mut [u8] LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:58:36 + --> $DIR/cast_slice_different_sizes.rs:66:36 | LL | fn uwu(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ +LL | | LL | | x as *mut _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:62:37 + --> $DIR/cast_slice_different_sizes.rs:71:37 | LL | fn bar2(x: *mut [u16]) -> *mut [u8] { | _____________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:67:39 + --> $DIR/cast_slice_different_sizes.rs:77:39 | LL | fn bar3(x: *mut [u16]) -> *const [u8] { | _______________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(x as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:72:39 + --> $DIR/cast_slice_different_sizes.rs:83:39 | LL | fn bar4(x: *const [u16]) -> *mut [u8] { | _______________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:77:39 + --> $DIR/cast_slice_different_sizes.rs:89:39 | LL | fn blocks(x: *mut [u16]) -> *mut [u8] { | _______________________________________^ +LL | | LL | | ({ x }) as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:81:44 + --> $DIR/cast_slice_different_sizes.rs:94:44 | LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] { | ____________________________________________^ +LL | | LL | | { ({ x }) as _ } +LL | | LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:82:5 + --> $DIR/cast_slice_different_sizes.rs:96:5 | LL | { ({ x }) as _ } | ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` diff --git a/tests/ui/cfg_features.fixed b/tests/ui/cfg_features.fixed index c3e570698d7dc..3d52f2382ea72 100644 --- a/tests/ui/cfg_features.fixed +++ b/tests/ui/cfg_features.fixed @@ -2,11 +2,16 @@ fn main() { #[cfg(feature = "not-really-a-feature")] + //~^ ERROR: feature may misspelled as features + //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings` let _ = 1 + 2; #[cfg(all(feature = "right", feature = "wrong"))] + //~^ ERROR: feature may misspelled as features let _ = 1 + 2; #[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))] + //~^ ERROR: feature may misspelled as features + //~| ERROR: feature may misspelled as features let _ = 1 + 2; } diff --git a/tests/ui/cfg_features.rs b/tests/ui/cfg_features.rs index bc4109c2c8964..a0344a0044799 100644 --- a/tests/ui/cfg_features.rs +++ b/tests/ui/cfg_features.rs @@ -2,11 +2,16 @@ fn main() { #[cfg(features = "not-really-a-feature")] + //~^ ERROR: feature may misspelled as features + //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings` let _ = 1 + 2; #[cfg(all(feature = "right", features = "wrong"))] + //~^ ERROR: feature may misspelled as features let _ = 1 + 2; #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] + //~^ ERROR: feature may misspelled as features + //~| ERROR: feature may misspelled as features let _ = 1 + 2; } diff --git a/tests/ui/cfg_features.stderr b/tests/ui/cfg_features.stderr index 00405985d48c7..5f92dfe169c72 100644 --- a/tests/ui/cfg_features.stderr +++ b/tests/ui/cfg_features.stderr @@ -7,19 +7,19 @@ LL | #[cfg(features = "not-really-a-feature")] = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings` error: feature may misspelled as features - --> $DIR/cfg_features.rs:7:34 + --> $DIR/cfg_features.rs:9:34 | LL | #[cfg(all(feature = "right", features = "wrong"))] | ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"` error: feature may misspelled as features - --> $DIR/cfg_features.rs:10:15 + --> $DIR/cfg_features.rs:13:15 | LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong1"` error: feature may misspelled as features - --> $DIR/cfg_features.rs:10:59 + --> $DIR/cfg_features.rs:13:59 | LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"` diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index e724c456b8883..7bb3daf0f1e72 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -3,4 +3,6 @@ fn main() { // no suggestion, since a byte literal won't work. let _ = '❤' as u8; + //~^ ERROR: casting a character literal to `u8` truncates + //~| NOTE: `char` is four bytes wide, but `u8` is a single byte } diff --git a/tests/ui/checked_unwrap/complex_conditionals.rs b/tests/ui/checked_unwrap/complex_conditionals.rs index 9e618350b1982..323dae380633d 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -11,12 +11,16 @@ fn test_complex_conditions() { if x.is_ok() && y.is_err() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic // will panic y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_err` } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -32,27 +36,37 @@ fn test_complex_conditions() { } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` // will panic y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` } let z: Result<(), ()> = Ok(()); if x.is_ok() && !(y.is_ok() || z.is_err()) { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic // will panic y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` // unnecessary z.unwrap(); + //~^ ERROR: called `unwrap` on `z` after checking its variant with `is_err` // will panic z.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -62,16 +76,22 @@ fn test_complex_conditions() { } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` // unnecessary y.unwrap(); + //~^ ERROR: called `unwrap` on `y` after checking its variant with `is_ok` // will panic y.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic // will panic z.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary z.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `z` after checking its variant with `is_err` } } diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index f342815ac76ba..73c074a93393f 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -15,7 +15,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:15:9 + --> $DIR/complex_conditionals.rs:16:9 | LL | if x.is_ok() && y.is_err() { | --------- because of this check @@ -30,7 +30,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:17:9 + --> $DIR/complex_conditionals.rs:19:9 | LL | if x.is_ok() && y.is_err() { | ---------- because of this check @@ -39,7 +39,7 @@ LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:19:9 + --> $DIR/complex_conditionals.rs:22:9 | LL | if x.is_ok() && y.is_err() { | ---------- the check is happening here @@ -50,7 +50,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:34:9 + --> $DIR/complex_conditionals.rs:38:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check @@ -59,7 +59,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:36:9 + --> $DIR/complex_conditionals.rs:41:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here @@ -70,7 +70,7 @@ LL | x.unwrap_err(); = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:38:9 + --> $DIR/complex_conditionals.rs:44:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check @@ -79,7 +79,7 @@ LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:40:9 + --> $DIR/complex_conditionals.rs:47:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here @@ -90,7 +90,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:45:9 + --> $DIR/complex_conditionals.rs:53:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here @@ -101,7 +101,7 @@ LL | x.unwrap(); = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:47:9 + --> $DIR/complex_conditionals.rs:56:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check @@ -110,7 +110,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:49:9 + --> $DIR/complex_conditionals.rs:59:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check @@ -119,7 +119,7 @@ LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:51:9 + --> $DIR/complex_conditionals.rs:62:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here @@ -130,7 +130,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: called `unwrap` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:53:9 + --> $DIR/complex_conditionals.rs:65:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- the check is happening here @@ -141,7 +141,7 @@ LL | z.unwrap(); = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:55:9 + --> $DIR/complex_conditionals.rs:68:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- because of this check @@ -150,7 +150,7 @@ LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:64:9 + --> $DIR/complex_conditionals.rs:78:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check @@ -159,7 +159,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:66:9 + --> $DIR/complex_conditionals.rs:81:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here @@ -170,7 +170,7 @@ LL | x.unwrap_err(); = help: try using `if let` or `match` error: called `unwrap` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:68:9 + --> $DIR/complex_conditionals.rs:84:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here @@ -181,7 +181,7 @@ LL | y.unwrap(); = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:70:9 + --> $DIR/complex_conditionals.rs:87:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check @@ -190,7 +190,7 @@ LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:72:9 + --> $DIR/complex_conditionals.rs:90:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- because of this check @@ -199,7 +199,7 @@ LL | z.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:74:9 + --> $DIR/complex_conditionals.rs:93:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index 1ee8d16565b5c..68923793dcdf9 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -11,9 +11,11 @@ fn test_nested() { if x.is_some() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic } } } diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr index bf7c6750ccfda..d9f701a5b2e00 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr @@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals_nested.rs:16:13 + --> $DIR/complex_conditionals_nested.rs:17:13 | LL | if x.is_some() { | ----------- because of this check diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 12522ae5ba12c..e82e7bcb06cb0 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -45,20 +45,26 @@ fn main() { if x.is_some() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` // unnecessary x.expect("an error message"); + //~^ ERROR: called `expect` on `x` after checking its variant with `is_some` } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // will panic x.expect("an error message"); + //~^ ERROR: this call to `expect()` will always panic } if x.is_none() { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic } else { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_none` } m!(x); // ok @@ -71,28 +77,38 @@ fn main() { if x.is_ok() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` // unnecessary x.expect("an error message"); + //~^ ERROR: called `expect` on `x` after checking its variant with `is_ok` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // will panic x.expect("an error message"); + //~^ ERROR: this call to `expect()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` } if x.is_err() { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_err` } else { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_err` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } if x.is_ok() { x = Err(()); diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index 0c5a64979241f..ed603581ecddb 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:49:9 + --> $DIR/simple_conditionals.rs:50:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` @@ -23,7 +23,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:52:9 + --> $DIR/simple_conditionals.rs:54:9 | LL | if x.is_some() { | ----------- because of this check @@ -38,7 +38,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:54:9 + --> $DIR/simple_conditionals.rs:57:9 | LL | if x.is_some() { | ----------- because of this check @@ -47,7 +47,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:58:9 + --> $DIR/simple_conditionals.rs:62:9 | LL | if x.is_none() { | ----------- because of this check @@ -56,7 +56,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> $DIR/simple_conditionals.rs:61:9 + --> $DIR/simple_conditionals.rs:66:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` @@ -79,7 +79,7 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:73:9 + --> $DIR/simple_conditionals.rs:79:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -88,7 +88,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:75:9 + --> $DIR/simple_conditionals.rs:82:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -97,7 +97,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:77:9 + --> $DIR/simple_conditionals.rs:85:9 | LL | if x.is_ok() { | --------- because of this check @@ -106,7 +106,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:80:9 + --> $DIR/simple_conditionals.rs:89:9 | LL | if x.is_ok() { | --------- because of this check @@ -115,7 +115,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:82:9 + --> $DIR/simple_conditionals.rs:92:9 | LL | if x.is_ok() { | --------- because of this check @@ -124,7 +124,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:84:9 + --> $DIR/simple_conditionals.rs:95:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` @@ -133,7 +133,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:88:9 + --> $DIR/simple_conditionals.rs:100:9 | LL | if x.is_err() { | ---------- because of this check @@ -142,7 +142,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:90:9 + --> $DIR/simple_conditionals.rs:103:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` @@ -151,7 +151,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:93:9 + --> $DIR/simple_conditionals.rs:107:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` @@ -160,7 +160,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:95:9 + --> $DIR/simple_conditionals.rs:110:9 | LL | if x.is_err() { | ---------- because of this check diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index 2d2d04178c35d..ef1d93940aa6e 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -7,11 +7,14 @@ fn main() { let x = 0; let p: *const usize = &x; if p == ptr::null() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~| NOTE: `-D clippy::cmp-null` implied by `-D warnings` println!("This is surprising!"); } let mut y = 0; let mut m: *mut usize = &mut y; if m == ptr::null_mut() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method println!("This is surprising, too!"); } } diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index a1f4c70fb2786..cc2ffb21b476b 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -7,7 +7,7 @@ LL | if p == ptr::null() { = note: `-D clippy::cmp-null` implied by `-D warnings` error: comparing with null is better expressed by the `.is_null()` method - --> $DIR/cmp_null.rs:14:8 + --> $DIR/cmp_null.rs:16:8 | LL | if m == ptr::null_mut() { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cmp_owned/without_suggestion.rs b/tests/ui/cmp_owned/without_suggestion.rs index d8a202cb6a1c6..ec45d635c1727 100644 --- a/tests/ui/cmp_owned/without_suggestion.rs +++ b/tests/ui/cmp_owned/without_suggestion.rs @@ -5,10 +5,13 @@ fn main() { let x = &Baz; let y = &Baz; y.to_owned() == *x; + //~^ ERROR: this creates an owned instance just for comparison + //~| NOTE: `-D clippy::cmp-owned` implied by `-D warnings` let x = &&Baz; let y = &Baz; y.to_owned() == **x; + //~^ ERROR: this creates an owned instance just for comparison let x = 0u32; let y = U32Wrapper(x); @@ -20,6 +23,7 @@ struct Foo; impl PartialEq for Foo { fn eq(&self, other: &Self) -> bool { self.to_owned() == *other + //~^ ERROR: this creates an owned instance just for comparison } } diff --git a/tests/ui/cmp_owned/without_suggestion.stderr b/tests/ui/cmp_owned/without_suggestion.stderr index d2dd14d8edbb8..fa7cb380eba18 100644 --- a/tests/ui/cmp_owned/without_suggestion.stderr +++ b/tests/ui/cmp_owned/without_suggestion.stderr @@ -7,13 +7,13 @@ LL | y.to_owned() == *x; = note: `-D clippy::cmp-owned` implied by `-D warnings` error: this creates an owned instance just for comparison - --> $DIR/without_suggestion.rs:11:5 + --> $DIR/without_suggestion.rs:13:5 | LL | y.to_owned() == **x; | ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating error: this creates an owned instance just for comparison - --> $DIR/without_suggestion.rs:22:9 + --> $DIR/without_suggestion.rs:25:9 | LL | self.to_owned() == *other | ^^^^^^^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating diff --git a/tests/ui/cognitive_complexity.rs b/tests/ui/cognitive_complexity.rs index 07bdaff00dc41..e8fd063a98f24 100644 --- a/tests/ui/cognitive_complexity.rs +++ b/tests/ui/cognitive_complexity.rs @@ -4,6 +4,7 @@ #[rustfmt::skip] fn main() { +//~^ ERROR: the function has a cognitive complexity of (28/25) if true { println!("a"); } @@ -89,6 +90,7 @@ fn main() { #[clippy::cognitive_complexity = "1"] fn kaboom() { + //~^ ERROR: the function has a cognitive complexity of (7/1) let n = 0; 'a: for i in 0..20 { 'b: for j in i..20 { @@ -147,7 +149,9 @@ fn lots_of_short_circuits2() -> bool { #[clippy::cognitive_complexity = "1"] fn baa() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let x = || match 99 { + //~^ ERROR: the function has a cognitive complexity of (2/1) 0 => 0, 1 => 1, 2 => 2, @@ -165,6 +169,7 @@ fn baa() { #[clippy::cognitive_complexity = "1"] fn bar() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -176,6 +181,7 @@ fn bar() { /// Tests are usually complex but simple at the same time. `clippy::cognitive_complexity` used to /// give lots of false-positives in tests. fn dont_warn_on_tests() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -184,6 +190,7 @@ fn dont_warn_on_tests() { #[clippy::cognitive_complexity = "1"] fn barr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -194,6 +201,7 @@ fn barr() { #[clippy::cognitive_complexity = "1"] fn barr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -210,6 +218,7 @@ fn barr2() { #[clippy::cognitive_complexity = "1"] fn barrr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -220,6 +229,7 @@ fn barrr() { #[clippy::cognitive_complexity = "1"] fn barrr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -236,6 +246,7 @@ fn barrr2() { #[clippy::cognitive_complexity = "1"] fn barrrr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -246,6 +257,7 @@ fn barrrr() { #[clippy::cognitive_complexity = "1"] fn barrrr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -262,6 +274,7 @@ fn barrrr2() { #[clippy::cognitive_complexity = "1"] fn cake() { + //~^ ERROR: the function has a cognitive complexity of (2/1) if 4 == 5 { println!("yea"); } else { @@ -272,6 +285,7 @@ fn cake() { #[clippy::cognitive_complexity = "1"] pub fn read_file(input_path: &str) -> String { + //~^ ERROR: the function has a cognitive complexity of (4/1) use std::fs::File; use std::io::{Read, Write}; use std::path::Path; @@ -303,6 +317,7 @@ enum Void {} #[clippy::cognitive_complexity = "1"] fn void(void: Void) { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { match void {} } @@ -354,6 +369,7 @@ fn early() -> Result { #[rustfmt::skip] #[clippy::cognitive_complexity = "1"] fn early_ret() -> i32 { +//~^ ERROR: the function has a cognitive complexity of (8/1) let a = if true { 42 } else { return 0; }; let a = if a < 99 { 42 } else { return 0; }; let a = if a < 99 { 42 } else { return 0; }; @@ -375,6 +391,7 @@ fn early_ret() -> i32 { #[clippy::cognitive_complexity = "1"] fn closures() { let x = |a: i32, b: i32| -> i32 { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { println!("moo"); } @@ -388,6 +405,7 @@ struct Moo; #[clippy::cognitive_complexity = "1"] impl Moo { fn moo(&self) { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { println!("moo"); } @@ -397,6 +415,7 @@ impl Moo { #[clippy::cognitive_complexity = "1"] mod issue9300 { async fn a() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let a = 0; if a == 0 {} } @@ -404,6 +423,7 @@ mod issue9300 { pub struct S; impl S { pub async fn async_method() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let a = 0; if a == 0 {} } diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index d867246301abd..a712b163b171c 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -8,7 +8,7 @@ LL | fn main() { = note: `-D clippy::cognitive-complexity` implied by `-D warnings` error: the function has a cognitive complexity of (7/1) - --> $DIR/cognitive_complexity.rs:91:4 + --> $DIR/cognitive_complexity.rs:92:4 | LL | fn kaboom() { | ^^^^^^ @@ -16,7 +16,7 @@ LL | fn kaboom() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:149:4 + --> $DIR/cognitive_complexity.rs:151:4 | LL | fn baa() { | ^^^ @@ -24,7 +24,7 @@ LL | fn baa() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:150:13 + --> $DIR/cognitive_complexity.rs:153:13 | LL | let x = || match 99 { | ^^ @@ -32,7 +32,7 @@ LL | let x = || match 99 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:167:4 + --> $DIR/cognitive_complexity.rs:171:4 | LL | fn bar() { | ^^^ @@ -40,7 +40,7 @@ LL | fn bar() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:178:4 + --> $DIR/cognitive_complexity.rs:183:4 | LL | fn dont_warn_on_tests() { | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | fn dont_warn_on_tests() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:186:4 + --> $DIR/cognitive_complexity.rs:192:4 | LL | fn barr() { | ^^^^ @@ -56,7 +56,7 @@ LL | fn barr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:196:4 + --> $DIR/cognitive_complexity.rs:203:4 | LL | fn barr2() { | ^^^^^ @@ -64,7 +64,7 @@ LL | fn barr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:212:4 + --> $DIR/cognitive_complexity.rs:220:4 | LL | fn barrr() { | ^^^^^ @@ -72,7 +72,7 @@ LL | fn barrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:222:4 + --> $DIR/cognitive_complexity.rs:231:4 | LL | fn barrr2() { | ^^^^^^ @@ -80,7 +80,7 @@ LL | fn barrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:238:4 + --> $DIR/cognitive_complexity.rs:248:4 | LL | fn barrrr() { | ^^^^^^ @@ -88,7 +88,7 @@ LL | fn barrrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:248:4 + --> $DIR/cognitive_complexity.rs:259:4 | LL | fn barrrr2() { | ^^^^^^^ @@ -96,7 +96,7 @@ LL | fn barrrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:264:4 + --> $DIR/cognitive_complexity.rs:276:4 | LL | fn cake() { | ^^^^ @@ -104,7 +104,7 @@ LL | fn cake() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (4/1) - --> $DIR/cognitive_complexity.rs:274:8 + --> $DIR/cognitive_complexity.rs:287:8 | LL | pub fn read_file(input_path: &str) -> String { | ^^^^^^^^^ @@ -112,7 +112,7 @@ LL | pub fn read_file(input_path: &str) -> String { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:305:4 + --> $DIR/cognitive_complexity.rs:319:4 | LL | fn void(void: Void) { | ^^^^ @@ -120,7 +120,7 @@ LL | fn void(void: Void) { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (8/1) - --> $DIR/cognitive_complexity.rs:356:4 + --> $DIR/cognitive_complexity.rs:371:4 | LL | fn early_ret() -> i32 { | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | fn early_ret() -> i32 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:377:13 + --> $DIR/cognitive_complexity.rs:393:13 | LL | let x = |a: i32, b: i32| -> i32 { | ^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let x = |a: i32, b: i32| -> i32 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:390:8 + --> $DIR/cognitive_complexity.rs:407:8 | LL | fn moo(&self) { | ^^^ @@ -144,7 +144,7 @@ LL | fn moo(&self) { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:399:14 + --> $DIR/cognitive_complexity.rs:417:14 | LL | async fn a() { | ^ @@ -152,7 +152,7 @@ LL | async fn a() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:406:22 + --> $DIR/cognitive_complexity.rs:425:22 | LL | pub async fn async_method() { | ^^^^^^^^^^^^ diff --git a/tests/ui/cognitive_complexity_attr_used.rs b/tests/ui/cognitive_complexity_attr_used.rs index 771a26fc9a86d..6f6e89983d2b7 100644 --- a/tests/ui/cognitive_complexity_attr_used.rs +++ b/tests/ui/cognitive_complexity_attr_used.rs @@ -7,6 +7,7 @@ fn main() { #[clippy::cognitive_complexity = "0"] fn kaboom() { + //~^ ERROR: the function has a cognitive complexity of (3/0) if 42 == 43 { panic!(); } else if "cake" == "lie" { diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs index 1d7a72846419f..7501fd2b0bd99 100644 --- a/tests/ui/collapsible_match.rs +++ b/tests/ui/collapsible_match.rs @@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match without block match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -20,6 +21,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match with block match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -29,6 +31,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, if let if let Ok(val) = res_opt { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` take(n); } } @@ -36,6 +39,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, if let else if let Ok(val) = res_opt { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` take(n); } else { return; @@ -47,6 +51,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, match if let Ok(val) = res_opt { match val { + //~^ ERROR: this `match` can be collapsed into the outer `if let` Some(n) => foo(n), _ => (), } @@ -56,6 +61,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `match` take(n); } }, @@ -65,6 +71,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, match if let Ok(val) = res_opt { match val { + //~^ ERROR: this `match` can be collapsed into the outer `if let` Some(n) => foo(n), _ => return, } @@ -76,6 +83,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `match` take(n); } else { return; @@ -87,6 +95,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // None in inner match same as outer wild branch match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), None => return, }, @@ -96,6 +105,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // None in outer match same as inner wild branch match opt_opt { Some(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -261,6 +271,7 @@ pub enum Issue9647 { pub fn test_1(x: Issue9647) { if let Issue9647::A { a, .. } = x { if let Some(u) = a { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` println!("{u:?}") } } @@ -269,6 +280,7 @@ pub fn test_1(x: Issue9647) { pub fn test_2(x: Issue9647) { if let Issue9647::A { a: Some(a), .. } = x { if let Some(u) = a { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` println!("{u}") } } diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 0294be60b43fd..51a5eedd761c2 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match` | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -13,38 +14,42 @@ help: the outer pattern can be modified to include the inner pattern | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:22:20 + --> $DIR/collapsible_match.rs:23:20 | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:22:12 + --> $DIR/collapsible_match.rs:23:12 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:31:9 + --> $DIR/collapsible_match.rs:33:9 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:30:15 + --> $DIR/collapsible_match.rs:32:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -52,9 +57,10 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:38:9 + --> $DIR/collapsible_match.rs:41:9 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -62,7 +68,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:37:15 + --> $DIR/collapsible_match.rs:40:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -70,33 +76,35 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:49:9 + --> $DIR/collapsible_match.rs:53:9 | LL | / match val { +LL | | LL | | Some(n) => foo(n), LL | | _ => (), LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:48:15 + --> $DIR/collapsible_match.rs:52:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding -LL | match val { +... LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:58:13 + --> $DIR/collapsible_match.rs:63:13 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:57:12 + --> $DIR/collapsible_match.rs:62:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -104,27 +112,29 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:67:9 + --> $DIR/collapsible_match.rs:73:9 | LL | / match val { +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:66:15 + --> $DIR/collapsible_match.rs:72:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding -LL | match val { +... LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:78:13 + --> $DIR/collapsible_match.rs:85:13 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -132,7 +142,7 @@ LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:77:12 + --> $DIR/collapsible_match.rs:84:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -140,51 +150,56 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:89:20 + --> $DIR/collapsible_match.rs:97:20 | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | None => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:89:12 + --> $DIR/collapsible_match.rs:97:12 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:98:22 + --> $DIR/collapsible_match.rs:107:22 | LL | Some(val) => match val { | ______________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:98:14 + --> $DIR/collapsible_match.rs:107:14 | LL | Some(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:263:9 + --> $DIR/collapsible_match.rs:273:9 | LL | / if let Some(u) = a { +LL | | LL | | println!("{u:?}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:262:27 + --> $DIR/collapsible_match.rs:272:27 | LL | if let Issue9647::A { a, .. } = x { | ^ replace this binding @@ -192,15 +207,16 @@ LL | if let Some(u) = a { | ^^^^^^^ with this pattern, prefixed by a: error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:271:9 + --> $DIR/collapsible_match.rs:282:9 | LL | / if let Some(u) = a { +LL | | LL | | println!("{u}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:270:35 + --> $DIR/collapsible_match.rs:281:35 | LL | if let Issue9647::A { a: Some(a), .. } = x { | ^ replace this binding diff --git a/tests/ui/collapsible_match2.rs b/tests/ui/collapsible_match2.rs index c8fb0a39e954c..56801f99e4545 100644 --- a/tests/ui/collapsible_match2.rs +++ b/tests/ui/collapsible_match2.rs @@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> { match res_opt { Ok(val) if make() => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -18,6 +19,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> } match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -49,6 +51,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // deref reference value match Some(&[1]) { Some(s) => match *s { + //~^ ERROR: this `match` can be collapsed into the outer `match` [n] => foo(n), _ => (), }, @@ -58,6 +61,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // ref pattern and deref match Some(&[1]) { Some(ref s) => match s { + //~^ ERROR: this `match` can be collapsed into the outer `match` [n] => foo(n), _ => (), }, diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index 144dbe40a7ad6..f1b7c1417ef71 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match` | LL | Ok(val) if make() => match val { | __________________________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -13,30 +14,33 @@ help: the outer pattern can be modified to include the inner pattern | LL | Ok(val) if make() => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:20:24 + --> $DIR/collapsible_match2.rs:21:24 | LL | Ok(val) => match val { | ________________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:20:16 + --> $DIR/collapsible_match2.rs:21:16 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:34:29 + --> $DIR/collapsible_match2.rs:36:29 | LL | $pat => match $e { | _____________________________^ @@ -49,7 +53,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ------------------------------------------------ in this macro invocation | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:46:28 + --> $DIR/collapsible_match2.rs:48:28 | LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern @@ -58,38 +62,42 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:51:20 + --> $DIR/collapsible_match2.rs:53:20 | LL | Some(s) => match *s { | ____________________^ +LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:51:14 + --> $DIR/collapsible_match2.rs:53:14 | LL | Some(s) => match *s { | ^ replace this binding +LL | LL | [n] => foo(n), | ^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:60:24 + --> $DIR/collapsible_match2.rs:63:24 | LL | Some(ref s) => match s { | ________________________^ +LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:60:14 + --> $DIR/collapsible_match2.rs:63:14 | LL | Some(ref s) => match s { | ^^^^^ replace this binding +LL | LL | [n] => foo(n), | ^^^ with this pattern diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs index f7ba68fd8948e..bd281f7870cee 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -19,6 +19,8 @@ fn no_access_at_all() { fn write_without_read() { // The main use case for `collection_is_never_read`. let mut x = HashMap::new(); + //~^ ERROR: collection is never read + //~| NOTE: `-D clippy::collection-is-never-read` implied by `-D warnings` x.insert(1, 2); } @@ -58,6 +60,7 @@ fn read_in_closure() { fn write_in_closure() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read let _ = || { x.push(4); }; @@ -73,11 +76,13 @@ fn shadowing_1() { let x = HashMap::::new(); // Ok let _ = x.len(); let mut x = HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); } fn shadowing_2() { let mut x = HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); let x = HashMap::::new(); // Ok let _ = x.len(); @@ -86,18 +91,21 @@ fn shadowing_2() { #[allow(clippy::let_unit_value)] fn fake_read_1() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.reverse(); let _: () = x.clear(); } fn fake_read_2() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.reverse(); println!("{:?}", x.push(5)); } fn assignment() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read let y = vec![4, 5, 6]; // Ok x = y; } @@ -105,6 +113,7 @@ fn assignment() { #[allow(clippy::self_assignment)] fn self_assignment() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x = x; } @@ -122,6 +131,7 @@ fn method_argument_but_not_target() { fn insert_is_not_a_read() { let mut x = HashSet::new(); + //~^ ERROR: collection is never read x.insert(5); } @@ -136,6 +146,7 @@ fn not_read_if_return_value_not_used() { // `is_empty` does not modify the set, so it's a query. But since the return value is not used, the // lint does not consider it a read here. let x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.is_empty(); } @@ -171,33 +182,43 @@ fn function_argument() { fn supported_types() { let mut x = std::collections::BTreeMap::new(); + //~^ ERROR: collection is never read x.insert(true, 1); let mut x = std::collections::BTreeSet::new(); + //~^ ERROR: collection is never read x.insert(1); let mut x = std::collections::BinaryHeap::new(); + //~^ ERROR: collection is never read x.push(1); let mut x = std::collections::HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); let mut x = std::collections::HashSet::new(); + //~^ ERROR: collection is never read x.insert(1); let mut x = std::collections::LinkedList::new(); + //~^ ERROR: collection is never read x.push_front(1); let mut x = Some(true); + //~^ ERROR: collection is never read x.insert(false); let mut x = String::from("hello"); + //~^ ERROR: collection is never read x.push('!'); let mut x = Vec::new(); + //~^ ERROR: collection is never read x.clear(); x.push(1); let mut x = std::collections::VecDeque::new(); + //~^ ERROR: collection is never read x.push_front(1); } diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 32ba6b9bc2738..0d3f2fc602f81 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -7,115 +7,115 @@ LL | let mut x = HashMap::new(); = note: `-D clippy::collection-is-never-read` implied by `-D warnings` error: collection is never read - --> $DIR/collection_is_never_read.rs:60:5 + --> $DIR/collection_is_never_read.rs:62:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:75:5 + --> $DIR/collection_is_never_read.rs:78:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:80:5 + --> $DIR/collection_is_never_read.rs:84:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:88:5 + --> $DIR/collection_is_never_read.rs:93:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:94:5 + --> $DIR/collection_is_never_read.rs:100:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:100:5 + --> $DIR/collection_is_never_read.rs:107:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:107:5 + --> $DIR/collection_is_never_read.rs:115:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:124:5 + --> $DIR/collection_is_never_read.rs:133:5 | LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:138:5 + --> $DIR/collection_is_never_read.rs:148:5 | LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:173:5 + --> $DIR/collection_is_never_read.rs:184:5 | LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:176:5 + --> $DIR/collection_is_never_read.rs:188:5 | LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:179:5 + --> $DIR/collection_is_never_read.rs:192:5 | LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:182:5 + --> $DIR/collection_is_never_read.rs:196:5 | LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:185:5 + --> $DIR/collection_is_never_read.rs:200:5 | LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:188:5 + --> $DIR/collection_is_never_read.rs:204:5 | LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:191:5 + --> $DIR/collection_is_never_read.rs:208:5 | LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:194:5 + --> $DIR/collection_is_never_read.rs:212:5 | LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:197:5 + --> $DIR/collection_is_never_read.rs:216:5 | LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:201:5 + --> $DIR/collection_is_never_read.rs:221:5 | LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/comparison_chain.rs b/tests/ui/comparison_chain.rs index c12c6a310275d..266cee4c33890 100644 --- a/tests/ui/comparison_chain.rs +++ b/tests/ui/comparison_chain.rs @@ -12,6 +12,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -25,6 +26,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -33,6 +35,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if y > x { b() @@ -41,6 +44,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > 1 { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < 1 { b() @@ -115,12 +119,14 @@ fn g(x: f64, y: f64, z: f64) { fn h(x: T, y: T, z: T) { if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -129,6 +135,7 @@ fn h(x: T, y: T, z: T) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if y > x { b() diff --git a/tests/ui/comparison_chain.stderr b/tests/ui/comparison_chain.stderr index 2eeb50202cd43..db20b1fbb3b4b 100644 --- a/tests/ui/comparison_chain.stderr +++ b/tests/ui/comparison_chain.stderr @@ -2,6 +2,7 @@ error: `if` chain can be rewritten with `match` --> $DIR/comparison_chain.rs:14:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -12,13 +13,13 @@ LL | | } = note: `-D clippy::comparison-chain` implied by `-D warnings` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:27:5 + --> $DIR/comparison_chain.rs:28:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -26,13 +27,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:35:5 + --> $DIR/comparison_chain.rs:37:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if y > x { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -40,13 +41,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:43:5 + --> $DIR/comparison_chain.rs:46:5 | LL | / if x > 1 { +LL | | LL | | a() LL | | } else if x < 1 { -LL | | b() -LL | | } else if x == 1 { +... | LL | | c() LL | | } | |_____^ @@ -54,9 +55,10 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:117:5 + --> $DIR/comparison_chain.rs:121:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -66,13 +68,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:123:5 + --> $DIR/comparison_chain.rs:128:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -80,13 +82,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:131:5 + --> $DIR/comparison_chain.rs:137:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if y > x { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs index 8e265c9141c16..c0403758f1bb9 100644 --- a/tests/ui/const_comparisons.rs +++ b/tests/ui/const_comparisons.rs @@ -42,52 +42,96 @@ fn main() { status_code >= 400 && status_code < 500; // Correct status_code <= 400 && status_code > 500; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st status_code > 500 && status_code < 400; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` > `400`, the expression evaluates to false for any value of `st status_code < 500 && status_code > 500; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status_code` cannot simultaneously be greater than and less than `500` // More complex expressions status_code < { 400 } && status_code > { 500 }; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status_code` cannot simultaneously be greater than and less than `STATUS_S // Comparing two different types, via the `impl PartialOrd for Status` status < { 400 } && status > { 500 }; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER // Yoda conditions 500 <= status_code && 600 > status_code; // Correct 500 <= status_code && status_code <= 600; // Correct 500 >= status_code && 600 < status_code; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st 500 >= status_code && status_code > 600; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Yoda conditions, comparing two different types 500 <= status && 600 > status; // Correct 500 <= status && status <= 600; // Correct 500 >= status && 600 < status; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st 500 >= status && status > 600; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Expressions where one of the sides has no effect status_code < 200 && status_code <= 299; + //~^ ERROR: right-hand side of `&&` operator has no effect status_code > 200 && status_code >= 299; + //~^ ERROR: left-hand side of `&&` operator has no effect status_code >= 500 && status_code > 500; // Useless left + //~^ ERROR: left-hand side of `&&` operator has no effect status_code > 500 && status_code >= 500; // Useless right + //~^ ERROR: right-hand side of `&&` operator has no effect status_code <= 500 && status_code < 500; // Useless left + //~^ ERROR: left-hand side of `&&` operator has no effect status_code < 500 && status_code <= 500; // Useless right + //~^ ERROR: right-hand side of `&&` operator has no effect // Other types let name = "Steve"; name < "Jennifer" && name > "Shannon"; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any let numbers = [1, 2]; numbers < [3, 4] && numbers > [5, 6]; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value let letter = 'a'; letter < 'b' && letter > 'c'; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `'b'` < `'c'`, the expression evaluates to false for any value of `le let area = 42.0; area < std::f32::consts::E && area > std::f32::consts::PI; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `std::f32::consts::E` < `std::f32::consts::PI`, the expression evalua } diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index 90e6db647621a..e319ce8d17b89 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -8,7 +8,7 @@ LL | status_code <= 400 && status_code > 500; = note: `-D clippy::impossible-comparisons` implied by `-D warnings` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:45:5 + --> $DIR/const_comparisons.rs:47:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | status_code > 500 && status_code < 400; = note: since `500` > `400`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:46:5 + --> $DIR/const_comparisons.rs:50:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | status_code < 500 && status_code > 500; = note: `status_code` cannot simultaneously be greater than and less than `500` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:49:5 + --> $DIR/const_comparisons.rs:55:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | status_code < { 400 } && status_code > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:50:5 + --> $DIR/const_comparisons.rs:58:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:51:5 + --> $DIR/const_comparisons.rs:61:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:52:5 + --> $DIR/const_comparisons.rs:64:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:55:5 + --> $DIR/const_comparisons.rs:69:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | status < { 400 } && status > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:56:5 + --> $DIR/const_comparisons.rs:72:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:57:5 + --> $DIR/const_comparisons.rs:75:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:58:5 + --> $DIR/const_comparisons.rs:78:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:63:5 + --> $DIR/const_comparisons.rs:85:5 | LL | 500 >= status_code && 600 < status_code; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | 500 >= status_code && 600 < status_code; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:64:5 + --> $DIR/const_comparisons.rs:88:5 | LL | 500 >= status_code && status_code > 600; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | 500 >= status_code && status_code > 600; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:69:5 + --> $DIR/const_comparisons.rs:95:5 | LL | 500 >= status && 600 < status; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | 500 >= status && 600 < status; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:70:5 + --> $DIR/const_comparisons.rs:98:5 | LL | 500 >= status && status > 600; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,80 +120,80 @@ LL | 500 >= status && status > 600; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:73:5 + --> $DIR/const_comparisons.rs:103:5 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well - --> $DIR/const_comparisons.rs:73:23 + --> $DIR/const_comparisons.rs:103:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-comparisons` implied by `-D warnings` error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:74:5 + --> $DIR/const_comparisons.rs:105:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well - --> $DIR/const_comparisons.rs:74:5 + --> $DIR/const_comparisons.rs:105:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:76:5 + --> $DIR/const_comparisons.rs:108:5 | LL | status_code >= 500 && status_code > 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:76:5 + --> $DIR/const_comparisons.rs:108:5 | LL | status_code >= 500 && status_code > 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:77:5 + --> $DIR/const_comparisons.rs:110:5 | LL | status_code > 500 && status_code >= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:77:23 + --> $DIR/const_comparisons.rs:110:23 | LL | status_code > 500 && status_code >= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code <= 500 && status_code < 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code <= 500 && status_code < 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:79:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code < 500 && status_code <= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:79:23 + --> $DIR/const_comparisons.rs:114:23 | LL | status_code < 500 && status_code <= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:83:5 + --> $DIR/const_comparisons.rs:119:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +201,7 @@ LL | name < "Jennifer" && name > "Shannon"; = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:86:5 + --> $DIR/const_comparisons.rs:124:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | numbers < [3, 4] && numbers > [5, 6]; = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:89:5 + --> $DIR/const_comparisons.rs:129:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | letter < 'b' && letter > 'c'; = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:92:5 + --> $DIR/const_comparisons.rs:134:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/copy_iterator.rs b/tests/ui/copy_iterator.rs index ae67ebded4374..c0e5fc3e44674 100644 --- a/tests/ui/copy_iterator.rs +++ b/tests/ui/copy_iterator.rs @@ -4,6 +4,8 @@ struct Countdown(u8); impl Iterator for Countdown { + //~^ ERROR: you are implementing `Iterator` on a `Copy` type + //~| NOTE: consider implementing `IntoIterator` instead type Item = u8; fn next(&mut self) -> Option { diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index 6bc6fd6b6fa84..12a329bdc12b6 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -2,9 +2,9 @@ error: you are implementing `Iterator` on a `Copy` type --> $DIR/copy_iterator.rs:6:1 | LL | / impl Iterator for Countdown { -LL | | type Item = u8; LL | | -LL | | fn next(&mut self) -> Option { +LL | | +LL | | type Item = u8; ... | LL | | } LL | | } diff --git a/tests/ui/crashes/ice-10912.rs b/tests/ui/crashes/ice-10912.rs index 02f333070f948..8dfce19422171 100644 --- a/tests/ui/crashes/ice-10912.rs +++ b/tests/ui/crashes/ice-10912.rs @@ -1,4 +1,8 @@ #![warn(clippy::unreadable_literal)] -fn f2() -> impl Sized { && 3.14159265358979323846E } //@no-rustfix +fn f2() -> impl Sized { && 3.14159265358979323846E } +//~^ ERROR: expected at least one digit in exponent +//~| ERROR: long literal lacking separators +//~| NOTE: `-D clippy::unreadable-literal` implied by `-D warnings` + fn main() {} diff --git a/tests/ui/crashes/ice-10912.stderr b/tests/ui/crashes/ice-10912.stderr index a74ce731577d0..0833769feecf1 100644 --- a/tests/ui/crashes/ice-10912.stderr +++ b/tests/ui/crashes/ice-10912.stderr @@ -1,11 +1,11 @@ error: expected at least one digit in exponent - --> $DIR/ice-10912.rs:2:28 + --> $DIR/ice-10912.rs:3:28 | LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> $DIR/ice-10912.rs:2:28 + --> $DIR/ice-10912.rs:3:28 | LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46` diff --git a/tests/ui/crashes/ice-2774.fixed b/tests/ui/crashes/ice-2774.fixed index d71b8fcad1f5b..96cf0d8540cd9 100644 --- a/tests/ui/crashes/ice-2774.fixed +++ b/tests/ui/crashes/ice-2774.fixed @@ -13,6 +13,8 @@ pub struct Foo; #[allow(clippy::implicit_hasher)] // This should not cause a "cannot relate bound region" ICE. pub fn add_barfoos_to_foos(bars: &HashSet<&Bar>) { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` let mut foos = HashSet::new(); foos.extend(bars.iter().map(|b| &b.foo)); } diff --git a/tests/ui/crashes/ice-2774.rs b/tests/ui/crashes/ice-2774.rs index 88cfa1f923c0b..464d7891c9f49 100644 --- a/tests/ui/crashes/ice-2774.rs +++ b/tests/ui/crashes/ice-2774.rs @@ -13,6 +13,8 @@ pub struct Foo; #[allow(clippy::implicit_hasher)] // This should not cause a "cannot relate bound region" ICE. pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` let mut foos = HashSet::new(); foos.extend(bars.iter().map(|b| &b.foo)); } diff --git a/tests/ui/crashes/ice-360.rs b/tests/ui/crashes/ice-360.rs index 2649674667be7..28589e1efeda5 100644 --- a/tests/ui/crashes/ice-360.rs +++ b/tests/ui/crashes/ice-360.rs @@ -3,10 +3,13 @@ fn main() {} fn no_panic(slice: &[T]) { let mut iter = slice.iter(); loop { + //~^ ERROR: this loop could be written as a `while let` loop + //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` let _ = match iter.next() { Some(ele) => ele, None => break, }; loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } } diff --git a/tests/ui/crashes/ice-360.stderr b/tests/ui/crashes/ice-360.stderr index a2e2ab8fd192f..292b27dd934ed 100644 --- a/tests/ui/crashes/ice-360.stderr +++ b/tests/ui/crashes/ice-360.stderr @@ -2,18 +2,18 @@ error: this loop could be written as a `while let` loop --> $DIR/ice-360.rs:5:5 | LL | / loop { +LL | | +LL | | LL | | let _ = match iter.next() { -LL | | Some(ele) => ele, -LL | | None => break, -LL | | }; -LL | | loop {} +... | +LL | | LL | | } | |_____^ help: try: `while let Some(ele) = iter.next() { .. }` | = note: `-D clippy::while-let-loop` implied by `-D warnings` error: empty `loop {}` wastes CPU cycles - --> $DIR/ice-360.rs:10:9 + --> $DIR/ice-360.rs:12:9 | LL | loop {} | ^^^^^^^ diff --git a/tests/ui/crashes/ice-3717.fixed b/tests/ui/crashes/ice-3717.fixed index f48273e796a64..3f54b326979c9 100644 --- a/tests/ui/crashes/ice-3717.fixed +++ b/tests/ui/crashes/ice-3717.fixed @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { + //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers let _ = [0u8; 0]; let _: HashSet = HashSet::default(); } diff --git a/tests/ui/crashes/ice-3717.rs b/tests/ui/crashes/ice-3717.rs index f50714643fd25..2890a9277c719 100644 --- a/tests/ui/crashes/ice-3717.rs +++ b/tests/ui/crashes/ice-3717.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { + //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers let _ = [0u8; 0]; let _: HashSet = HashSet::new(); } diff --git a/tests/ui/crashes/ice-3891.rs b/tests/ui/crashes/ice-3891.rs index 05c5134c8457b..a3f1ccad71ae6 100644 --- a/tests/ui/crashes/ice-3891.rs +++ b/tests/ui/crashes/ice-3891.rs @@ -1,3 +1,4 @@ fn main() { 1x; + //~^ ERROR: invalid suffix `x` for number literal } diff --git a/tests/ui/crashes/ice-3969.rs b/tests/ui/crashes/ice-3969.rs index 9b68cac7ff485..d5676cbd91d19 100644 --- a/tests/ui/crashes/ice-3969.rs +++ b/tests/ui/crashes/ice-3969.rs @@ -18,10 +18,13 @@ struct Dst { struct TwoStrs(str, str) where str: Sized; +//~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim +//~| NOTE: `-D trivial-bounds` implied by `-D warnings` fn unsized_local() where for<'a> Dst: Sized, + //~^ ERROR: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend { let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); } @@ -29,6 +32,7 @@ where fn return_str() -> str where str: Sized, + //~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim { *"Sized".to_string().into_boxed_str() } @@ -36,6 +40,7 @@ where fn use_op(s: String) -> String where String: ::std::ops::Neg, + //~^ ERROR: trait bound std::string::String: std::ops::Neg does not depend on any type { -s } @@ -43,6 +48,7 @@ where fn use_for() where i32: Iterator, + //~^ ERROR: trait bound i32: std::iter::Iterator does not depend on any type or lifeti { for _ in 2i32 {} } diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index 79018080886c0..bc10555693ca8 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -7,25 +7,25 @@ LL | str: Sized; = note: `-D trivial-bounds` implied by `-D warnings` error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:24:30 + --> $DIR/ice-3969.rs:26:30 | LL | for<'a> Dst: Sized, | ^^^^^ error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:31:10 + --> $DIR/ice-3969.rs:34:10 | LL | str: Sized, | ^^^^^ error: trait bound std::string::String: std::ops::Neg does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:38:13 + --> $DIR/ice-3969.rs:42:13 | LL | String: ::std::ops::Neg, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: trait bound i32: std::iter::Iterator does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:45:10 + --> $DIR/ice-3969.rs:50:10 | LL | i32: Iterator, | ^^^^^^^^ diff --git a/tests/ui/crashes/ice-5835.fixed b/tests/ui/crashes/ice-5835.fixed index c11f68e85ca1e..c0532d685786d 100644 --- a/tests/ui/crashes/ice-5835.fixed +++ b/tests/ui/crashes/ice-5835.fixed @@ -1,6 +1,8 @@ #[rustfmt::skip] pub struct Foo { /// 位 + //~^ ERROR: using tabs in doc comments is not recommended + //~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/tests/ui/crashes/ice-5835.rs b/tests/ui/crashes/ice-5835.rs index 5e99cb432b6e2..122bddd6ae679 100644 --- a/tests/ui/crashes/ice-5835.rs +++ b/tests/ui/crashes/ice-5835.rs @@ -1,6 +1,8 @@ #[rustfmt::skip] pub struct Foo { /// 位 + //~^ ERROR: using tabs in doc comments is not recommended + //~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/tests/ui/crashes/ice-5872.fixed b/tests/ui/crashes/ice-5872.fixed index b009b2323ba62..c8e870c62fbfb 100644 --- a/tests/ui/crashes/ice-5872.fixed +++ b/tests/ui/crashes/ice-5872.fixed @@ -2,4 +2,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter().next().is_none(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-5872.rs b/tests/ui/crashes/ice-5872.rs index 68afa8f8c3a84..c6ed313658922 100644 --- a/tests/ui/crashes/ice-5872.rs +++ b/tests/ui/crashes/ice-5872.rs @@ -2,4 +2,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-6254.rs b/tests/ui/crashes/ice-6254.rs index 8af60890390e7..2ae426cf789de 100644 --- a/tests/ui/crashes/ice-6254.rs +++ b/tests/ui/crashes/ice-6254.rs @@ -11,6 +11,8 @@ fn main() { // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071) match FOO_REF_REF { FOO_REF_REF => {}, + //~^ ERROR: to use a constant of type `Foo` in a pattern, `Foo` must be annotated + //~| NOTE: for more information, see issue #62411 {}, } } diff --git a/tests/ui/crashes/ice-7169.fixed b/tests/ui/crashes/ice-7169.fixed index 91cfbb38b77af..cf4077e4d8982 100644 --- a/tests/ui/crashes/ice-7169.fixed +++ b/tests/ui/crashes/ice-7169.fixed @@ -8,4 +8,6 @@ struct A { fn main() { if Ok::<_, ()>(A::::default()).is_ok() {} + //~^ ERROR: redundant pattern matching, consider using `is_ok()` + //~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-7169.rs b/tests/ui/crashes/ice-7169.rs index b203252f0a14a..b09e6f3846327 100644 --- a/tests/ui/crashes/ice-7169.rs +++ b/tests/ui/crashes/ice-7169.rs @@ -8,4 +8,6 @@ struct A { fn main() { if let Ok(_) = Ok::<_, ()>(A::::default()) {} + //~^ ERROR: redundant pattern matching, consider using `is_ok()` + //~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-7869.rs b/tests/ui/crashes/ice-7869.rs index 8f97a063a9a9f..774e22f6b4c59 100644 --- a/tests/ui/crashes/ice-7869.rs +++ b/tests/ui/crashes/ice-7869.rs @@ -1,4 +1,5 @@ enum Tila { + //~^ ERROR: all variants have the same prefix: `Työ` TyöAlkoi, TyöKeskeytyi, TyöValmis, diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 35d1e8fd29573..61fc8a4817a7d 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -2,6 +2,7 @@ error: all variants have the same prefix: `Työ` --> $DIR/ice-7869.rs:1:1 | LL | / enum Tila { +LL | | LL | | TyöAlkoi, LL | | TyöKeskeytyi, LL | | TyöValmis, diff --git a/tests/ui/crashes/ice-8250.fixed b/tests/ui/crashes/ice-8250.fixed index 478b3b49270f0..984b61258c781 100644 --- a/tests/ui/crashes/ice-8250.fixed +++ b/tests/ui/crashes/ice-8250.fixed @@ -1,5 +1,7 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].split('.').next()?; + //~^ ERROR: unnecessary use of `splitn` + //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` Some(()) } diff --git a/tests/ui/crashes/ice-8250.rs b/tests/ui/crashes/ice-8250.rs index d9a5ee1162a49..c1b2e48ba3c06 100644 --- a/tests/ui/crashes/ice-8250.rs +++ b/tests/ui/crashes/ice-8250.rs @@ -1,5 +1,7 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].splitn(2, '.').next()?; + //~^ ERROR: unnecessary use of `splitn` + //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` Some(()) } diff --git a/tests/ui/crashes/ice-8821.fixed b/tests/ui/crashes/ice-8821.fixed index df297eea056ad..a25bb46f9ff7b 100644 --- a/tests/ui/crashes/ice-8821.fixed +++ b/tests/ui/crashes/ice-8821.fixed @@ -5,4 +5,6 @@ static FN: fn() = f; fn main() { FN(); + //~^ ERROR: this let-binding has unit value + //~| NOTE: `-D clippy::let-unit-value` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-8821.rs b/tests/ui/crashes/ice-8821.rs index fb87b79aeed87..082f7c92646a6 100644 --- a/tests/ui/crashes/ice-8821.rs +++ b/tests/ui/crashes/ice-8821.rs @@ -5,4 +5,6 @@ static FN: fn() = f; fn main() { let _: () = FN(); + //~^ ERROR: this let-binding has unit value + //~| NOTE: `-D clippy::let-unit-value` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-8850.fixed b/tests/ui/crashes/ice-8850.fixed index 2a5b4110c2441..4569b9e8793e2 100644 --- a/tests/ui/crashes/ice-8850.fixed +++ b/tests/ui/crashes/ice-8850.fixed @@ -2,12 +2,15 @@ fn fn_pointer_static() -> usize { static FN: fn() -> usize = || 1; FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn fn_pointer_const() -> usize { const FN: fn() -> usize = || 1; FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block } fn deref_to_dyn_fn() -> usize { @@ -22,6 +25,7 @@ fn deref_to_dyn_fn() -> usize { static FN: Derefs = Derefs; FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block } fn main() {} diff --git a/tests/ui/crashes/ice-8850.rs b/tests/ui/crashes/ice-8850.rs index f2747ab2239a6..499756ecefe98 100644 --- a/tests/ui/crashes/ice-8850.rs +++ b/tests/ui/crashes/ice-8850.rs @@ -2,12 +2,15 @@ fn fn_pointer_static() -> usize { static FN: fn() -> usize = || 1; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn fn_pointer_const() -> usize { const FN: fn() -> usize = || 1; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block } fn deref_to_dyn_fn() -> usize { @@ -22,6 +25,7 @@ fn deref_to_dyn_fn() -> usize { static FN: Derefs = Derefs; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block } fn main() {} diff --git a/tests/ui/crashes/ice-8850.stderr b/tests/ui/crashes/ice-8850.stderr index 620fd1edaf790..41da3f715ae37 100644 --- a/tests/ui/crashes/ice-8850.stderr +++ b/tests/ui/crashes/ice-8850.stderr @@ -14,7 +14,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> $DIR/ice-8850.rs:10:5 + --> $DIR/ice-8850.rs:12:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding @@ -28,7 +28,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> $DIR/ice-8850.rs:24:5 + --> $DIR/ice-8850.rs:27:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding diff --git a/tests/ui/crashes/ice-9041.rs b/tests/ui/crashes/ice-9041.rs index 9adc30c680b6a..727d88f7fbd26 100644 --- a/tests/ui/crashes/ice-9041.rs +++ b/tests/ui/crashes/ice-9041.rs @@ -3,6 +3,8 @@ pub struct Thing; pub fn has_thing(things: &[Thing]) -> bool { let is_thing_ready = |_peer: &Thing| -> bool { todo!() }; things.iter().find(|p| is_thing_ready(p)).is_some() + //~^ ERROR: called `is_some()` after searching an `Iterator` with `find` + //~| NOTE: `-D clippy::search-is-some` implied by `-D warnings` } fn main() {} diff --git a/tests/ui/crashes/ice-9445.rs b/tests/ui/crashes/ice-9445.rs index c67b22f6f8c47..b6afbd33c79fb 100644 --- a/tests/ui/crashes/ice-9445.rs +++ b/tests/ui/crashes/ice-9445.rs @@ -1,3 +1,5 @@ const UNINIT: core::mem::MaybeUninit> = core::mem::MaybeUninit::uninit(); +//~^ ERROR: a `const` item should never be interior mutable +//~| NOTE: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` fn main() {} diff --git a/tests/ui/crashes/ice-9463.rs b/tests/ui/crashes/ice-9463.rs index 9564e77c24b1c..fa83d25b3942d 100644 --- a/tests/ui/crashes/ice-9463.rs +++ b/tests/ui/crashes/ice-9463.rs @@ -1,5 +1,9 @@ #![deny(arithmetic_overflow)] fn main() { let _x = -1_i32 >> -1; + //~^ ERROR: this arithmetic operation will overflow let _y = 1u32 >> 10000000000000u32; + //~^ ERROR: this arithmetic operation will overflow + //~| ERROR: literal out of range for `u32` + //~| NOTE: the literal `10000000000000u32` does not fit into the type `u32` whose rang } diff --git a/tests/ui/crashes/ice-9463.stderr b/tests/ui/crashes/ice-9463.stderr index 2b425e85a27b5..911795694c38e 100644 --- a/tests/ui/crashes/ice-9463.stderr +++ b/tests/ui/crashes/ice-9463.stderr @@ -11,13 +11,13 @@ LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow - --> $DIR/ice-9463.rs:4:14 + --> $DIR/ice-9463.rs:5:14 | LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift right by `1316134912_u32`, which would overflow error: literal out of range for `u32` - --> $DIR/ice-9463.rs:4:22 + --> $DIR/ice-9463.rs:5:22 | LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed index 7b4def818152c..8bd9eea75bb26 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -13,6 +13,7 @@ impl<'a> Foo for Baz<'a> {} impl Bar { fn baz(&self) -> impl Foo + '_ { + //~^ ERROR: the following explicit lifetimes could be elided: 'a Baz { bar: self } } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/needless_lifetimes_impl_trait.rs index 376ff97ba6036..06947e3a3513d 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -13,6 +13,7 @@ impl<'a> Foo for Baz<'a> {} impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { + //~^ ERROR: the following explicit lifetimes could be elided: 'a Baz { bar: self } } } diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed b/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed index 517f9cdd42ccc..774dea3919396 100644 --- a/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed @@ -5,5 +5,6 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: &Foo<'_>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn main() {} diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs b/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs index dd3d8b8b6d156..f3d8871929a22 100644 --- a/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs @@ -5,5 +5,6 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: Foo<'_>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn main() {} diff --git a/tests/ui/crate_level_checks/no_std_swap.rs b/tests/ui/crate_level_checks/no_std_swap.rs index d3571eaf0d7be..8ed45a3346550 100644 --- a/tests/ui/crate_level_checks/no_std_swap.rs +++ b/tests/ui/crate_level_checks/no_std_swap.rs @@ -10,5 +10,7 @@ fn main() { let mut b = 1337; a = b; + //~^ ERROR: this looks like you are trying to swap `a` and `b` + //~| NOTE: or maybe you should use `core::mem::replace`? b = a; } diff --git a/tests/ui/crate_level_checks/no_std_swap.stderr b/tests/ui/crate_level_checks/no_std_swap.stderr index 7d8ea3f76b0f6..9258c828aafc6 100644 --- a/tests/ui/crate_level_checks/no_std_swap.stderr +++ b/tests/ui/crate_level_checks/no_std_swap.stderr @@ -2,6 +2,8 @@ error: this looks like you are trying to swap `a` and `b` --> $DIR/no_std_swap.rs:12:5 | LL | / a = b; +LL | | +LL | | LL | | b = a; | |_________^ help: try: `core::mem::swap(&mut a, &mut b)` | diff --git a/tests/ui/crate_level_checks/std_main_recursion.rs b/tests/ui/crate_level_checks/std_main_recursion.rs index 89ff6609934d2..c2c3e0958ec78 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.rs +++ b/tests/ui/crate_level_checks/std_main_recursion.rs @@ -3,4 +3,5 @@ fn main() { println!("Hello, World!"); main(); + //~^ ERROR: recursing into entrypoint `main` } diff --git a/tests/ui/dbg_macro.rs b/tests/ui/dbg_macro.rs index acbd463162ff2..149b08476192c 100644 --- a/tests/ui/dbg_macro.rs +++ b/tests/ui/dbg_macro.rs @@ -4,23 +4,33 @@ fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~| NOTE: `-D clippy::dbg-macro` implied by `-D warnings` } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if dbg!(n <= 1) { + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } else { dbg!(n * factorial(n - 1)) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } fn main() { dbg!(42); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(dbg!(dbg!(42))); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo(3) + dbg!(factorial(4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, dbg!(3, 4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, 3, 4, 5); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } fn issue9914() { @@ -41,11 +51,16 @@ fn issue9914() { } dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool #[allow(clippy::let_unit_value)] let _ = dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool bar(dbg!()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo!(dbg!()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo2!(foo!(dbg!())); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool expand_to_dbg!(); } @@ -67,22 +82,26 @@ mod issue7274 { struct MyThing; define_thing!(MyThing, { dbg!(2); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool }); } #[test] pub fn issue8481() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } #[cfg(test)] fn foo2() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } #[cfg(test)] mod mod1 { fn func() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr index aa58fb09aff15..e63d07a5f2472 100644 --- a/tests/ui/dbg_macro.stderr +++ b/tests/ui/dbg_macro.stderr @@ -11,7 +11,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:11:8 + --> $DIR/dbg_macro.rs:13:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:12:9 + --> $DIR/dbg_macro.rs:15:9 | LL | dbg!(1) | ^^^^^^^ @@ -33,7 +33,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:14:9 + --> $DIR/dbg_macro.rs:18:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:19:5 + --> $DIR/dbg_macro.rs:24:5 | LL | dbg!(42); | ^^^^^^^^ @@ -55,7 +55,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:20:5 + --> $DIR/dbg_macro.rs:26:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:21:14 + --> $DIR/dbg_macro.rs:28:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:22:5 + --> $DIR/dbg_macro.rs:30:5 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | (1, 2, dbg!(3, 4)); | ~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:23:5 + --> $DIR/dbg_macro.rs:32:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:43:5 + --> $DIR/dbg_macro.rs:53:5 | LL | dbg!(); | ^^^^^^^ @@ -111,7 +111,7 @@ LL + | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:45:13 + --> $DIR/dbg_macro.rs:56:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:46:9 + --> $DIR/dbg_macro.rs:58:9 | LL | bar(dbg!()); | ^^^^^^ @@ -133,7 +133,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:47:10 + --> $DIR/dbg_macro.rs:60:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -144,7 +144,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:48:16 + --> $DIR/dbg_macro.rs:62:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -155,7 +155,7 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:69:9 + --> $DIR/dbg_macro.rs:84:9 | LL | dbg!(2); | ^^^^^^^ @@ -166,7 +166,7 @@ LL | 2; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:75:5 + --> $DIR/dbg_macro.rs:91:5 | LL | dbg!(1); | ^^^^^^^ @@ -177,7 +177,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:80:5 + --> $DIR/dbg_macro.rs:97:5 | LL | dbg!(1); | ^^^^^^^ @@ -188,7 +188,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:86:9 + --> $DIR/dbg_macro.rs:104:9 | LL | dbg!(1); | ^^^^^^^ diff --git a/tests/ui/debug_assert_with_mut_call.rs b/tests/ui/debug_assert_with_mut_call.rs index 46faa0a7b9117..8d04be777c7b8 100644 --- a/tests/ui/debug_assert_with_mut_call.rs +++ b/tests/ui/debug_assert_with_mut_call.rs @@ -40,13 +40,20 @@ fn func_non_mutable() { fn func_mutable() { debug_assert!(bool_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~| NOTE: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` debug_assert!(!bool_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert_eq!(0, u32_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(u32_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(1, u32_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(u32_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` } fn method_non_mutable() { @@ -62,20 +69,33 @@ fn method_non_mutable() { fn method_mutable() { debug_assert!(S.bool_self_mut()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(!S.bool_self_mut()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_mut_arg_ref(&3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert_eq!(S.u32_self_mut(), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(S.u32_self_mut(), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` } fn misc() { @@ -84,27 +104,35 @@ fn misc() { debug_assert_eq!(v.get(0), Some(&1)); debug_assert_ne!(v[0], 2); debug_assert_eq!(v.pop(), Some(1)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(Some(3), v.pop()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` let a = &mut 3; debug_assert!(bool_mut(a)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // nested debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // chained debug_assert_eq!(v.pop().unwrap(), 3); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` // format args debug_assert!(bool_ref(&3), "w/o format"); debug_assert!(bool_mut(&mut 3), "w/o format"); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(bool_ref(&3), "{} format", "w/"); debug_assert!(bool_mut(&mut 3), "{} format", "w/"); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // sub block let mut x = 42_u32; debug_assert!({ bool_mut(&mut x); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert! x > 10 }); @@ -112,6 +140,7 @@ fn misc() { debug_assert!((|| { let mut x = 42; bool_mut(&mut x); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert! x > 10 })()); } diff --git a/tests/ui/debug_assert_with_mut_call.stderr b/tests/ui/debug_assert_with_mut_call.stderr index a2ca71b57a6fd..97c47064a3353 100644 --- a/tests/ui/debug_assert_with_mut_call.stderr +++ b/tests/ui/debug_assert_with_mut_call.stderr @@ -7,163 +7,163 @@ LL | debug_assert!(bool_mut(&mut 3)); = note: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:43:20 + --> $DIR/debug_assert_with_mut_call.rs:45:20 | LL | debug_assert!(!bool_mut(&mut 3)); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:45:25 + --> $DIR/debug_assert_with_mut_call.rs:48:25 | LL | debug_assert_eq!(0, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:46:22 + --> $DIR/debug_assert_with_mut_call.rs:50:22 | LL | debug_assert_eq!(u32_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:48:25 + --> $DIR/debug_assert_with_mut_call.rs:53:25 | LL | debug_assert_ne!(1, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:49:22 + --> $DIR/debug_assert_with_mut_call.rs:55:22 | LL | debug_assert_ne!(u32_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:64:19 + --> $DIR/debug_assert_with_mut_call.rs:71:19 | LL | debug_assert!(S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:65:20 + --> $DIR/debug_assert_with_mut_call.rs:73:20 | LL | debug_assert!(!S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:66:19 + --> $DIR/debug_assert_with_mut_call.rs:75:19 | LL | debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:67:19 + --> $DIR/debug_assert_with_mut_call.rs:77:19 | LL | debug_assert!(S.bool_self_mut_arg_ref(&3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:68:19 + --> $DIR/debug_assert_with_mut_call.rs:79:19 | LL | debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:70:22 + --> $DIR/debug_assert_with_mut_call.rs:82:22 | LL | debug_assert_eq!(S.u32_self_mut(), 0); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:71:22 + --> $DIR/debug_assert_with_mut_call.rs:84:22 | LL | debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:72:22 + --> $DIR/debug_assert_with_mut_call.rs:86:22 | LL | debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:73:22 + --> $DIR/debug_assert_with_mut_call.rs:88:22 | LL | debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:75:22 + --> $DIR/debug_assert_with_mut_call.rs:91:22 | LL | debug_assert_ne!(S.u32_self_mut(), 1); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:76:22 + --> $DIR/debug_assert_with_mut_call.rs:93:22 | LL | debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:77:22 + --> $DIR/debug_assert_with_mut_call.rs:95:22 | LL | debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:78:22 + --> $DIR/debug_assert_with_mut_call.rs:97:22 | LL | debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:86:22 + --> $DIR/debug_assert_with_mut_call.rs:106:22 | LL | debug_assert_eq!(v.pop(), Some(1)); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:87:31 + --> $DIR/debug_assert_with_mut_call.rs:108:31 | LL | debug_assert_ne!(Some(3), v.pop()); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:90:19 + --> $DIR/debug_assert_with_mut_call.rs:112:19 | LL | debug_assert!(bool_mut(a)); | ^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:93:31 + --> $DIR/debug_assert_with_mut_call.rs:116:31 | LL | debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:96:22 + --> $DIR/debug_assert_with_mut_call.rs:120:22 | LL | debug_assert_eq!(v.pop().unwrap(), 3); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:100:19 + --> $DIR/debug_assert_with_mut_call.rs:125:19 | LL | debug_assert!(bool_mut(&mut 3), "w/o format"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:102:19 + --> $DIR/debug_assert_with_mut_call.rs:128:19 | LL | debug_assert!(bool_mut(&mut 3), "{} format", "w/"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:107:9 + --> $DIR/debug_assert_with_mut_call.rs:134:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:114:9 + --> $DIR/debug_assert_with_mut_call.rs:142:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs index da0816830b85f..190d636ebf34a 100644 --- a/tests/ui/def_id_nocore.rs +++ b/tests/ui/def_id_nocore.rs @@ -25,6 +25,7 @@ struct A; impl A { pub fn as_ref(self) -> &'static str { + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl "A" } } diff --git a/tests/ui/default_union_representation.rs b/tests/ui/default_union_representation.rs index 93b2d33da2cd2..41308b077bac6 100644 --- a/tests/ui/default_union_representation.rs +++ b/tests/ui/default_union_representation.rs @@ -2,6 +2,7 @@ #![warn(clippy::default_union_representation)] union NoAttribute { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -14,6 +15,7 @@ union ReprC { #[repr(packed)] union ReprPacked { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -32,6 +34,7 @@ union ReprCAlign { #[repr(align(32))] union ReprAlign { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -52,6 +55,7 @@ union ZSTsAndField2 { f3: (), } union ZSTAndTwoFields { + //~^ ERROR: this union has the default representation f0: u32, f1: u64, f2: (), diff --git a/tests/ui/default_union_representation.stderr b/tests/ui/default_union_representation.stderr index 8b7ed94cbc611..256eebc44200a 100644 --- a/tests/ui/default_union_representation.stderr +++ b/tests/ui/default_union_representation.stderr @@ -2,6 +2,7 @@ error: this union has the default representation --> $DIR/default_union_representation.rs:4:1 | LL | / union NoAttribute { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -11,9 +12,10 @@ LL | | } = note: `-D clippy::default-union-representation` implied by `-D warnings` error: this union has the default representation - --> $DIR/default_union_representation.rs:16:1 + --> $DIR/default_union_representation.rs:17:1 | LL | / union ReprPacked { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -22,9 +24,10 @@ LL | | } = help: consider annotating `ReprPacked` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> $DIR/default_union_representation.rs:34:1 + --> $DIR/default_union_representation.rs:36:1 | LL | / union ReprAlign { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -33,9 +36,10 @@ LL | | } = help: consider annotating `ReprAlign` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> $DIR/default_union_representation.rs:54:1 + --> $DIR/default_union_representation.rs:57:1 | LL | / union ZSTAndTwoFields { +LL | | LL | | f0: u32, LL | | f1: u64, LL | | f2: (), diff --git a/tests/ui/deprecated_old.rs b/tests/ui/deprecated_old.rs index e89dca4fcfd4c..356ad5f060b6c 100644 --- a/tests/ui/deprecated_old.rs +++ b/tests/ui/deprecated_old.rs @@ -1,5 +1,9 @@ #[warn(unstable_as_slice)] +//~^ ERROR: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized +//~| NOTE: `-D renamed-and-removed-lints` implied by `-D warnings` #[warn(unstable_as_mut_slice)] +//~^ ERROR: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been st #[warn(misaligned_transmute)] +//~^ ERROR: lint `misaligned_transmute` has been removed: this lint has been split into ca fn main() {} diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr index 8043ab0058a5e..5a6c4be80b246 100644 --- a/tests/ui/deprecated_old.stderr +++ b/tests/ui/deprecated_old.stderr @@ -7,13 +7,13 @@ LL | #[warn(unstable_as_slice)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 - --> $DIR/deprecated_old.rs:2:8 + --> $DIR/deprecated_old.rs:4:8 | LL | #[warn(unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^ error: lint `misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr - --> $DIR/deprecated_old.rs:3:8 + --> $DIR/deprecated_old.rs:6:8 | LL | #[warn(misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs index 190ca5cc0a242..32582a3a8bfa3 100644 --- a/tests/ui/deref_addrof_double_trigger.rs +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -8,10 +8,13 @@ fn main() { //This produces a suggestion of 'let b = *&a;' which //will trigger the 'clippy::deref_addrof' lint again let b = **&&a; + //~^ ERROR: immediately dereferencing a reference + //~| NOTE: `-D clippy::deref-addrof` implied by `-D warnings` { let mut x = 10; let y = *&mut x; + //~^ ERROR: immediately dereferencing a reference } { @@ -19,5 +22,6 @@ fn main() { //will trigger the 'clippy::deref_addrof' lint again let mut x = 10; let y = **&mut &mut x; + //~^ ERROR: immediately dereferencing a reference } } diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr index 6fa5069b6b4bd..3463f0a1ab73e 100644 --- a/tests/ui/deref_addrof_double_trigger.stderr +++ b/tests/ui/deref_addrof_double_trigger.stderr @@ -7,13 +7,13 @@ LL | let b = **&&a; = note: `-D clippy::deref-addrof` implied by `-D warnings` error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:14:17 + --> $DIR/deref_addrof_double_trigger.rs:16:17 | LL | let y = *&mut x; | ^^^^^^^ help: try: `x` error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:21:18 + --> $DIR/deref_addrof_double_trigger.rs:24:18 | LL | let y = **&mut &mut x; | ^^^^^^^^^^^^ help: try: `&mut x` diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index ff4dcbfa2f2d9..07df50f4661ae 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -9,6 +9,7 @@ struct Qux; impl Clone for Qux { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { Qux } @@ -33,6 +34,7 @@ struct Lt<'a> { } impl<'a> Clone for Lt<'a> { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -44,6 +46,7 @@ struct BigArray { } impl Clone for BigArray { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -55,6 +58,7 @@ struct FnPtr { } impl Clone for FnPtr { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -75,6 +79,7 @@ impl Clone for Generic { #[derive(Copy)] struct Generic2(T); impl Clone for Generic2 { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { Self(self.0.clone()) } diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index f7948e044b7e3..cf8e90cd844e6 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -2,6 +2,7 @@ error: you are implementing `Clone` explicitly on a `Copy` type --> $DIR/derive.rs:11:1 | LL | / impl Clone for Qux { +LL | | LL | | fn clone(&self) -> Self { LL | | Qux LL | | } @@ -12,6 +13,7 @@ note: consider deriving `Clone` or removing `Copy` --> $DIR/derive.rs:11:1 | LL | / impl Clone for Qux { +LL | | LL | | fn clone(&self) -> Self { LL | | Qux LL | | } @@ -20,9 +22,10 @@ LL | | } = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:35:1 + --> $DIR/derive.rs:36:1 | LL | / impl<'a> Clone for Lt<'a> { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -30,9 +33,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:35:1 + --> $DIR/derive.rs:36:1 | LL | / impl<'a> Clone for Lt<'a> { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -40,9 +44,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:46:1 + --> $DIR/derive.rs:48:1 | LL | / impl Clone for BigArray { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -50,9 +55,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:46:1 + --> $DIR/derive.rs:48:1 | LL | / impl Clone for BigArray { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -60,9 +66,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:57:1 + --> $DIR/derive.rs:60:1 | LL | / impl Clone for FnPtr { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -70,9 +77,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:57:1 + --> $DIR/derive.rs:60:1 | LL | / impl Clone for FnPtr { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -80,9 +88,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:77:1 + --> $DIR/derive.rs:81:1 | LL | / impl Clone for Generic2 { +LL | | LL | | fn clone(&self) -> Self { LL | | Self(self.0.clone()) LL | | } @@ -90,9 +99,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:77:1 + --> $DIR/derive.rs:81:1 | LL | / impl Clone for Generic2 { +LL | | LL | | fn clone(&self) -> Self { LL | | Self(self.0.clone()) LL | | } diff --git a/tests/ui/derive_ord_xor_partial_ord.rs b/tests/ui/derive_ord_xor_partial_ord.rs index 1fb3d51c46dc7..2c19942d420c9 100644 --- a/tests/ui/derive_ord_xor_partial_ord.rs +++ b/tests/ui/derive_ord_xor_partial_ord.rs @@ -20,6 +20,7 @@ impl PartialOrd for DeriveBoth { } #[derive(Ord, PartialEq, Eq)] +//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly struct DeriveOrd; impl PartialOrd for DeriveOrd { @@ -29,6 +30,7 @@ impl PartialOrd for DeriveOrd { } #[derive(Ord, PartialEq, Eq)] +//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly struct DeriveOrdWithExplicitTypeVariable; impl PartialOrd for DeriveOrdWithExplicitTypeVariable { @@ -41,6 +43,7 @@ impl PartialOrd for DeriveOrdWithExplicitType struct DerivePartialOrd; impl std::cmp::Ord for DerivePartialOrd { + //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } @@ -61,6 +64,7 @@ mod use_ord { struct DerivePartialOrdInUseOrd; impl Ord for DerivePartialOrdInUseOrd { + //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr index bd14883481404..ee900c5ea2762 100644 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -5,7 +5,7 @@ LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:25:1 + --> $DIR/derive_ord_xor_partial_ord.rs:26:1 | LL | impl PartialOrd for DeriveOrd { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,22 +13,23 @@ LL | impl PartialOrd for DeriveOrd { = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly - --> $DIR/derive_ord_xor_partial_ord.rs:31:10 + --> $DIR/derive_ord_xor_partial_ord.rs:32:10 | LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:34:1 + --> $DIR/derive_ord_xor_partial_ord.rs:36:1 | LL | impl PartialOrd for DeriveOrdWithExplicitTypeVariable { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:43:1 + --> $DIR/derive_ord_xor_partial_ord.rs:45:1 | LL | / impl std::cmp::Ord for DerivePartialOrd { +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { LL | | Ordering::Less LL | | } @@ -36,16 +37,17 @@ LL | | } | |_^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:40:10 + --> $DIR/derive_ord_xor_partial_ord.rs:42:10 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:63:5 + --> $DIR/derive_ord_xor_partial_ord.rs:66:5 | LL | / impl Ord for DerivePartialOrdInUseOrd { +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { LL | | Ordering::Less LL | | } @@ -53,7 +55,7 @@ LL | | } | |_____^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:60:14 + --> $DIR/derive_ord_xor_partial_ord.rs:63:14 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ diff --git a/tests/ui/derived_hash_with_manual_eq.rs b/tests/ui/derived_hash_with_manual_eq.rs index 8ad09a8de43d5..8423699d99ed8 100644 --- a/tests/ui/derived_hash_with_manual_eq.rs +++ b/tests/ui/derived_hash_with_manual_eq.rs @@ -10,6 +10,7 @@ impl PartialEq for Foo { } #[derive(Hash)] +//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly struct Bar; impl PartialEq for Bar { @@ -19,6 +20,7 @@ impl PartialEq for Bar { } #[derive(Hash)] +//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly struct Baz; impl PartialEq for Baz { diff --git a/tests/ui/derived_hash_with_manual_eq.stderr b/tests/ui/derived_hash_with_manual_eq.stderr index 230940f25fb60..8ef08f9fa5cbb 100644 --- a/tests/ui/derived_hash_with_manual_eq.stderr +++ b/tests/ui/derived_hash_with_manual_eq.stderr @@ -5,7 +5,7 @@ LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> $DIR/derived_hash_with_manual_eq.rs:15:1 + --> $DIR/derived_hash_with_manual_eq.rs:16:1 | LL | impl PartialEq for Bar { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | impl PartialEq for Bar { = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Hash` but have implemented `PartialEq` explicitly - --> $DIR/derived_hash_with_manual_eq.rs:21:10 + --> $DIR/derived_hash_with_manual_eq.rs:22:10 | LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> $DIR/derived_hash_with_manual_eq.rs:24:1 + --> $DIR/derived_hash_with_manual_eq.rs:26:1 | LL | impl PartialEq for Baz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/disallowed_names.rs b/tests/ui/disallowed_names.rs index 5889f04439ff4..9a701a2cbcfb8 100644 --- a/tests/ui/disallowed_names.rs +++ b/tests/ui/disallowed_names.rs @@ -10,11 +10,16 @@ #![warn(clippy::disallowed_names)] fn test(foo: ()) {} +//~^ ERROR: use of a disallowed/placeholder name `foo` +//~| NOTE: `-D clippy::disallowed-names` implied by `-D warnings` fn main() { let foo = 42; + //~^ ERROR: use of a disallowed/placeholder name `foo` let baz = 42; + //~^ ERROR: use of a disallowed/placeholder name `baz` let quux = 42; + //~^ ERROR: use of a disallowed/placeholder name `quux` // Unlike these others, `bar` is actually considered an acceptable name. // Among many other legitimate uses, bar commonly refers to a period of time in music. // See https://github.com/rust-lang/rust-clippy/issues/5225. @@ -26,23 +31,33 @@ fn main() { match (42, Some(1337), Some(0)) { (foo, Some(baz), quux @ Some(_)) => (), + //~^ ERROR: use of a disallowed/placeholder name `foo` + //~| ERROR: use of a disallowed/placeholder name `baz` + //~| ERROR: use of a disallowed/placeholder name `quux` _ => (), } } fn issue_1647(mut foo: u8) { + //~^ ERROR: use of a disallowed/placeholder name `foo` let mut baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(mut quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } fn issue_1647_ref() { let ref baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(ref quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } fn issue_1647_ref_mut() { let ref mut baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(ref mut quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } mod tests { diff --git a/tests/ui/disallowed_names.stderr b/tests/ui/disallowed_names.stderr index 9ab68b641f137..259501a94e78c 100644 --- a/tests/ui/disallowed_names.stderr +++ b/tests/ui/disallowed_names.stderr @@ -7,79 +7,79 @@ LL | fn test(foo: ()) {} = note: `-D clippy::disallowed-names` implied by `-D warnings` error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:15:9 + --> $DIR/disallowed_names.rs:17:9 | LL | let foo = 42; | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:16:9 + --> $DIR/disallowed_names.rs:19:9 | LL | let baz = 42; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:17:9 + --> $DIR/disallowed_names.rs:21:9 | LL | let quux = 42; | ^^^^ error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:28:10 + --> $DIR/disallowed_names.rs:33:10 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:28:20 + --> $DIR/disallowed_names.rs:33:20 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:28:26 + --> $DIR/disallowed_names.rs:33:26 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:33:19 + --> $DIR/disallowed_names.rs:41:19 | LL | fn issue_1647(mut foo: u8) { | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:34:13 + --> $DIR/disallowed_names.rs:43:13 | LL | let mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:35:21 + --> $DIR/disallowed_names.rs:45:21 | LL | if let Some(mut quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:39:13 + --> $DIR/disallowed_names.rs:50:13 | LL | let ref baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:40:21 + --> $DIR/disallowed_names.rs:52:21 | LL | if let Some(ref quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:44:17 + --> $DIR/disallowed_names.rs:57:17 | LL | let ref mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:45:25 + --> $DIR/disallowed_names.rs:59:25 | LL | if let Some(ref mut quux) = Some(42) {} | ^^^^ diff --git a/tests/ui/disallowed_script_idents.rs b/tests/ui/disallowed_script_idents.rs index 6fc6f9988ebe4..6b68fae318c03 100644 --- a/tests/ui/disallowed_script_idents.rs +++ b/tests/ui/disallowed_script_idents.rs @@ -9,6 +9,8 @@ fn main() { // Cyrillic is not allowed by default. let счётчик = 10; + //~^ ERROR: identifier `счётчик` has a Unicode script that is not allowed by configura // Same for japanese. let カウンタ = 10; + //~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuratio } diff --git a/tests/ui/disallowed_script_idents.stderr b/tests/ui/disallowed_script_idents.stderr index 7b91d8c426b27..bf5cbe306c681 100644 --- a/tests/ui/disallowed_script_idents.stderr +++ b/tests/ui/disallowed_script_idents.stderr @@ -11,7 +11,7 @@ LL | #![deny(clippy::disallowed_script_idents)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana - --> $DIR/disallowed_script_idents.rs:13:9 + --> $DIR/disallowed_script_idents.rs:14:9 | LL | let カウンタ = 10; | ^^^^^^^^ diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index 9b1619baf0e6c..e0acf050949a1 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -18,7 +18,10 @@ impl A { fn main() { let b = true; b || diverge(); + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` b || A.foo(); + //~^ ERROR: sub-expression diverges } #[allow(dead_code, unused_variables)] @@ -29,20 +32,28 @@ fn foobar() { 4 => return, 5 => continue, 6 => true || return, + //~^ ERROR: sub-expression diverges 7 => true || continue, + //~^ ERROR: sub-expression diverges 8 => break, 9 => diverge(), 3 => true || diverge(), + //~^ ERROR: sub-expression diverges 10 => match 42 { 99 => return, _ => true || panic!("boo"), + //~^ ERROR: sub-expression diverges }, // lint blocks as well 15 => true || { return; }, + //~^ ERROR: sub-expression diverges 16 => false || { return; }, + //~^ ERROR: sub-expression diverges // ... and when it's a single expression 17 => true || { return }, + //~^ ERROR: sub-expression diverges 18 => false || { return }, + //~^ ERROR: sub-expression diverges // ... but not when there's both an expression and a statement 19 => true || { _ = 1; return }, 20 => false || { _ = 1; return }, @@ -52,6 +63,7 @@ fn foobar() { 23 => true || { return; true }, 24 => true || { return; true }, _ => true || break, + //~^ ERROR: sub-expression diverges }; } } diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 243a5cf5369ad..042e2690ec41e 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -7,31 +7,31 @@ LL | b || diverge(); = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:21:10 + --> $DIR/diverging_sub_expression.rs:23:10 | LL | b || A.foo(); | ^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:31:26 + --> $DIR/diverging_sub_expression.rs:34:26 | LL | 6 => true || return, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:32:26 + --> $DIR/diverging_sub_expression.rs:36:26 | LL | 7 => true || continue, | ^^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:35:26 + --> $DIR/diverging_sub_expression.rs:40:26 | LL | 3 => true || diverge(), | ^^^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:38:30 + --> $DIR/diverging_sub_expression.rs:44:30 | LL | _ => true || panic!("boo"), | ^^^^^^^^^^^^^ @@ -39,31 +39,31 @@ LL | _ => true || panic!("boo"), = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:41:29 + --> $DIR/diverging_sub_expression.rs:48:29 | LL | 15 => true || { return; }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:42:30 + --> $DIR/diverging_sub_expression.rs:50:30 | LL | 16 => false || { return; }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:44:29 + --> $DIR/diverging_sub_expression.rs:53:29 | LL | 17 => true || { return }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:45:30 + --> $DIR/diverging_sub_expression.rs:55:30 | LL | 18 => false || { return }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:54:26 + --> $DIR/diverging_sub_expression.rs:65:26 | LL | _ => true || break, | ^^^^^ diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 101434b4f3be5..4a1711f79a020 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -5,16 +5,20 @@ #![warn(clippy::doc_markdown)] /// This is a doc comment with `unbalanced_tick marks and several words that +//~^ ERROR: backticks are unbalanced /// should be `encompassed_by` tick marks because they `contain_underscores`. /// Because of the initial `unbalanced_tick` pair, the error message is /// very `confusing_and_misleading`. fn main() {} /// This paragraph has `unbalanced_tick marks and should stop_linting. +//~^ ERROR: backticks are unbalanced /// /// This paragraph is fine and should_be linted normally. +//~^ ERROR: item in documentation is missing backticks /// /// Double unbalanced backtick from ``here to here` should lint. +//~^ ERROR: backticks are unbalanced /// /// Double balanced back ticks ``start end`` is fine. fn multiple_paragraphs() {} @@ -28,11 +32,15 @@ fn in_code_block() {} /// # `Fine` /// /// ## not_fine +//~^ ERROR: item in documentation is missing backticks /// /// ### `unbalanced +//~^ ERROR: backticks are unbalanced /// /// - This `item has unbalanced tick marks +//~^ ERROR: backticks are unbalanced /// - This item needs backticks_here +//~^ ERROR: item in documentation is missing backticks fn other_markdown() {} #[rustfmt::skip] diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index f2ac6bc3269aa..7a3544288be85 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -2,6 +2,7 @@ error: backticks are unbalanced --> $DIR/unbalanced_ticks.rs:7:1 | LL | / /// This is a doc comment with `unbalanced_tick marks and several words that +LL | | LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`. LL | | /// Because of the initial `unbalanced_tick` pair, the error message is LL | | /// very `confusing_and_misleading`. @@ -11,7 +12,7 @@ LL | | /// very `confusing_and_misleading`. = note: `-D clippy::doc-markdown` implied by `-D warnings` error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:13:1 + --> $DIR/unbalanced_ticks.rs:14:1 | LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,7 +20,7 @@ LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:15:32 + --> $DIR/unbalanced_ticks.rs:17:32 | LL | /// This paragraph is fine and should_be linted normally. | ^^^^^^^^^ @@ -30,7 +31,7 @@ LL | /// This paragraph is fine and `should_be` linted normally. | ~~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:17:1 + --> $DIR/unbalanced_ticks.rs:20:1 | LL | /// Double unbalanced backtick from ``here to here` should lint. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +39,7 @@ LL | /// Double unbalanced backtick from ``here to here` should lint. = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:30:8 + --> $DIR/unbalanced_ticks.rs:34:8 | LL | /// ## not_fine | ^^^^^^^^ @@ -49,7 +50,7 @@ LL | /// ## `not_fine` | ~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:32:1 + --> $DIR/unbalanced_ticks.rs:37:1 | LL | /// ### `unbalanced | ^^^^^^^^^^^^^^^^^^^ @@ -57,7 +58,7 @@ LL | /// ### `unbalanced = help: a backtick may be missing a pair error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:34:1 + --> $DIR/unbalanced_ticks.rs:40:1 | LL | /// - This `item has unbalanced tick marks | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +66,7 @@ LL | /// - This `item has unbalanced tick marks = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:35:23 + --> $DIR/unbalanced_ticks.rs:42:23 | LL | /// - This item needs backticks_here | ^^^^^^^^^^^^^^ diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs index 30fdd3b087371..86721f61d199c 100644 --- a/tests/ui/doc_errors.rs +++ b/tests/ui/doc_errors.rs @@ -5,20 +5,25 @@ use std::io; pub fn pub_fn_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section + //~| NOTE: `-D clippy::missing-errors-doc` implied by `-D warnings` unimplemented!(); } pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub fn pub_fn_returning_io_result() -> io::Result<()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } @@ -49,11 +54,13 @@ pub struct Struct1; impl Struct1 { /// This is not sufficiently documented. pub fn pub_method_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } @@ -83,6 +90,7 @@ impl Struct1 { pub trait Trait1 { /// This is not sufficiently documented. fn trait_method_missing_errors_header() -> Result<(), ()>; + //~^ ERROR: docs for function returning `Result` missing `# Errors` section /// # Errors /// A description of the errors goes here. diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index d74f2dbfe1baa..a0356623003e8 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -7,37 +7,37 @@ LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> { = note: `-D clippy::missing-errors-doc` implied by `-D warnings` error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:11:1 + --> $DIR/doc_errors.rs:13:1 | LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:16:1 + --> $DIR/doc_errors.rs:19:1 | LL | pub fn pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:21:1 + --> $DIR/doc_errors.rs:25:1 | LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:51:5 + --> $DIR/doc_errors.rs:56:5 | LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:56:5 + --> $DIR/doc_errors.rs:62:5 | LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:85:5 + --> $DIR/doc_errors.rs:92:5 | LL | fn trait_method_missing_errors_header() -> Result<(), ()>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/doc_link_with_quotes.rs b/tests/ui/doc_link_with_quotes.rs index 17c04c34e2461..37d0d13595737 100644 --- a/tests/ui/doc_link_with_quotes.rs +++ b/tests/ui/doc_link_with_quotes.rs @@ -5,6 +5,8 @@ fn main() { } /// Calls ['bar'] uselessly +//~^ ERROR: possible intra-doc link using quotes instead of backticks +//~| NOTE: `-D clippy::doc-link-with-quotes` implied by `-D warnings` pub fn foo() { bar() } diff --git a/tests/ui/double_must_use.rs b/tests/ui/double_must_use.rs index 26a387b3cf049..615de3e24743c 100644 --- a/tests/ui/double_must_use.rs +++ b/tests/ui/double_must_use.rs @@ -3,16 +3,19 @@ #[must_use] pub fn must_use_result() -> Result<(), ()> { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } #[must_use] pub fn must_use_tuple() -> (Result<(), ()>, u8) { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } #[must_use] pub fn must_use_array() -> [Result<(), ()>; 1] { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } @@ -29,6 +32,7 @@ async fn async_must_use() -> usize { #[must_use] async fn async_must_use_result() -> Result<(), ()> { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already Ok(()) } diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index 49ab2ea3e12b4..46d56006ebfce 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -8,7 +8,7 @@ LL | pub fn must_use_result() -> Result<(), ()> { = note: `-D clippy::double-must-use` implied by `-D warnings` error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:10:1 + --> $DIR/double_must_use.rs:11:1 | LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { = help: either add some descriptive text or remove the attribute error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:15:1 + --> $DIR/double_must_use.rs:17:1 | LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | pub fn must_use_array() -> [Result<(), ()>; 1] { = help: either add some descriptive text or remove the attribute error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:31:1 + --> $DIR/double_must_use.rs:34:1 | LL | async fn async_must_use_result() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/double_neg.rs b/tests/ui/double_neg.rs index 38a8fbd74dcf6..da82890443eb8 100644 --- a/tests/ui/double_neg.rs +++ b/tests/ui/double_neg.rs @@ -5,4 +5,6 @@ fn main() { -x; -(-x); --x; + //~^ ERROR: `--x` could be misinterpreted as pre-decrement by C programmers, is usuall + //~| NOTE: `-D clippy::double-neg` implied by `-D warnings` } diff --git a/tests/ui/double_parens.rs b/tests/ui/double_parens.rs index ff1dc76ab63b1..ab1459eed48bc 100644 --- a/tests/ui/double_parens.rs +++ b/tests/ui/double_parens.rs @@ -13,22 +13,28 @@ impl DummyStruct { fn simple_double_parens() -> i32 { ((0)) + //~^ ERROR: consider removing unnecessary double parentheses + //~| NOTE: `-D clippy::double-parens` implied by `-D warnings` } fn fn_double_parens() { dummy_fn((0)); + //~^ ERROR: consider removing unnecessary double parentheses } fn method_double_parens(x: DummyStruct) { x.dummy_method((0)); + //~^ ERROR: consider removing unnecessary double parentheses } fn tuple_double_parens() -> (i32, i32) { ((1, 2)) + //~^ ERROR: consider removing unnecessary double parentheses } fn unit_double_parens() { (()) + //~^ ERROR: consider removing unnecessary double parentheses } fn fn_tuple_ok() { @@ -51,6 +57,7 @@ fn method_unit_ok(x: DummyStruct) { fn inside_macro() { assert_eq!((1, 2), (1, 2), "Error"); assert_eq!(((1, 2)), (1, 2), "Error"); + //~^ ERROR: consider removing unnecessary double parentheses } fn main() {} diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr index 40fcad2ab1d4a..303ddce024837 100644 --- a/tests/ui/double_parens.stderr +++ b/tests/ui/double_parens.stderr @@ -7,31 +7,31 @@ LL | ((0)) = note: `-D clippy::double-parens` implied by `-D warnings` error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:19:14 + --> $DIR/double_parens.rs:21:14 | LL | dummy_fn((0)); | ^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:23:20 + --> $DIR/double_parens.rs:26:20 | LL | x.dummy_method((0)); | ^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:27:5 + --> $DIR/double_parens.rs:31:5 | LL | ((1, 2)) | ^^^^^^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:31:5 + --> $DIR/double_parens.rs:36:5 | LL | (()) | ^^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:53:16 + --> $DIR/double_parens.rs:59:16 | LL | assert_eq!(((1, 2)), (1, 2), "Error"); | ^^^^^^^^ diff --git a/tests/ui/drop_non_drop.rs b/tests/ui/drop_non_drop.rs index 5a0ebde82c5d4..6dbcb7777d49e 100644 --- a/tests/ui/drop_non_drop.rs +++ b/tests/ui/drop_non_drop.rs @@ -20,6 +20,7 @@ fn main() { struct Foo; // Lint drop(Foo); + //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop // Don't lint drop(make_result(Foo)); // Don't lint @@ -35,6 +36,7 @@ fn main() { struct Baz(T); // Lint drop(Baz(Foo)); + //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop // Don't lint drop(Baz(Bar)); } diff --git a/tests/ui/drop_non_drop.stderr b/tests/ui/drop_non_drop.stderr index b86057c0c321f..15e7c6eeca276 100644 --- a/tests/ui/drop_non_drop.stderr +++ b/tests/ui/drop_non_drop.stderr @@ -12,13 +12,13 @@ LL | drop(Foo); = note: `-D clippy::drop-non-drop` implied by `-D warnings` error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_non_drop.rs:37:5 + --> $DIR/drop_non_drop.rs:38:5 | LL | drop(Baz(Foo)); | ^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> $DIR/drop_non_drop.rs:37:10 + --> $DIR/drop_non_drop.rs:38:10 | LL | drop(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs index 54d748c7ce280..118f6e4a34c0a 100644 --- a/tests/ui/duplicate_underscore_argument.rs +++ b/tests/ui/duplicate_underscore_argument.rs @@ -2,6 +2,8 @@ #[allow(dead_code, unused)] fn join_the_dark_side(darth: i32, _darth: i32) {} +//~^ ERROR: `darth` already exists, having another argument having almost the same name ma +//~| NOTE: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one fn main() { diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs index a2e5c13c45282..77357c15d957f 100644 --- a/tests/ui/empty_enum.rs +++ b/tests/ui/empty_enum.rs @@ -3,5 +3,6 @@ // Enable never type to test empty enum lint #![feature(never_type)] enum Empty {} +//~^ ERROR: enum with no variants fn main() {} diff --git a/tests/ui/empty_loop_no_std.rs b/tests/ui/empty_loop_no_std.rs index f9ab443dfd94a..5fe32351ed450 100644 --- a/tests/ui/empty_loop_no_std.rs +++ b/tests/ui/empty_loop_no_std.rs @@ -11,6 +11,7 @@ use core::panic::PanicInfo; fn main(argc: isize, argv: *const *const u8) -> isize { // This should trigger the lint loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } #[panic_handler] @@ -23,4 +24,5 @@ fn panic(_info: &PanicInfo) -> ! { extern "C" fn eh_personality() { // This should also trigger the lint loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } diff --git a/tests/ui/empty_loop_no_std.stderr b/tests/ui/empty_loop_no_std.stderr index 71af64f49d522..417b7f01c78a9 100644 --- a/tests/ui/empty_loop_no_std.stderr +++ b/tests/ui/empty_loop_no_std.stderr @@ -8,7 +8,7 @@ LL | loop {} = note: `-D clippy::empty-loop` implied by `-D warnings` error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop_no_std.rs:25:5 + --> $DIR/empty_loop_no_std.rs:26:5 | LL | loop {} | ^^^^^^^ diff --git a/tests/ui/enum_clike_unportable_variant.rs b/tests/ui/enum_clike_unportable_variant.rs index abe42a2305f52..964e5634ddb11 100644 --- a/tests/ui/enum_clike_unportable_variant.rs +++ b/tests/ui/enum_clike_unportable_variant.rs @@ -6,6 +6,8 @@ #[repr(usize)] enum NonPortable { X = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~| NOTE: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings` Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, @@ -13,9 +15,11 @@ enum NonPortable { enum NonPortableNoHint { X = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } #[repr(isize)] @@ -23,21 +27,27 @@ enum NonPortableSigned { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets A = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets B = i32::MIN as isize, C = (i32::MIN as isize) - 1, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } enum NonPortableSignedNoHint { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets A = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } #[repr(usize)] enum NonPortable2 { X = ::Number, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets Y = 0, } diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index 531652a0e0026..85df852f72965 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -12,7 +12,10 @@ enum FakeCallType2 { } enum Foo { + //~^ ERROR: all variants have the same prefix: `c` cFoo, + //~^ ERROR: variant name ends with the enum's name + //~| NOTE: `-D clippy::enum-variant-names` implied by `-D warnings` cBar, cBaz, } @@ -23,9 +26,13 @@ enum Fooo { } enum Food { + //~^ ERROR: all variants have the same prefix: `Food` FoodGood, + //~^ ERROR: variant name starts with the enum's name FoodMiddle, + //~^ ERROR: variant name starts with the enum's name FoodBad, + //~^ ERROR: variant name starts with the enum's name } enum Stuff { @@ -33,6 +40,7 @@ enum Stuff { } enum BadCallType { + //~^ ERROR: all variants have the same prefix: `CallType` CallTypeCall, CallTypeCreate, CallTypeDestroy, @@ -45,6 +53,7 @@ enum TwoCallType { } enum Consts { + //~^ ERROR: all variants have the same prefix: `Constant` ConstantInt, ConstantCake, ConstantLie, @@ -57,6 +66,7 @@ enum Two { } enum Something { + //~^ ERROR: all variants have the same prefix: `C` CCall, CCreate, CCryogenize, @@ -79,6 +89,7 @@ enum Sealll { } enum Seallll { + //~^ ERROR: all variants have the same prefix: `WithOut` WithOutCake, WithOutTea, WithOut, @@ -134,12 +145,14 @@ pub enum NetworkLayer { // should lint suggesting `IData`, not only `Data` (see #4639) enum IDataRequest { + //~^ ERROR: all variants have the same postfix: `IData` PutIData(String), GetIData(String), DeleteUnpubIData(String), } enum HIDataRequest { + //~^ ERROR: all variants have the same postfix: `HIData` PutHIData(String), GetHIData(String), DeleteUnpubHIData(String), @@ -160,6 +173,7 @@ enum Phase { mod issue9018 { enum DoLint { + //~^ ERROR: all variants have the same prefix: `_Type` _TypeCreate, _TypeRead, _TypeUpdate, @@ -167,6 +181,7 @@ mod issue9018 { } enum DoLintToo { + //~^ ERROR: all variants have the same postfix: `Type` _CreateType, _UpdateType, _DeleteType, diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index 7342aff80f016..1cfe48cd797f9 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -1,5 +1,5 @@ error: variant name ends with the enum's name - --> $DIR/enum_variants.rs:15:5 + --> $DIR/enum_variants.rs:16:5 | LL | cFoo, | ^^^^ @@ -10,8 +10,10 @@ error: all variants have the same prefix: `c` --> $DIR/enum_variants.rs:14:1 | LL | / enum Foo { +LL | | LL | | cFoo, -LL | | cBar, +LL | | +... | LL | | cBaz, LL | | } | |_^ @@ -19,39 +21,42 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:26:5 + --> $DIR/enum_variants.rs:30:5 | LL | FoodGood, | ^^^^^^^^ error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:27:5 + --> $DIR/enum_variants.rs:32:5 | LL | FoodMiddle, | ^^^^^^^^^^ error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:28:5 + --> $DIR/enum_variants.rs:34:5 | LL | FoodBad, | ^^^^^^^ error: all variants have the same prefix: `Food` - --> $DIR/enum_variants.rs:25:1 + --> $DIR/enum_variants.rs:28:1 | LL | / enum Food { +LL | | LL | | FoodGood, -LL | | FoodMiddle, -LL | | FoodBad, +LL | | +... | +LL | | LL | | } | |_^ | = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `CallType` - --> $DIR/enum_variants.rs:35:1 + --> $DIR/enum_variants.rs:42:1 | LL | / enum BadCallType { +LL | | LL | | CallTypeCall, LL | | CallTypeCreate, LL | | CallTypeDestroy, @@ -61,9 +66,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `Constant` - --> $DIR/enum_variants.rs:47:1 + --> $DIR/enum_variants.rs:55:1 | LL | / enum Consts { +LL | | LL | | ConstantInt, LL | | ConstantCake, LL | | ConstantLie, @@ -73,9 +79,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `C` - --> $DIR/enum_variants.rs:59:1 + --> $DIR/enum_variants.rs:68:1 | LL | / enum Something { +LL | | LL | | CCall, LL | | CCreate, LL | | CCryogenize, @@ -85,9 +92,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `WithOut` - --> $DIR/enum_variants.rs:81:1 + --> $DIR/enum_variants.rs:91:1 | LL | / enum Seallll { +LL | | LL | | WithOutCake, LL | | WithOutTea, LL | | WithOut, @@ -97,9 +105,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `IData` - --> $DIR/enum_variants.rs:136:1 + --> $DIR/enum_variants.rs:147:1 | LL | / enum IDataRequest { +LL | | LL | | PutIData(String), LL | | GetIData(String), LL | | DeleteUnpubIData(String), @@ -109,9 +118,10 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `HIData` - --> $DIR/enum_variants.rs:142:1 + --> $DIR/enum_variants.rs:154:1 | LL | / enum HIDataRequest { +LL | | LL | | PutHIData(String), LL | | GetHIData(String), LL | | DeleteUnpubHIData(String), @@ -121,9 +131,10 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `_Type` - --> $DIR/enum_variants.rs:162:5 + --> $DIR/enum_variants.rs:175:5 | LL | / enum DoLint { +LL | | LL | | _TypeCreate, LL | | _TypeRead, LL | | _TypeUpdate, @@ -134,9 +145,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `Type` - --> $DIR/enum_variants.rs:169:5 + --> $DIR/enum_variants.rs:183:5 | LL | / enum DoLintToo { +LL | | LL | | _CreateType, LL | | _UpdateType, LL | | _DeleteType, diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed index d0349e68622a6..7383d784c8410 100644 --- a/tests/ui/eprint_with_newline.fixed +++ b/tests/ui/eprint_with_newline.fixed @@ -3,10 +3,16 @@ fn main() { eprintln!("Hello"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` eprintln!("Hello {}", "world"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprintln!("Hello {} {}", "world", "#2"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprintln!("{}", 1265); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprintln!(); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline // these are all fine eprint!(""); @@ -29,6 +35,7 @@ fn main() { // #3514 eprint!("\\n"); eprintln!("\\"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\\\\n"); // Raw strings @@ -37,9 +44,11 @@ fn main() { // Literal newlines should also fail eprintln!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline ); eprintln!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline ); @@ -47,6 +56,7 @@ fn main() { eprint!("\r\n"); eprint!("foo\r\n"); eprintln!("\\r"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/eprint_with_newline.rs b/tests/ui/eprint_with_newline.rs index 9446d5d651a17..5b114056411d9 100644 --- a/tests/ui/eprint_with_newline.rs +++ b/tests/ui/eprint_with_newline.rs @@ -3,10 +3,16 @@ fn main() { eprint!("Hello\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` eprint!("Hello {}\n", "world"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("{}\n", 1265); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline // these are all fine eprint!(""); @@ -29,6 +35,7 @@ fn main() { // #3514 eprint!("\\n"); eprint!("\\\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\\\\n"); // Raw strings @@ -37,10 +44,12 @@ fn main() { // Literal newlines should also fail eprint!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline " " ); eprint!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline r" " ); @@ -49,6 +58,7 @@ fn main() { eprint!("\r\n"); eprint!("foo\r\n"); eprint!("\\r\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index e92b1ba672fe7..934c4c8317314 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -12,7 +12,7 @@ LL + eprintln!("Hello"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:6:5 + --> $DIR/eprint_with_newline.rs:8:5 | LL | eprint!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + eprintln!("Hello {}", "world"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:7:5 + --> $DIR/eprint_with_newline.rs:10:5 | LL | eprint!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + eprintln!("Hello {} {}", "world", "#2"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:8:5 + --> $DIR/eprint_with_newline.rs:12:5 | LL | eprint!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + eprintln!("{}", 1265); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:9:5 + --> $DIR/eprint_with_newline.rs:14:5 | LL | eprint!("\n"); | ^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:31:5 + --> $DIR/eprint_with_newline.rs:37:5 | LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:39:5 + --> $DIR/eprint_with_newline.rs:46:5 | LL | / eprint!( +LL | | LL | | " LL | | " LL | | ); @@ -83,13 +84,15 @@ LL | | ); help: use `eprintln!` instead | LL ~ eprintln!( +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:43:5 + --> $DIR/eprint_with_newline.rs:51:5 | LL | / eprint!( +LL | | LL | | r" LL | | " LL | | ); @@ -98,11 +101,12 @@ LL | | ); help: use `eprintln!` instead | LL ~ eprintln!( +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:51:5 + --> $DIR/eprint_with_newline.rs:60:5 | LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index e973e5ba2fb1e..7c2c131875182 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -5,51 +5,80 @@ fn main() { // simple values and comparisons let _ = 1 == 1; + //~^ ERROR: equal expressions as operands to `==` + //~| NOTE: `-D clippy::eq-op` implied by `-D warnings` let _ = "no" == "no"; + //~^ ERROR: equal expressions as operands to `==` // even though I agree that no means no ;-) let _ = false != false; + //~^ ERROR: equal expressions as operands to `!=` let _ = 1.5 < 1.5; + //~^ ERROR: equal expressions as operands to `<` let _ = 1u64 >= 1u64; + //~^ ERROR: equal expressions as operands to `>=` let x = f32::NAN; let _ = x != x; + //~^ ERROR: equal expressions as operands to `!=` + //~| NOTE: if you intended to check if the operand is NaN, use `.is_nan()` instead // casts, methods, parentheses let _ = (1u32 as u64) & (1u32 as u64); + //~^ ERROR: equal expressions as operands to `&` #[rustfmt::skip] { let _ = 1 ^ ((((((1)))))); + //~^ ERROR: equal expressions as operands to `^` }; // unary and binary operators let _ = (-(2) < -(2)); + //~^ ERROR: equal expressions as operands to `<` let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); + //~^ ERROR: equal expressions as operands to `==` + //~| ERROR: equal expressions as operands to `&` + //~| ERROR: equal expressions as operands to `&` let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; + //~^ ERROR: equal expressions as operands to `==` // various other things let _ = ([1] != [1]); + //~^ ERROR: equal expressions as operands to `!=` let _ = ((1, 2) != (1, 2)); + //~^ ERROR: equal expressions as operands to `!=` let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros // const folding let _ = 1 + 1 == 2; + //~^ ERROR: equal expressions as operands to `==` let _ = 1 - 1 == 0; + //~^ ERROR: equal expressions as operands to `==` + //~| ERROR: equal expressions as operands to `-` let _ = 1 - 1; + //~^ ERROR: equal expressions as operands to `-` let _ = 1 / 1; + //~^ ERROR: equal expressions as operands to `/` let _ = true && true; + //~^ ERROR: equal expressions as operands to `&&` let _ = true || true; + //~^ ERROR: equal expressions as operands to `||` let a: u32 = 0; let b: u32 = 0; let _ = a == b && b == a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a != b && b != a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a < b && b > a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a <= b && b >= a; + //~^ ERROR: equal expressions as operands to `&&` let mut a = vec![1]; let _ = a == a; + //~^ ERROR: equal expressions as operands to `==` let _ = 2 * a.len() == 2 * a.len(); // ok, functions let _ = a.pop() == a.pop(); // ok, functions @@ -60,6 +89,7 @@ fn main() { const B: u32 = 10; const C: u32 = A / B; // ok, different named constants const D: u32 = A / A; + //~^ ERROR: equal expressions as operands to `/` } macro_rules! check_if_named_foo { @@ -91,6 +121,7 @@ struct Nested { fn check_nested(n1: &Nested, n2: &Nested) -> bool { // `n2.inner.0.0` mistyped as `n1.inner.0.0` (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 + //~^ ERROR: equal expressions as operands to `==` } #[test] diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index c7fa253bdca26..315d94cc90e62 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -7,31 +7,31 @@ LL | let _ = 1 == 1; = note: `-D clippy::eq-op` implied by `-D warnings` error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:8:13 + --> $DIR/eq_op.rs:10:13 | LL | let _ = "no" == "no"; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:10:13 + --> $DIR/eq_op.rs:13:13 | LL | let _ = false != false; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:11:13 + --> $DIR/eq_op.rs:15:13 | LL | let _ = 1.5 < 1.5; | ^^^^^^^^^ error: equal expressions as operands to `>=` - --> $DIR/eq_op.rs:12:13 + --> $DIR/eq_op.rs:17:13 | LL | let _ = 1u64 >= 1u64; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:14:13 + --> $DIR/eq_op.rs:20:13 | LL | let _ = x != x; | ^^^^^^ @@ -39,139 +39,139 @@ LL | let _ = x != x; = note: if you intended to check if the operand is NaN, use `.is_nan()` instead error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:17:13 + --> $DIR/eq_op.rs:25:13 | LL | let _ = (1u32 as u64) & (1u32 as u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `^` - --> $DIR/eq_op.rs:20:17 + --> $DIR/eq_op.rs:29:17 | LL | let _ = 1 ^ ((((((1)))))); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:24:13 + --> $DIR/eq_op.rs:34:13 | LL | let _ = (-(2) < -(2)); | ^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:25:13 + --> $DIR/eq_op.rs:36:13 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:14 + --> $DIR/eq_op.rs:36:14 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:35 + --> $DIR/eq_op.rs:36:35 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:26:13 + --> $DIR/eq_op.rs:40:13 | LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:29:13 + --> $DIR/eq_op.rs:44:13 | LL | let _ = ([1] != [1]); | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:30:13 + --> $DIR/eq_op.rs:46:13 | LL | let _ = ((1, 2) != (1, 2)); | ^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:34:13 + --> $DIR/eq_op.rs:51:13 | LL | let _ = 1 + 1 == 2; | ^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:35:13 + --> $DIR/eq_op.rs:53:13 | LL | let _ = 1 - 1 == 0; | ^^^^^^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:35:13 + --> $DIR/eq_op.rs:53:13 | LL | let _ = 1 - 1 == 0; | ^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:37:13 + --> $DIR/eq_op.rs:57:13 | LL | let _ = 1 - 1; | ^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:38:13 + --> $DIR/eq_op.rs:59:13 | LL | let _ = 1 / 1; | ^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:39:13 + --> $DIR/eq_op.rs:61:13 | LL | let _ = true && true; | ^^^^^^^^^^^^ error: equal expressions as operands to `||` - --> $DIR/eq_op.rs:41:13 + --> $DIR/eq_op.rs:64:13 | LL | let _ = true || true; | ^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:46:13 + --> $DIR/eq_op.rs:70:13 | LL | let _ = a == b && b == a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:47:13 + --> $DIR/eq_op.rs:72:13 | LL | let _ = a != b && b != a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:48:13 + --> $DIR/eq_op.rs:74:13 | LL | let _ = a < b && b > a; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:49:13 + --> $DIR/eq_op.rs:76:13 | LL | let _ = a <= b && b >= a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:52:13 + --> $DIR/eq_op.rs:80:13 | LL | let _ = a == a; | ^^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:62:20 + --> $DIR/eq_op.rs:91:20 | LL | const D: u32 = A / A; | ^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:93:5 + --> $DIR/eq_op.rs:123:5 | LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/eq_op_macros.rs b/tests/ui/eq_op_macros.rs index 4824067722890..a511af4a31c8c 100644 --- a/tests/ui/eq_op_macros.rs +++ b/tests/ui/eq_op_macros.rs @@ -21,7 +21,9 @@ fn main() { // lint identical args in `assert_eq!` assert_eq!(a, a); + //~^ ERROR: identical args used in this `assert_eq!` macro call assert_eq!(a + 1, a + 1); + //~^ ERROR: identical args used in this `assert_eq!` macro call // ok assert_eq!(a, b); assert_eq!(a, a + 1); @@ -29,7 +31,9 @@ fn main() { // lint identical args in `assert_ne!` assert_ne!(a, a); + //~^ ERROR: identical args used in this `assert_ne!` macro call assert_ne!(a + 1, a + 1); + //~^ ERROR: identical args used in this `assert_ne!` macro call // ok assert_ne!(a, b); assert_ne!(a, a + 1); @@ -37,7 +41,9 @@ fn main() { // lint identical args in `debug_assert_eq!` debug_assert_eq!(a, a); + //~^ ERROR: identical args used in this `debug_assert_eq!` macro call debug_assert_eq!(a + 1, a + 1); + //~^ ERROR: identical args used in this `debug_assert_eq!` macro call // ok debug_assert_eq!(a, b); debug_assert_eq!(a, a + 1); @@ -45,7 +51,9 @@ fn main() { // lint identical args in `debug_assert_ne!` debug_assert_ne!(a, a); + //~^ ERROR: identical args used in this `debug_assert_ne!` macro call debug_assert_ne!(a + 1, a + 1); + //~^ ERROR: identical args used in this `debug_assert_ne!` macro call // ok debug_assert_ne!(a, b); debug_assert_ne!(a, a + 1); diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr index cb9b0c01862bf..3c60cdbc5ca95 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -50,43 +50,43 @@ LL | assert_eq!(a, a); | ^^^^ error: identical args used in this `assert_eq!` macro call - --> $DIR/eq_op_macros.rs:24:16 + --> $DIR/eq_op_macros.rs:25:16 | LL | assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:31:16 + --> $DIR/eq_op_macros.rs:33:16 | LL | assert_ne!(a, a); | ^^^^ error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:32:16 + --> $DIR/eq_op_macros.rs:35:16 | LL | assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:39:22 + --> $DIR/eq_op_macros.rs:43:22 | LL | debug_assert_eq!(a, a); | ^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:40:22 + --> $DIR/eq_op_macros.rs:45:22 | LL | debug_assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:47:22 + --> $DIR/eq_op_macros.rs:53:22 | LL | debug_assert_ne!(a, a); | ^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:48:22 + --> $DIR/eq_op_macros.rs:55:22 | LL | debug_assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs index 74985029e008a..00c74f23fed04 100644 --- a/tests/ui/erasing_op.rs +++ b/tests/ui/erasing_op.rs @@ -33,11 +33,17 @@ impl core::ops::Mul for Vec1 { #[warn(clippy::erasing_op)] fn test(x: u8) { x * 0; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou + //~| NOTE: `-D clippy::erasing-op` implied by `-D warnings` 0 & x; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou 0 / x; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou 0 * Meter; // no error: Output type is different from the non-zero argument 0 * Vec1 { x: 5 }; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou Vec1 { x: 5 } * 0; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou } fn main() { diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr index 97941252355af..7b9608fe45228 100644 --- a/tests/ui/erasing_op.stderr +++ b/tests/ui/erasing_op.stderr @@ -7,25 +7,25 @@ LL | x * 0; = note: `-D clippy::erasing-op` implied by `-D warnings` error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:36:5 + --> $DIR/erasing_op.rs:38:5 | LL | 0 & x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:37:5 + --> $DIR/erasing_op.rs:40:5 | LL | 0 / x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:39:5 + --> $DIR/erasing_op.rs:43:5 | LL | 0 * Vec1 { x: 5 }; | ^^^^^^^^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:40:5 + --> $DIR/erasing_op.rs:45:5 | LL | Vec1 { x: 5 } * 0; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/error_impl_error.rs b/tests/ui/error_impl_error.rs index 40ce4181bf34a..05003f7d047ca 100644 --- a/tests/ui/error_impl_error.rs +++ b/tests/ui/error_impl_error.rs @@ -5,6 +5,7 @@ pub mod a { #[derive(Debug)] pub struct Error; + //~^ ERROR: exported type named `Error` that implements `Error` impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -18,6 +19,7 @@ pub mod a { mod b { #[derive(Debug)] pub(super) enum Error {} + //~^ ERROR: exported type named `Error` that implements `Error` impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -30,6 +32,7 @@ mod b { pub mod c { pub union Error { + //~^ ERROR: exported type named `Error` that implements `Error` a: u32, b: u32, } @@ -51,6 +54,7 @@ pub mod c { pub mod d { pub type Error = std::fmt::Error; + //~^ ERROR: exported type alias named `Error` that implements `Error` } mod e { diff --git a/tests/ui/error_impl_error.stderr b/tests/ui/error_impl_error.stderr index f3e04b6416731..54a55d5dcf4b1 100644 --- a/tests/ui/error_impl_error.stderr +++ b/tests/ui/error_impl_error.stderr @@ -5,38 +5,38 @@ LL | pub struct Error; | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:15:5 + --> $DIR/error_impl_error.rs:16:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::error-impl-error` implied by `-D warnings` error: exported type named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:20:21 + --> $DIR/error_impl_error.rs:21:21 | LL | pub(super) enum Error {} | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:28:5 + --> $DIR/error_impl_error.rs:30:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:32:15 + --> $DIR/error_impl_error.rs:34:15 | LL | pub union Error { | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:49:5 + --> $DIR/error_impl_error.rs:52:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type alias named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:53:14 + --> $DIR/error_impl_error.rs:56:14 | LL | pub type Error = std::fmt::Error; | ^^^^^ diff --git a/tests/ui/exit1.rs b/tests/ui/exit1.rs index 4eac6eb74672f..a89f6dd4ca0eb 100644 --- a/tests/ui/exit1.rs +++ b/tests/ui/exit1.rs @@ -3,6 +3,8 @@ fn not_main() { if true { std::process::exit(4); + //~^ ERROR: usage of `process::exit` + //~| NOTE: `-D clippy::exit` implied by `-D warnings` } } diff --git a/tests/ui/exit2.rs b/tests/ui/exit2.rs index 4b693ed7083f0..d5ff93fb9ccb8 100644 --- a/tests/ui/exit2.rs +++ b/tests/ui/exit2.rs @@ -2,6 +2,8 @@ fn also_not_main() { std::process::exit(3); + //~^ ERROR: usage of `process::exit` + //~| NOTE: `-D clippy::exit` implied by `-D warnings` } fn main() { diff --git a/tests/ui/expect.rs b/tests/ui/expect.rs index 1588579bb0f2f..f15b3d37e154b 100644 --- a/tests/ui/expect.rs +++ b/tests/ui/expect.rs @@ -4,12 +4,15 @@ fn expect_option() { let opt = Some(0); let _ = opt.expect(""); + //~^ ERROR: used `expect()` on an `Option` value } fn expect_result() { let res: Result = Ok(0); let _ = res.expect(""); + //~^ ERROR: used `expect()` on a `Result` value let _ = res.expect_err(""); + //~^ ERROR: used `expect_err()` on a `Result` value } fn main() { diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index f787fa973a32e..c9a29624d530a 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -8,7 +8,7 @@ LL | let _ = opt.expect(""); = note: `-D clippy::expect-used` implied by `-D warnings` error: used `expect()` on a `Result` value - --> $DIR/expect.rs:11:13 + --> $DIR/expect.rs:12:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = res.expect(""); = note: if this value is an `Err`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/expect.rs:12:13 + --> $DIR/expect.rs:14:13 | LL | let _ = res.expect_err(""); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs index 7963bf0f3a6a2..5fab9ceb67971 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.rs +++ b/tests/ui/expect_tool_lint_rfc_2383.rs @@ -33,10 +33,13 @@ mod rustc_warn { //! See #[expect(dead_code)] + //~^ ERROR: this lint expectation is unfulfilled + //~| NOTE: `-D unfulfilled-lint-expectations` implied by `-D warnings` pub fn rustc_lints() { let x = 42; #[expect(illegal_floating_point_literal_pattern)] + //~^ ERROR: this lint expectation is unfulfilled match x { 5 => {}, 6 => {}, @@ -111,6 +114,7 @@ mod clippy_warn { //! See #[expect(clippy::almost_swapped)] + //~^ ERROR: this lint expectation is unfulfilled fn foo() { let mut a = 0; let mut b = 9; @@ -118,16 +122,19 @@ mod clippy_warn { } #[expect(clippy::bytes_nth)] + //~^ ERROR: this lint expectation is unfulfilled fn bar() { let _ = "Hello".as_bytes().get(3); } #[expect(clippy::if_same_then_else)] + //~^ ERROR: this lint expectation is unfulfilled fn baz() { let _ = if true { 33 } else { 42 }; } #[expect(clippy::overly_complex_bool_expr)] + //~^ ERROR: this lint expectation is unfulfilled fn burger() { let a = false; let b = true; diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr index 7ce9e855b5e05..1a08d77113a40 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -7,31 +7,31 @@ LL | #[expect(dead_code)] = note: `-D unfulfilled-lint-expectations` implied by `-D warnings` error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:39:18 + --> $DIR/expect_tool_lint_rfc_2383.rs:41:18 | LL | #[expect(illegal_floating_point_literal_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:113:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:116:14 | LL | #[expect(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:120:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:124:14 | LL | #[expect(clippy::bytes_nth)] | ^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:125:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 | LL | #[expect(clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:136:14 | LL | #[expect(clippy::overly_complex_bool_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs index 15dc9669efa96..c25e79a36171f 100644 --- a/tests/ui/explicit_counter_loop.rs +++ b/tests/ui/explicit_counter_loop.rs @@ -5,22 +5,27 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; for _v in &vec { + //~^ ERROR: the variable `_index` is used as a loop counter + //~| NOTE: `-D clippy::explicit-counter-loop` implied by `-D warnings` _index += 1 } let mut _index = 1; _index = 0; for _v in &vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1 } let mut _index = 0; for _v in &mut vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1; } let mut _index = 0; for _v in vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1; } @@ -108,6 +113,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { + //~^ ERROR: the variable `count` is used as a loop counter println!("{}", count); count += 1; if ch == 'a' { @@ -119,6 +125,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { + //~^ ERROR: the variable `count` is used as a loop counter println!("{}", count); count += 1; for i in 0..2 { @@ -177,6 +184,7 @@ mod issue_1670 { pub fn test() { let mut count = 0; for _i in 3..10 { + //~^ ERROR: the variable `count` is used as a loop counter count += 1; } } @@ -217,6 +225,7 @@ mod issue_7920 { // should suggest `enumerate` for _item in slice { + //~^ ERROR: the variable `idx_usize` is used as a loop counter if idx_usize == index_usize { break; } @@ -229,6 +238,8 @@ mod issue_7920 { // should suggest `zip` for _item in slice { + //~^ ERROR: the variable `idx_u32` is used as a loop counter + //~| NOTE: `idx_u32` is of type `u32`, making it ineligible for `Iterator::enumera if idx_u32 == index_u32 { break; } diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr index 0677e4d78c8be..3b36f28617bb0 100644 --- a/tests/ui/explicit_counter_loop.stderr +++ b/tests/ui/explicit_counter_loop.stderr @@ -7,49 +7,49 @@ LL | for _v in &vec { = note: `-D clippy::explicit-counter-loop` implied by `-D warnings` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:13:5 + --> $DIR/explicit_counter_loop.rs:15:5 | LL | for _v in &vec { | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:18:5 + --> $DIR/explicit_counter_loop.rs:21:5 | LL | for _v in &mut vec { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:23:5 + --> $DIR/explicit_counter_loop.rs:27:5 | LL | for _v in vec { | ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:110:9 + --> $DIR/explicit_counter_loop.rs:115:9 | LL | for ch in text.chars() { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:121:9 + --> $DIR/explicit_counter_loop.rs:127:9 | LL | for ch in text.chars() { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:179:9 + --> $DIR/explicit_counter_loop.rs:186:9 | LL | for _i in 3..10 { | ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()` error: the variable `idx_usize` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:219:9 + --> $DIR/explicit_counter_loop.rs:227:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_usize, _item) in slice.iter().enumerate()` error: the variable `idx_u32` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:231:9 + --> $DIR/explicit_counter_loop.rs:240:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_u32, _item) in (0_u32..).zip(slice.iter())` diff --git a/tests/ui/extra_unused_type_parameters_unfixable.rs b/tests/ui/extra_unused_type_parameters_unfixable.rs index 10b39aa8f2c5b..65b53eb2e4b3a 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.rs +++ b/tests/ui/extra_unused_type_parameters_unfixable.rs @@ -1,6 +1,7 @@ #![warn(clippy::extra_unused_type_parameters)] fn unused_where_clause(x: U) +//~^ ERROR: type parameter `T` goes unused in function definition where T: Default, { @@ -8,6 +9,7 @@ where } fn unused_multi_where_clause(x: U) +//~^ ERROR: type parameters go unused in function definition: T, V where T: Default, { @@ -15,6 +17,7 @@ where } fn unused_all_where_clause() +//~^ ERROR: type parameters go unused in function definition: T, U, V where T: Default, { diff --git a/tests/ui/extra_unused_type_parameters_unfixable.stderr b/tests/ui/extra_unused_type_parameters_unfixable.stderr index a9580cc894f35..bbd0cf478ab3c 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.stderr +++ b/tests/ui/extra_unused_type_parameters_unfixable.stderr @@ -8,7 +8,7 @@ LL | fn unused_where_clause(x: U) = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` error: type parameters go unused in function definition: T, V - --> $DIR/extra_unused_type_parameters_unfixable.rs:10:30 + --> $DIR/extra_unused_type_parameters_unfixable.rs:11:30 | LL | fn unused_multi_where_clause(x: U) | ^ ^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn unused_multi_where_clause(x: U) = help: consider removing the parameters error: type parameters go unused in function definition: T, U, V - --> $DIR/extra_unused_type_parameters_unfixable.rs:17:28 + --> $DIR/extra_unused_type_parameters_unfixable.rs:19:28 | LL | fn unused_all_where_clause() | ^ ^^^^^^^^^^ ^^^^^^^^^^ diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs index fb6e8ec706b17..a81e51fcac75a 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -4,6 +4,7 @@ // docs example struct Foo(i32); impl From for Foo { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: String) -> Self { Foo(s.parse().unwrap()) } @@ -25,6 +26,7 @@ impl From for Valid { struct Invalid; impl From for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(i: usize) -> Invalid { if i != 42 { panic!(); @@ -34,6 +36,7 @@ impl From for Invalid { } impl From> for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: Option) -> Invalid { let s = s.unwrap(); if !s.is_empty() { @@ -52,6 +55,7 @@ impl ProjStrTrait for Box { type ProjString = String; } impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { if s.parse::().ok().unwrap() != 42 { panic!("{:?}", s); diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index 21761484f8c45..96074ca89ea0f 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -2,6 +2,7 @@ error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:6:1 | LL | / impl From for Foo { +LL | | LL | | fn from(s: String) -> Self { LL | | Foo(s.parse().unwrap()) LL | | } @@ -10,7 +11,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:8:13 + --> $DIR/fallible_impl_from.rs:9:13 | LL | Foo(s.parse().unwrap()) | ^^^^^^^^^^^^^^^^^^ @@ -21,12 +22,12 @@ LL | #![deny(clippy::fallible_impl_from)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:27:1 + --> $DIR/fallible_impl_from.rs:28:1 | LL | / impl From for Invalid { +LL | | LL | | fn from(i: usize) -> Invalid { LL | | if i != 42 { -LL | | panic!(); ... | LL | | } LL | | } @@ -34,19 +35,19 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:30:13 + --> $DIR/fallible_impl_from.rs:32:13 | LL | panic!(); | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:36:1 + --> $DIR/fallible_impl_from.rs:38:1 | LL | / impl From> for Invalid { +LL | | LL | | fn from(s: Option) -> Invalid { LL | | let s = s.unwrap(); -LL | | if !s.is_empty() { ... | LL | | } LL | | } @@ -54,7 +55,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:38:17 + --> $DIR/fallible_impl_from.rs:41:17 | LL | let s = s.unwrap(); | ^^^^^^^^^^ @@ -68,12 +69,12 @@ LL | panic!("{:?}", s); = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:54:1 + --> $DIR/fallible_impl_from.rs:57:1 | LL | / impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { +LL | | LL | | fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { LL | | if s.parse::().ok().unwrap() != 42 { -LL | | panic!("{:?}", s); ... | LL | | } LL | | } @@ -81,7 +82,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:56:12 + --> $DIR/fallible_impl_from.rs:60:12 | LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs index d3ad36e40b53c..9e8a4c04324b0 100644 --- a/tests/ui/filetype_is_file.rs +++ b/tests/ui/filetype_is_file.rs @@ -7,16 +7,19 @@ fn main() -> std::io::Result<()> { // !filetype.is_dir() if fs::metadata("foo.txt")?.file_type().is_file() { + //~^ ERROR: `FileType::is_file()` only covers regular files // read file } // positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file() { + //~^ ERROR: `!FileType::is_file()` only denies regular files // handle dir } // false positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { + //~^ ERROR: `FileType::is_file()` only covers regular files // ... } diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 36142deb3092a..718d287e6799f 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -8,7 +8,7 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() { = note: `-D clippy::filetype-is-file` implied by `-D warnings` error: `!FileType::is_file()` only denies regular files - --> $DIR/filetype_is_file.rs:14:8 + --> $DIR/filetype_is_file.rs:15:8 | LL | if !fs::metadata("foo.txt")?.file_type().is_file() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | if !fs::metadata("foo.txt")?.file_type().is_file() { = help: use `FileType::is_dir()` instead error: `FileType::is_file()` only covers regular files - --> $DIR/filetype_is_file.rs:19:9 + --> $DIR/filetype_is_file.rs:21:9 | LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/filter_map_next.rs b/tests/ui/filter_map_next.rs index dbeb2354309c9..9077b8fca23e2 100644 --- a/tests/ui/filter_map_next.rs +++ b/tests/ui/filter_map_next.rs @@ -5,6 +5,8 @@ fn main() { #[rustfmt::skip] let _: Option = vec![1, 2, 3, 4, 5, 6] + //~^ ERROR: called `filter_map(..).next()` on an `Iterator`. This is more succinctly e + //~| NOTE: `-D clippy::filter-map-next` implied by `-D warnings` .into_iter() .filter_map(|x| { if x == 2 { diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr index ddc982c93fe6d..3220ee51c2ac9 100644 --- a/tests/ui/filter_map_next.stderr +++ b/tests/ui/filter_map_next.stderr @@ -3,9 +3,9 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly | LL | let _: Option = vec![1, 2, 3, 4, 5, 6] | __________________________^ +LL | | +LL | | LL | | .into_iter() -LL | | .filter_map(|x| { -LL | | if x == 2 { ... | LL | | }) LL | | .next(); diff --git a/tests/ui/float_arithmetic.rs b/tests/ui/float_arithmetic.rs index a928c35e8bc99..1647273c436d8 100644 --- a/tests/ui/float_arithmetic.rs +++ b/tests/ui/float_arithmetic.rs @@ -13,40 +13,58 @@ fn main() { let mut f = 1.0f32; f * 2.0; + //~^ ERROR: floating-point arithmetic detected + //~| NOTE: `-D clippy::float-arithmetic` implied by `-D warnings` 1.0 + f; + //~^ ERROR: floating-point arithmetic detected f * 2.0; + //~^ ERROR: floating-point arithmetic detected f / 2.0; + //~^ ERROR: floating-point arithmetic detected f - 2.0 * 4.2; + //~^ ERROR: floating-point arithmetic detected -f; + //~^ ERROR: floating-point arithmetic detected f += 1.0; + //~^ ERROR: floating-point arithmetic detected f -= 1.0; + //~^ ERROR: floating-point arithmetic detected f *= 2.0; + //~^ ERROR: floating-point arithmetic detected f /= 2.0; + //~^ ERROR: floating-point arithmetic detected } // also warn about floating point arith with references involved pub fn float_arith_ref() { 3.1_f32 + &1.2_f32; + //~^ ERROR: floating-point arithmetic detected &3.4_f32 + 1.5_f32; + //~^ ERROR: floating-point arithmetic detected &3.5_f32 + &1.3_f32; + //~^ ERROR: floating-point arithmetic detected } pub fn float_foo(f: &f32) -> f32 { let a = 5.1; a + f + //~^ ERROR: floating-point arithmetic detected } pub fn float_bar(f1: &f32, f2: &f32) -> f32 { f1 + f2 + //~^ ERROR: floating-point arithmetic detected } pub fn float_baz(f1: f32, f2: &f32) -> f32 { f1 + f2 + //~^ ERROR: floating-point arithmetic detected } pub fn float_qux(f1: f32, f2: f32) -> f32 { (&f1 + &f2) + //~^ ERROR: floating-point arithmetic detected } diff --git a/tests/ui/float_arithmetic.stderr b/tests/ui/float_arithmetic.stderr index 1ceffb35beede..fe8446c98167a 100644 --- a/tests/ui/float_arithmetic.stderr +++ b/tests/ui/float_arithmetic.stderr @@ -7,97 +7,97 @@ LL | f * 2.0; = note: `-D clippy::float-arithmetic` implied by `-D warnings` error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:17:5 + --> $DIR/float_arithmetic.rs:19:5 | LL | 1.0 + f; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:18:5 + --> $DIR/float_arithmetic.rs:21:5 | LL | f * 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:19:5 + --> $DIR/float_arithmetic.rs:23:5 | LL | f / 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:20:5 + --> $DIR/float_arithmetic.rs:25:5 | LL | f - 2.0 * 4.2; | ^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:21:5 + --> $DIR/float_arithmetic.rs:27:5 | LL | -f; | ^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:23:5 + --> $DIR/float_arithmetic.rs:30:5 | LL | f += 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:24:5 + --> $DIR/float_arithmetic.rs:32:5 | LL | f -= 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:25:5 + --> $DIR/float_arithmetic.rs:34:5 | LL | f *= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:26:5 + --> $DIR/float_arithmetic.rs:36:5 | LL | f /= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:32:5 + --> $DIR/float_arithmetic.rs:43:5 | LL | 3.1_f32 + &1.2_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:33:5 + --> $DIR/float_arithmetic.rs:45:5 | LL | &3.4_f32 + 1.5_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:34:5 + --> $DIR/float_arithmetic.rs:47:5 | LL | &3.5_f32 + &1.3_f32; | ^^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:39:5 + --> $DIR/float_arithmetic.rs:53:5 | LL | a + f | ^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:43:5 + --> $DIR/float_arithmetic.rs:58:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:47:5 + --> $DIR/float_arithmetic.rs:63:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:51:5 + --> $DIR/float_arithmetic.rs:68:5 | LL | (&f1 + &f2) | ^^^^^^^^^^^ diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index b0a6a64a18aff..a547a67430fd2 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -55,14 +55,20 @@ fn main() { ONE != 0.0; // no error, comparison with zero is ok twice(ONE) != ONE; ONE as f64 != 2.0; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` ONE as f64 != 0.0; // no error, comparison with zero is ok let x: f64 = 1.0; x == 1.0; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` x != 0f64; // no error, comparison with zero is ok twice(x) != twice(ONE as f64); + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` x < 0.0; // no errors, lower or greater comparisons need no fuzzyness x > 0.0; @@ -83,12 +89,18 @@ fn main() { ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let a1: [f32; 1] = [0.0]; let a2: [f32; 1] = [1.1]; a1 == a2; + //~^ ERROR: strict comparison of `f32` or `f64` arrays + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` a1[0] == a2[0]; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` // no errors - comparing signums is ok let x32 = 3.21f32; diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index e3e9f3949fdf8..5836b5603d6eb 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -8,7 +8,7 @@ LL | ONE as f64 != 2.0; = note: `-D clippy::float-cmp` implied by `-D warnings` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:62:5 + --> $DIR/float_cmp.rs:64:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` @@ -16,7 +16,7 @@ LL | x == 1.0; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:65:5 + --> $DIR/float_cmp.rs:69:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` @@ -24,7 +24,7 @@ LL | twice(x) != twice(ONE as f64); = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:85:5 + --> $DIR/float_cmp.rs:91:5 | LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` @@ -32,7 +32,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` arrays - --> $DIR/float_cmp.rs:90:5 + --> $DIR/float_cmp.rs:98:5 | LL | a1 == a2; | ^^^^^^^^ @@ -40,7 +40,7 @@ LL | a1 == a2; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:91:5 + --> $DIR/float_cmp.rs:101:5 | LL | a1[0] == a2[0]; | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 1493d4f1d37f3..47ea0e19c68b9 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -14,15 +14,29 @@ fn eq_one(x: f32) -> bool { fn main() { // has errors 1f32 == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` TWO == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` TWO != ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` ONE + ONE == TWO; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let x = 1; x as f32 == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let v = 0.9; v == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` v != ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` // no errors, lower than or greater than comparisons v < ONE; @@ -55,4 +69,6 @@ fn main() { // has errors NON_ZERO_ARRAY == NON_ZERO_ARRAY2; + //~^ ERROR: strict comparison of `f32` or `f64` constant arrays + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` } diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 65c45648ab380..4de1d58adc0f3 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -8,7 +8,7 @@ LL | 1f32 == ONE; = note: `-D clippy::float-cmp-const` implied by `-D warnings` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:17:5 + --> $DIR/float_cmp_const.rs:19:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` @@ -16,7 +16,7 @@ LL | TWO == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:18:5 + --> $DIR/float_cmp_const.rs:22:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` @@ -24,7 +24,7 @@ LL | TWO != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:19:5 + --> $DIR/float_cmp_const.rs:25:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` @@ -32,7 +32,7 @@ LL | ONE + ONE == TWO; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:21:5 + --> $DIR/float_cmp_const.rs:29:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` @@ -40,7 +40,7 @@ LL | x as f32 == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:24:5 + --> $DIR/float_cmp_const.rs:34:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` @@ -48,7 +48,7 @@ LL | v == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:25:5 + --> $DIR/float_cmp_const.rs:37:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` @@ -56,7 +56,7 @@ LL | v != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant arrays - --> $DIR/float_cmp_const.rs:57:5 + --> $DIR/float_cmp_const.rs:71:5 | LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/float_equality_without_abs.rs b/tests/ui/float_equality_without_abs.rs index 4048c3a7855ba..6363472d8990a 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -2,6 +2,8 @@ //@no-rustfix pub fn is_roughly_equal(a: f32, b: f32) -> bool { (a - b) < f32::EPSILON + //~^ ERROR: float equality check without `.abs()` + //~| NOTE: `-D clippy::float-equality-without-abs` implied by `-D warnings` } pub fn main() { @@ -11,16 +13,26 @@ pub fn main() { let b = 0.0500001; let _ = (a - b) < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = a - b < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = a - b.abs() < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = (a as f64 - b as f64) < f64::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = 1.0 - 2.0 < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > (a - b); + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > a - b; + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > a - b.abs(); + //~^ ERROR: float equality check without `.abs()` let _ = f64::EPSILON > (a as f64 - b as f64); + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > 1.0 - 2.0; + //~^ ERROR: float equality check without `.abs()` // those are correct let _ = (a - b).abs() < f32::EPSILON; diff --git a/tests/ui/float_equality_without_abs.stderr b/tests/ui/float_equality_without_abs.stderr index b34c8159da04d..c9806019f1fa7 100644 --- a/tests/ui/float_equality_without_abs.stderr +++ b/tests/ui/float_equality_without_abs.stderr @@ -9,7 +9,7 @@ LL | (a - b) < f32::EPSILON = note: `-D clippy::float-equality-without-abs` implied by `-D warnings` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:13:13 + --> $DIR/float_equality_without_abs.rs:15:13 | LL | let _ = (a - b) < f32::EPSILON; | -------^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = (a - b) < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:14:13 + --> $DIR/float_equality_without_abs.rs:17:13 | LL | let _ = a - b < f32::EPSILON; | -----^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = a - b < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:15:13 + --> $DIR/float_equality_without_abs.rs:19:13 | LL | let _ = a - b.abs() < f32::EPSILON; | -----------^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = a - b.abs() < f32::EPSILON; | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:16:13 + --> $DIR/float_equality_without_abs.rs:21:13 | LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | ---------------------^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:17:13 + --> $DIR/float_equality_without_abs.rs:23:13 | LL | let _ = 1.0 - 2.0 < f32::EPSILON; | ---------^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = 1.0 - 2.0 < f32::EPSILON; | help: add `.abs()`: `(1.0 - 2.0).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:19:13 + --> $DIR/float_equality_without_abs.rs:26:13 | LL | let _ = f32::EPSILON > (a - b); | ^^^^^^^^^^^^^^^------- @@ -57,7 +57,7 @@ LL | let _ = f32::EPSILON > (a - b); | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:20:13 + --> $DIR/float_equality_without_abs.rs:28:13 | LL | let _ = f32::EPSILON > a - b; | ^^^^^^^^^^^^^^^----- @@ -65,7 +65,7 @@ LL | let _ = f32::EPSILON > a - b; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:21:13 + --> $DIR/float_equality_without_abs.rs:30:13 | LL | let _ = f32::EPSILON > a - b.abs(); | ^^^^^^^^^^^^^^^----------- @@ -73,7 +73,7 @@ LL | let _ = f32::EPSILON > a - b.abs(); | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:22:13 + --> $DIR/float_equality_without_abs.rs:32:13 | LL | let _ = f64::EPSILON > (a as f64 - b as f64); | ^^^^^^^^^^^^^^^--------------------- @@ -81,7 +81,7 @@ LL | let _ = f64::EPSILON > (a as f64 - b as f64); | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:23:13 + --> $DIR/float_equality_without_abs.rs:34:13 | LL | let _ = f32::EPSILON > 1.0 - 2.0; | ^^^^^^^^^^^^^^^--------- diff --git a/tests/ui/fn_address_comparisons.rs b/tests/ui/fn_address_comparisons.rs index 362dcb4fd80ca..35535bd4fddd0 100644 --- a/tests/ui/fn_address_comparisons.rs +++ b/tests/ui/fn_address_comparisons.rs @@ -13,7 +13,10 @@ fn main() { // These should fail: let _ = f == a; + //~^ ERROR: comparing with a non-unique address of a function item + //~| NOTE: `-D clippy::fn-address-comparisons` implied by `-D warnings` let _ = f != a; + //~^ ERROR: comparing with a non-unique address of a function item // These should be fine: let _ = f == g; diff --git a/tests/ui/fn_address_comparisons.stderr b/tests/ui/fn_address_comparisons.stderr index 9c1b5419a4319..87415a0d9048c 100644 --- a/tests/ui/fn_address_comparisons.stderr +++ b/tests/ui/fn_address_comparisons.stderr @@ -7,7 +7,7 @@ LL | let _ = f == a; = note: `-D clippy::fn-address-comparisons` implied by `-D warnings` error: comparing with a non-unique address of a function item - --> $DIR/fn_address_comparisons.rs:16:13 + --> $DIR/fn_address_comparisons.rs:18:13 | LL | let _ = f != a; | ^^^^^^ diff --git a/tests/ui/fn_params_excessive_bools.rs b/tests/ui/fn_params_excessive_bools.rs index f53e531629aae..cc18708d25faf 100644 --- a/tests/ui/fn_params_excessive_bools.rs +++ b/tests/ui/fn_params_excessive_bools.rs @@ -17,22 +17,27 @@ foo!(); #[no_mangle] extern "C" fn k(_: bool, _: bool, _: bool, _: bool) {} fn g(_: bool, _: bool, _: bool, _: bool) {} +//~^ ERROR: more than 3 bools in function parameters fn h(_: bool, _: bool, _: bool) {} fn e(_: S, _: S, _: Box, _: Vec) {} fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} +//~^ ERROR: more than 3 bools in function parameters struct S; trait Trait { // should warn for trait functions with and without body fn f(_: bool, _: bool, _: bool, _: bool); + //~^ ERROR: more than 3 bools in function parameters fn g(_: bool, _: bool, _: bool, _: Vec); #[allow(clippy::fn_params_excessive_bools)] fn h(_: bool, _: bool, _: bool, _: bool, _: bool, _: bool); fn i(_: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters } impl S { fn f(&self, _: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters fn g(&self, _: bool, _: bool, _: bool) {} #[no_mangle] extern "C" fn h(_: bool, _: bool, _: bool, _: bool) {} @@ -48,6 +53,8 @@ impl Trait for S { fn main() { fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { + //~^ ERROR: more than 3 bools in function parameters fn nn(_: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters } } diff --git a/tests/ui/fn_params_excessive_bools.stderr b/tests/ui/fn_params_excessive_bools.stderr index 43363b46972c3..db09418cd808e 100644 --- a/tests/ui/fn_params_excessive_bools.stderr +++ b/tests/ui/fn_params_excessive_bools.stderr @@ -8,7 +8,7 @@ LL | fn g(_: bool, _: bool, _: bool, _: bool) {} = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:22:1 + --> $DIR/fn_params_excessive_bools.rs:23:1 | LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:27:5 + --> $DIR/fn_params_excessive_bools.rs:29:5 | LL | fn f(_: bool, _: bool, _: bool, _: bool); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn f(_: bool, _: bool, _: bool, _: bool); = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:31:5 + --> $DIR/fn_params_excessive_bools.rs:34:5 | LL | fn i(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn i(_: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:35:5 + --> $DIR/fn_params_excessive_bools.rs:39:5 | LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,17 +40,19 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:50:5 + --> $DIR/fn_params_excessive_bools.rs:55:5 | LL | / fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { +LL | | LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {} +LL | | LL | | } | |_____^ | = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:51:9 + --> $DIR/fn_params_excessive_bools.rs:57:9 | LL | fn nn(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 05053270c5bc6..09128d8176e08 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -8,17 +8,30 @@ fn foo() -> String { fn test_function_to_numeric_cast() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8`, which truncates the value + //~| NOTE: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16`, which truncates the value let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32`, which truncates the value let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` + //~| NOTE: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8`, which truncates the value let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16`, which truncates the value let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32`, which truncates the value let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` // Casting to usize is OK and should not warn let _ = foo as usize; @@ -32,17 +45,28 @@ fn test_function_var_to_numeric_cast() { let abc: fn() -> String = foo; let _ = abc as i8; + //~^ ERROR: casting function pointer `abc` to `i8`, which truncates the value let _ = abc as i16; + //~^ ERROR: casting function pointer `abc` to `i16`, which truncates the value let _ = abc as i32; + //~^ ERROR: casting function pointer `abc` to `i32`, which truncates the value let _ = abc as i64; + //~^ ERROR: casting function pointer `abc` to `i64` let _ = abc as i128; + //~^ ERROR: casting function pointer `abc` to `i128` let _ = abc as isize; + //~^ ERROR: casting function pointer `abc` to `isize` let _ = abc as u8; + //~^ ERROR: casting function pointer `abc` to `u8`, which truncates the value let _ = abc as u16; + //~^ ERROR: casting function pointer `abc` to `u16`, which truncates the value let _ = abc as u32; + //~^ ERROR: casting function pointer `abc` to `u32`, which truncates the value let _ = abc as u64; + //~^ ERROR: casting function pointer `abc` to `u64` let _ = abc as u128; + //~^ ERROR: casting function pointer `abc` to `u128` // Casting to usize is OK and should not warn let _ = abc as usize; @@ -50,6 +74,7 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 + //~^ ERROR: casting function pointer `f` to `i32`, which truncates the value } fn main() {} diff --git a/tests/ui/fn_to_numeric_cast.stderr b/tests/ui/fn_to_numeric_cast.stderr index e9549e157cd91..5b2e8bdf30b06 100644 --- a/tests/ui/fn_to_numeric_cast.stderr +++ b/tests/ui/fn_to_numeric_cast.stderr @@ -7,19 +7,19 @@ LL | let _ = foo as i8; = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` error: casting function pointer `foo` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:11:13 + --> $DIR/fn_to_numeric_cast.rs:13:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:12:13 + --> $DIR/fn_to_numeric_cast.rs:15:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast.rs:13:13 + --> $DIR/fn_to_numeric_cast.rs:17:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` @@ -27,115 +27,115 @@ LL | let _ = foo as i64; = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast.rs:14:13 + --> $DIR/fn_to_numeric_cast.rs:20:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast.rs:15:13 + --> $DIR/fn_to_numeric_cast.rs:22:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:17:13 + --> $DIR/fn_to_numeric_cast.rs:25:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:18:13 + --> $DIR/fn_to_numeric_cast.rs:27:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:19:13 + --> $DIR/fn_to_numeric_cast.rs:29:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast.rs:20:13 + --> $DIR/fn_to_numeric_cast.rs:31:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast.rs:21:13 + --> $DIR/fn_to_numeric_cast.rs:33:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:34:13 + --> $DIR/fn_to_numeric_cast.rs:47:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:35:13 + --> $DIR/fn_to_numeric_cast.rs:49:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:36:13 + --> $DIR/fn_to_numeric_cast.rs:51:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> $DIR/fn_to_numeric_cast.rs:37:13 + --> $DIR/fn_to_numeric_cast.rs:53:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> $DIR/fn_to_numeric_cast.rs:38:13 + --> $DIR/fn_to_numeric_cast.rs:55:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> $DIR/fn_to_numeric_cast.rs:39:13 + --> $DIR/fn_to_numeric_cast.rs:57:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:41:13 + --> $DIR/fn_to_numeric_cast.rs:60:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:42:13 + --> $DIR/fn_to_numeric_cast.rs:62:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:43:13 + --> $DIR/fn_to_numeric_cast.rs:64:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> $DIR/fn_to_numeric_cast.rs:44:13 + --> $DIR/fn_to_numeric_cast.rs:66:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> $DIR/fn_to_numeric_cast.rs:45:13 + --> $DIR/fn_to_numeric_cast.rs:68:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:52:5 + --> $DIR/fn_to_numeric_cast.rs:76:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/tests/ui/fn_to_numeric_cast_32bit.rs b/tests/ui/fn_to_numeric_cast_32bit.rs index 62ce97f098d4c..93e9361f4dc5b 100644 --- a/tests/ui/fn_to_numeric_cast_32bit.rs +++ b/tests/ui/fn_to_numeric_cast_32bit.rs @@ -8,17 +8,30 @@ fn foo() -> String { fn test_function_to_numeric_cast() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8`, which truncates the value + //~| NOTE: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16`, which truncates the value let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32`, which truncates the value let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` + //~| NOTE: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8`, which truncates the value let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16`, which truncates the value let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32`, which truncates the value let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` // Casting to usize is OK and should not warn let _ = foo as usize; @@ -32,17 +45,28 @@ fn test_function_var_to_numeric_cast() { let abc: fn() -> String = foo; let _ = abc as i8; + //~^ ERROR: casting function pointer `abc` to `i8`, which truncates the value let _ = abc as i16; + //~^ ERROR: casting function pointer `abc` to `i16`, which truncates the value let _ = abc as i32; + //~^ ERROR: casting function pointer `abc` to `i32`, which truncates the value let _ = abc as i64; + //~^ ERROR: casting function pointer `abc` to `i64` let _ = abc as i128; + //~^ ERROR: casting function pointer `abc` to `i128` let _ = abc as isize; + //~^ ERROR: casting function pointer `abc` to `isize` let _ = abc as u8; + //~^ ERROR: casting function pointer `abc` to `u8`, which truncates the value let _ = abc as u16; + //~^ ERROR: casting function pointer `abc` to `u16`, which truncates the value let _ = abc as u32; + //~^ ERROR: casting function pointer `abc` to `u32`, which truncates the value let _ = abc as u64; + //~^ ERROR: casting function pointer `abc` to `u64` let _ = abc as u128; + //~^ ERROR: casting function pointer `abc` to `u128` // Casting to usize is OK and should not warn let _ = abc as usize; @@ -50,6 +74,7 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 + //~^ ERROR: casting function pointer `f` to `i32`, which truncates the value } fn main() {} diff --git a/tests/ui/fn_to_numeric_cast_any.rs b/tests/ui/fn_to_numeric_cast_any.rs index b77aefd38e590..95abc0ac68dd5 100644 --- a/tests/ui/fn_to_numeric_cast_any.rs +++ b/tests/ui/fn_to_numeric_cast_any.rs @@ -21,40 +21,58 @@ impl Trait for Struct {} fn fn_pointer_to_integer() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8` + //~| NOTE: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16` let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32` let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8` let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16` let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32` let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` let _ = foo as usize; + //~^ ERROR: casting function pointer `foo` to `usize` } fn static_method_to_integer() { let _ = Struct::static_method as usize; + //~^ ERROR: casting function pointer `Struct::static_method` to `usize` } fn fn_with_fn_arg(f: fn(i32) -> u32) -> usize { f as usize + //~^ ERROR: casting function pointer `f` to `usize` } fn fn_with_generic_static_trait_method() -> usize { T::static_method as usize + //~^ ERROR: casting function pointer `T::static_method` to `usize` } fn closure_to_fn_to_integer() { let clos = |x| x * 2_u32; let _ = (clos as fn(u32) -> u32) as usize; + //~^ ERROR: casting function pointer `(clos as fn(u32) -> u32)` to `usize` } fn fn_to_raw_ptr() { let _ = foo as *const (); + //~^ ERROR: casting function pointer `foo` to `*const ()` } fn cast_fn_to_self() { diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index a6c4a77672f86..36058965479c0 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -7,97 +7,97 @@ LL | let _ = foo as i8; = note: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` error: casting function pointer `foo` to `i16` - --> $DIR/fn_to_numeric_cast_any.rs:24:13 + --> $DIR/fn_to_numeric_cast_any.rs:26:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i16` error: casting function pointer `foo` to `i32` - --> $DIR/fn_to_numeric_cast_any.rs:25:13 + --> $DIR/fn_to_numeric_cast_any.rs:28:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i32` error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast_any.rs:26:13 + --> $DIR/fn_to_numeric_cast_any.rs:30:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i64` error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast_any.rs:27:13 + --> $DIR/fn_to_numeric_cast_any.rs:32:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i128` error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast_any.rs:28:13 + --> $DIR/fn_to_numeric_cast_any.rs:34:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as isize` error: casting function pointer `foo` to `u8` - --> $DIR/fn_to_numeric_cast_any.rs:30:13 + --> $DIR/fn_to_numeric_cast_any.rs:37:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u8` error: casting function pointer `foo` to `u16` - --> $DIR/fn_to_numeric_cast_any.rs:31:13 + --> $DIR/fn_to_numeric_cast_any.rs:39:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u16` error: casting function pointer `foo` to `u32` - --> $DIR/fn_to_numeric_cast_any.rs:32:13 + --> $DIR/fn_to_numeric_cast_any.rs:41:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u32` error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast_any.rs:33:13 + --> $DIR/fn_to_numeric_cast_any.rs:43:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u64` error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast_any.rs:34:13 + --> $DIR/fn_to_numeric_cast_any.rs:45:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u128` error: casting function pointer `foo` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:35:13 + --> $DIR/fn_to_numeric_cast_any.rs:47:13 | LL | let _ = foo as usize; | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as usize` error: casting function pointer `Struct::static_method` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:39:13 + --> $DIR/fn_to_numeric_cast_any.rs:52:13 | LL | let _ = Struct::static_method as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `Struct::static_method() as usize` error: casting function pointer `f` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:43:5 + --> $DIR/fn_to_numeric_cast_any.rs:57:5 | LL | f as usize | ^^^^^^^^^^ help: did you mean to invoke the function?: `f() as usize` error: casting function pointer `T::static_method` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:47:5 + --> $DIR/fn_to_numeric_cast_any.rs:62:5 | LL | T::static_method as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `T::static_method() as usize` error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:53:13 + --> $DIR/fn_to_numeric_cast_any.rs:69:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `(clos as fn(u32) -> u32)() as usize` error: casting function pointer `foo` to `*const ()` - --> $DIR/fn_to_numeric_cast_any.rs:57:13 + --> $DIR/fn_to_numeric_cast_any.rs:74:13 | LL | let _ = foo as *const (); | ^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as *const ()` diff --git a/tests/ui/for_kv_map.fixed b/tests/ui/for_kv_map.fixed index 703ae98e8ed57..a2112d7b73005 100644 --- a/tests/ui/for_kv_map.fixed +++ b/tests/ui/for_kv_map.fixed @@ -7,11 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for v in m.values() { + //~^ ERROR: you seem to want to iterate on a map's values + //~| NOTE: `-D clippy::for-kv-map` implied by `-D warnings` let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for v in (*m).values() { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -20,17 +23,20 @@ fn main() { let mut m: HashMap = HashMap::new(); for v in m.values_mut() { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for v in (*m).values_mut() { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: HashMap = HashMap::new(); let rm = &m; for k in rm.keys() { + //~^ ERROR: you seem to want to iterate on a map's keys let _k = k; } diff --git a/tests/ui/for_kv_map.rs b/tests/ui/for_kv_map.rs index 39a8d960a7e91..1b7959b8f92d6 100644 --- a/tests/ui/for_kv_map.rs +++ b/tests/ui/for_kv_map.rs @@ -7,11 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for (_, v) in &m { + //~^ ERROR: you seem to want to iterate on a map's values + //~| NOTE: `-D clippy::for-kv-map` implied by `-D warnings` let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for (_, v) in &*m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -20,17 +23,20 @@ fn main() { let mut m: HashMap = HashMap::new(); for (_, v) in &mut m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for (_, v) in &mut *m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: HashMap = HashMap::new(); let rm = &m; for (k, _value) in rm { + //~^ ERROR: you seem to want to iterate on a map's keys let _k = k; } diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index e5cc7c1466ab4..d5e4ef0b4ba36 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -11,7 +11,7 @@ LL | for v in m.values() { | ~ ~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:14:19 + --> $DIR/for_kv_map.rs:16:19 | LL | for (_, v) in &*m { | ^^^ @@ -22,7 +22,7 @@ LL | for v in (*m).values() { | ~ ~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:22:19 + --> $DIR/for_kv_map.rs:25:19 | LL | for (_, v) in &mut m { | ^^^^^^ @@ -33,7 +33,7 @@ LL | for v in m.values_mut() { | ~ ~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:27:19 + --> $DIR/for_kv_map.rs:31:19 | LL | for (_, v) in &mut *m { | ^^^^^^^ @@ -44,7 +44,7 @@ LL | for v in (*m).values_mut() { | ~ ~~~~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> $DIR/for_kv_map.rs:33:24 + --> $DIR/for_kv_map.rs:38:24 | LL | for (k, _value) in rm { | ^^ diff --git a/tests/ui/forget_non_drop.rs b/tests/ui/forget_non_drop.rs index 7580cf95ebfa8..2459f51a38dac 100644 --- a/tests/ui/forget_non_drop.rs +++ b/tests/ui/forget_non_drop.rs @@ -11,6 +11,7 @@ fn main() { struct Foo; // Lint forget(Foo); + //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo struct Bar; impl Drop for Bar { @@ -22,6 +23,7 @@ fn main() { struct Baz(T); // Lint forget(Baz(Foo)); + //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo // Don't lint forget(Baz(Bar)); } diff --git a/tests/ui/forget_non_drop.stderr b/tests/ui/forget_non_drop.stderr index 194e37c8b4247..4634dc67f02db 100644 --- a/tests/ui/forget_non_drop.stderr +++ b/tests/ui/forget_non_drop.stderr @@ -12,13 +12,13 @@ LL | forget(Foo); = note: `-D clippy::forget-non-drop` implied by `-D warnings` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it - --> $DIR/forget_non_drop.rs:24:5 + --> $DIR/forget_non_drop.rs:25:5 | LL | forget(Baz(Foo)); | ^^^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> $DIR/forget_non_drop.rs:24:12 + --> $DIR/forget_non_drop.rs:25:12 | LL | forget(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/format_args_unfixable.rs b/tests/ui/format_args_unfixable.rs index 423bfaf97965e..b7492e38b256b 100644 --- a/tests/ui/format_args_unfixable.rs +++ b/tests/ui/format_args_unfixable.rs @@ -24,31 +24,49 @@ fn main() { let x = 'x'; println!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{}: {}", error, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{{}}: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("error: {}", format!("something failed at {} {0}", Location::caller())); + //~^ ERROR: `format!` in `println!` args let _ = format!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `format!` args let _ = write!( + //~^ ERROR: `format!` in `write!` args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); let _ = writeln!( + //~^ ERROR: `format!` in `writeln!` args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); print!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `print!` args eprint!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `eprint!` args eprintln!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `eprintln!` args let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `format_args!` args assert!(true, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert!` args assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert_eq!` args assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert_ne!` args panic!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `panic!` args // negative tests println!("error: {}", format_args!("something failed at {}", Location::caller())); diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr index c1be48c3b7269..430c435957931 100644 --- a/tests/ui/format_args_unfixable.stderr +++ b/tests/ui/format_args_unfixable.stderr @@ -9,7 +9,7 @@ LL | println!("error: {}", format!("something failed at {}", Location::calle = note: `-D clippy::format-in-format-args` implied by `-D warnings` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:27:5 + --> $DIR/format_args_unfixable.rs:28:5 | LL | println!("{}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | println!("{}: {}", error, format!("something failed at {}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:28:5 + --> $DIR/format_args_unfixable.rs:30:5 | LL | println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | println!("{:?}: {}", error, format!("something failed at {}", Location: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:29:5 + --> $DIR/format_args_unfixable.rs:32:5 | LL | println!("{{}}: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | println!("{{}}: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:30:5 + --> $DIR/format_args_unfixable.rs:34:5 | LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | println!(r#"error: "{}""#, format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:31:5 + --> $DIR/format_args_unfixable.rs:36:5 | LL | println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | println!("error: {}", format!(r#"something failed at "{}""#, Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:32:5 + --> $DIR/format_args_unfixable.rs:38:5 | LL | println!("error: {}", format!("something failed at {} {0}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | println!("error: {}", format!("something failed at {} {0}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `format!` args - --> $DIR/format_args_unfixable.rs:33:13 + --> $DIR/format_args_unfixable.rs:40:13 | LL | let _ = format!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,10 +72,11 @@ LL | let _ = format!("error: {}", format!("something failed at {}", Location = help: or consider changing `format!` to `format_args!` error: `format!` in `write!` args - --> $DIR/format_args_unfixable.rs:34:13 + --> $DIR/format_args_unfixable.rs:42:13 | LL | let _ = write!( | _____________^ +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -86,10 +87,11 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `writeln!` args - --> $DIR/format_args_unfixable.rs:39:13 + --> $DIR/format_args_unfixable.rs:48:13 | LL | let _ = writeln!( | _____________^ +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -100,7 +102,7 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `print!` args - --> $DIR/format_args_unfixable.rs:44:5 + --> $DIR/format_args_unfixable.rs:54:5 | LL | print!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +111,7 @@ LL | print!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `eprint!` args - --> $DIR/format_args_unfixable.rs:45:5 + --> $DIR/format_args_unfixable.rs:56:5 | LL | eprint!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +120,7 @@ LL | eprint!("error: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `eprintln!` args - --> $DIR/format_args_unfixable.rs:46:5 + --> $DIR/format_args_unfixable.rs:58:5 | LL | eprintln!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -127,7 +129,7 @@ LL | eprintln!("error: {}", format!("something failed at {}", Location::call = help: or consider changing `format!` to `format_args!` error: `format!` in `format_args!` args - --> $DIR/format_args_unfixable.rs:47:13 + --> $DIR/format_args_unfixable.rs:60:13 | LL | let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +138,7 @@ LL | let _ = format_args!("error: {}", format!("something failed at {}", Loc = help: or consider changing `format!` to `format_args!` error: `format!` in `assert!` args - --> $DIR/format_args_unfixable.rs:48:5 + --> $DIR/format_args_unfixable.rs:62:5 | LL | assert!(true, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +147,7 @@ LL | assert!(true, "error: {}", format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_eq!` args - --> $DIR/format_args_unfixable.rs:49:5 + --> $DIR/format_args_unfixable.rs:64:5 | LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +156,7 @@ LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Locatio = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_ne!` args - --> $DIR/format_args_unfixable.rs:50:5 + --> $DIR/format_args_unfixable.rs:66:5 | LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +165,7 @@ LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Locatio = help: or consider changing `format!` to `format_args!` error: `format!` in `panic!` args - --> $DIR/format_args_unfixable.rs:51:5 + --> $DIR/format_args_unfixable.rs:68:5 | LL | panic!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_collect.rs b/tests/ui/format_collect.rs index c7f2b7b695074..26ebdc6c0cb61 100644 --- a/tests/ui/format_collect.rs +++ b/tests/ui/format_collect.rs @@ -3,11 +3,13 @@ fn hex_encode(bytes: &[u8]) -> String { bytes.iter().map(|b| format!("{b:02X}")).collect() + //~^ ERROR: use of `format!` to build up a string from an iterator } #[rustfmt::skip] fn hex_encode_deep(bytes: &[u8]) -> String { bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() + //~^ ERROR: use of `format!` to build up a string from an iterator } macro_rules! fmt { @@ -22,6 +24,7 @@ fn from_macro(bytes: &[u8]) -> String { fn with_block() -> String { (1..10) + //~^ ERROR: use of `format!` to build up a string from an iterator .map(|s| { let y = 1; format!("{s} {y}") diff --git a/tests/ui/format_collect.stderr b/tests/ui/format_collect.stderr index d918f1ed466b1..79e353111f387 100644 --- a/tests/ui/format_collect.stderr +++ b/tests/ui/format_collect.stderr @@ -18,27 +18,28 @@ LL | bytes.iter().map(|b| format!("{b:02X}")).collect() = note: `-D clippy::format-collect` implied by `-D warnings` error: use of `format!` to build up a string from an iterator - --> $DIR/format_collect.rs:10:5 + --> $DIR/format_collect.rs:11:5 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: call `fold` instead - --> $DIR/format_collect.rs:10:18 + --> $DIR/format_collect.rs:11:18 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^ help: ... and use the `write!` macro here - --> $DIR/format_collect.rs:10:32 + --> $DIR/format_collect.rs:11:32 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^ = note: this can be written more efficiently by appending to a `String` directly error: use of `format!` to build up a string from an iterator - --> $DIR/format_collect.rs:24:5 + --> $DIR/format_collect.rs:26:5 | LL | / (1..10) +LL | | LL | | .map(|s| { LL | | let y = 1; LL | | format!("{s} {y}") @@ -47,12 +48,12 @@ LL | | .collect() | |__________________^ | help: call `fold` instead - --> $DIR/format_collect.rs:25:10 + --> $DIR/format_collect.rs:28:10 | LL | .map(|s| { | ^^^ help: ... and use the `write!` macro here - --> $DIR/format_collect.rs:27:13 + --> $DIR/format_collect.rs:30:13 | LL | format!("{s} {y}") | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_push_string.rs b/tests/ui/format_push_string.rs index 89423ffe1cf8c..735ae3393289e 100644 --- a/tests/ui/format_push_string.rs +++ b/tests/ui/format_push_string.rs @@ -3,7 +3,9 @@ fn main() { let mut string = String::new(); string += &format!("{:?}", 1234); + //~^ ERROR: `format!(..)` appended to existing `String` string.push_str(&format!("{:?}", 5678)); + //~^ ERROR: `format!(..)` appended to existing `String` } mod issue9493 { @@ -11,6 +13,7 @@ mod issue9493 { let mut hex = String::with_capacity(vector.len() * 2); for byte in vector { hex += &(if upper { + //~^ ERROR: `format!(..)` appended to existing `String` format!("{byte:02X}") } else { format!("{byte:02x}") @@ -23,12 +26,14 @@ mod issue9493 { let mut s = String::new(); // if let s += &(if let Some(_a) = Some(1234) { + //~^ ERROR: `format!(..)` appended to existing `String` format!("{}", 1234) } else { format!("{}", 1234) }); // match s += &(match Some(1234) { + //~^ ERROR: `format!(..)` appended to existing `String` Some(_) => format!("{}", 1234), None => format!("{}", 1234), }); diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr index 76762c4a1d1f7..d862dd6dc5f36 100644 --- a/tests/ui/format_push_string.stderr +++ b/tests/ui/format_push_string.stderr @@ -8,7 +8,7 @@ LL | string += &format!("{:?}", 1234); = note: `-D clippy::format-push-string` implied by `-D warnings` error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:6:5 + --> $DIR/format_push_string.rs:7:5 | LL | string.push_str(&format!("{:?}", 5678)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,9 +16,10 @@ LL | string.push_str(&format!("{:?}", 5678)); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:13:13 + --> $DIR/format_push_string.rs:15:13 | LL | / hex += &(if upper { +LL | | LL | | format!("{byte:02X}") LL | | } else { LL | | format!("{byte:02x}") @@ -28,9 +29,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:25:9 + --> $DIR/format_push_string.rs:28:9 | LL | / s += &(if let Some(_a) = Some(1234) { +LL | | LL | | format!("{}", 1234) LL | | } else { LL | | format!("{}", 1234) @@ -40,9 +42,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:31:9 + --> $DIR/format_push_string.rs:35:9 | LL | / s += &(match Some(1234) { +LL | | LL | | Some(_) => format!("{}", 1234), LL | | None => format!("{}", 1234), LL | | }); diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 471a8e0de6e19..312fa2aa40ad2 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -14,10 +14,16 @@ fn main() { // weird op_eq formatting: let mut a = 42; a =- 35; + //~^ ERROR: this looks like you are trying to use `.. -= ..`, but you really are doing + //~| NOTE: to remove this lint, use either `-=` or `= -` a =* &191; + //~^ ERROR: this looks like you are trying to use `.. *= ..`, but you really are doing + //~| NOTE: to remove this lint, use either `*=` or `= *` let mut b = true; b =! false; + //~^ ERROR: this looks like you are trying to use `.. != ..`, but you really are doing + //~| NOTE: to remove this lint, use either `!=` or `= !` // those are ok: a = -35; @@ -27,10 +33,14 @@ fn main() { // possible missing comma in an array let _ = &[ -1, -2, -3 // <= no comma here + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line -4, -5, -6 ]; let _ = &[ -1, -2, -3 // <= no comma here + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line *4, -5, -6 ]; @@ -68,6 +78,8 @@ fn main() { // lint if it doesn't let _ = &[ -1 + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line -4, ]; } diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index caccd5cba1784..1266d143cb165 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -8,7 +8,7 @@ LL | a =- 35; = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` - --> $DIR/formatting.rs:17:6 + --> $DIR/formatting.rs:19:6 | LL | a =* &191; | ^^^^ @@ -16,7 +16,7 @@ LL | a =* &191; = note: to remove this lint, use either `*=` or `= *` error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)` - --> $DIR/formatting.rs:20:6 + --> $DIR/formatting.rs:24:6 | LL | b =! false; | ^^^^ @@ -24,7 +24,7 @@ LL | b =! false; = note: to remove this lint, use either `!=` or `= !` error: possibly missing a comma here - --> $DIR/formatting.rs:29:19 + --> $DIR/formatting.rs:35:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -33,7 +33,7 @@ LL | -1, -2, -3 // <= no comma here = note: `-D clippy::possible-missing-comma` implied by `-D warnings` error: possibly missing a comma here - --> $DIR/formatting.rs:33:19 + --> $DIR/formatting.rs:41:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -41,7 +41,7 @@ LL | -1, -2, -3 // <= no comma here = note: to remove this lint, add a comma or write the expr in a single line error: possibly missing a comma here - --> $DIR/formatting.rs:70:11 + --> $DIR/formatting.rs:80:11 | LL | -1 | ^ diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index c769e38eb33a0..0c1f39f93fd33 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -9,6 +9,7 @@ macro_rules! in_macro { } impl Into for String { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> InMacro { InMacro(in_macro!()) } @@ -17,6 +18,7 @@ impl Into for String { struct WeirdUpperSelf; impl Into for &'static [u8] { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> WeirdUpperSelf { let _ = Self::default(); WeirdUpperSelf @@ -26,6 +28,7 @@ impl Into for &'static [u8] { struct ContainsVal; impl Into for ContainsVal { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> u8 { let val = 1; val + 1 @@ -37,6 +40,7 @@ pub struct Lval(T); pub struct Rval(T); impl Into> for Lval { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> Rval { Rval(self) } diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr index 2ab9b9d6b17cc..3470eff9e9585 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -8,7 +8,7 @@ LL | impl Into for String { = note: `-D clippy::from-over-into` implied by `-D warnings` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:19:1 + --> $DIR/from_over_into_unfixable.rs:20:1 | LL | impl Into for &'static [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | impl Into for &'static [u8] { = help: replace the `Into` implementation with `From<&'static [u8]>` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:28:1 + --> $DIR/from_over_into_unfixable.rs:30:1 | LL | impl Into for ContainsVal { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | impl Into for ContainsVal { = help: replace the `Into` implementation with `From` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:39:1 + --> $DIR/from_over_into_unfixable.rs:42:1 | LL | impl Into> for Lval { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/from_raw_with_void_ptr.rs b/tests/ui/from_raw_with_void_ptr.rs index 95ef6425fad9a..81472070eb4ce 100644 --- a/tests/ui/from_raw_with_void_ptr.rs +++ b/tests/ui/from_raw_with_void_ptr.rs @@ -9,6 +9,7 @@ fn main() { // must lint let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void; let _ = unsafe { Box::from_raw(ptr) }; + //~^ ERROR: creating a `Box` from a void raw pointer // shouldn't be linted let _ = unsafe { Box::from_raw(ptr as *mut usize) }; @@ -20,16 +21,20 @@ fn main() { // must lint let ptr = Rc::into_raw(Rc::new(42usize)) as *mut c_void; let _ = unsafe { Rc::from_raw(ptr) }; + //~^ ERROR: creating a `Rc` from a void raw pointer // must lint let ptr = Arc::into_raw(Arc::new(42usize)) as *mut c_void; let _ = unsafe { Arc::from_raw(ptr) }; + //~^ ERROR: creating a `Arc` from a void raw pointer // must lint let ptr = std::rc::Weak::into_raw(Rc::downgrade(&Rc::new(42usize))) as *mut c_void; let _ = unsafe { std::rc::Weak::from_raw(ptr) }; + //~^ ERROR: creating a `Weak` from a void raw pointer // must lint let ptr = std::sync::Weak::into_raw(Arc::downgrade(&Arc::new(42usize))) as *mut c_void; let _ = unsafe { std::sync::Weak::from_raw(ptr) }; + //~^ ERROR: creating a `Weak` from a void raw pointer } diff --git a/tests/ui/from_raw_with_void_ptr.stderr b/tests/ui/from_raw_with_void_ptr.stderr index 1963d08014b15..b6460862419d3 100644 --- a/tests/ui/from_raw_with_void_ptr.stderr +++ b/tests/ui/from_raw_with_void_ptr.stderr @@ -12,49 +12,49 @@ LL | let _ = unsafe { Box::from_raw(ptr) }; = note: `-D clippy::from-raw-with-void-ptr` implied by `-D warnings` error: creating a `Rc` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:22:22 + --> $DIR/from_raw_with_void_ptr.rs:23:22 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:22:35 + --> $DIR/from_raw_with_void_ptr.rs:23:35 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^ error: creating a `Arc` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:26:22 + --> $DIR/from_raw_with_void_ptr.rs:28:22 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:26:36 + --> $DIR/from_raw_with_void_ptr.rs:28:36 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:30:22 + --> $DIR/from_raw_with_void_ptr.rs:33:22 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:30:46 + --> $DIR/from_raw_with_void_ptr.rs:33:46 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:34:22 + --> $DIR/from_raw_with_void_ptr.rs:38:22 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:34:48 + --> $DIR/from_raw_with_void_ptr.rs:38:48 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^ diff --git a/tests/ui/from_str_radix_10.fixed b/tests/ui/from_str_radix_10.fixed index b0fb88f988ada..8c253bfd99a57 100644 --- a/tests/ui/from_str_radix_10.fixed +++ b/tests/ui/from_str_radix_10.fixed @@ -26,17 +26,26 @@ impl std::ops::Add for Test { fn main() -> Result<(), Box> { // all of these should trigger the lint "30".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings` "24".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` "100".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` "7".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` ("10".to_owned() + "5").parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` (Test + Test).parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let string = "300"; string.parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let stringier = "400".to_string(); stringier.parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` // none of these should trigger the lint u16::from_str_radix("20", 3)?; diff --git a/tests/ui/from_str_radix_10.rs b/tests/ui/from_str_radix_10.rs index 2f2ea04847a98..e9d02215710cb 100644 --- a/tests/ui/from_str_radix_10.rs +++ b/tests/ui/from_str_radix_10.rs @@ -26,17 +26,26 @@ impl std::ops::Add for Test { fn main() -> Result<(), Box> { // all of these should trigger the lint u32::from_str_radix("30", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings` i64::from_str_radix("24", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` isize::from_str_radix("100", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` u8::from_str_radix("7", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` u16::from_str_radix(&("10".to_owned() + "5"), 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` i128::from_str_radix(Test + Test, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let string = "300"; i32::from_str_radix(string, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let stringier = "400".to_string(); i32::from_str_radix(&stringier, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` // none of these should trigger the lint u16::from_str_radix("20", 3)?; diff --git a/tests/ui/from_str_radix_10.stderr b/tests/ui/from_str_radix_10.stderr index da5c16f8d01a8..1fbd1e3a5f20d 100644 --- a/tests/ui/from_str_radix_10.stderr +++ b/tests/ui/from_str_radix_10.stderr @@ -7,43 +7,43 @@ LL | u32::from_str_radix("30", 10)?; = note: `-D clippy::from-str-radix-10` implied by `-D warnings` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:29:5 + --> $DIR/from_str_radix_10.rs:31:5 | LL | i64::from_str_radix("24", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"24".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:30:5 + --> $DIR/from_str_radix_10.rs:33:5 | LL | isize::from_str_radix("100", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"100".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:31:5 + --> $DIR/from_str_radix_10.rs:35:5 | LL | u8::from_str_radix("7", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"7".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:32:5 + --> $DIR/from_str_radix_10.rs:37:5 | LL | u16::from_str_radix(&("10".to_owned() + "5"), 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("10".to_owned() + "5").parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:33:5 + --> $DIR/from_str_radix_10.rs:39:5 | LL | i128::from_str_radix(Test + Test, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(Test + Test).parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:36:5 + --> $DIR/from_str_radix_10.rs:43:5 | LL | i32::from_str_radix(string, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:39:5 + --> $DIR/from_str_radix_10.rs:47:5 | LL | i32::from_str_radix(&stringier, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `stringier.parse::()` diff --git a/tests/ui/functions.rs b/tests/ui/functions.rs index 18149bfbc3fe0..0aef60959593b 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -6,9 +6,12 @@ fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} +//~^ ERROR: this function has too many arguments (8/7) +//~| NOTE: `-D clippy::too-many-arguments` implied by `-D warnings` #[rustfmt::skip] fn bad_multiline( +//~^ ERROR: this function has too many arguments (8/7) one: u32, two: u32, three: &str, @@ -43,6 +46,7 @@ extern "C" fn extern_fn( pub trait Foo { fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool); fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); + //~^ ERROR: this function has too many arguments (8/7) fn ptr(p: *const u8); } @@ -52,6 +56,7 @@ pub struct Bar; impl Bar { fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} + //~^ ERROR: this function has too many arguments (8/7) } // ok, we don’t want to warn implementations @@ -61,8 +66,12 @@ impl Foo for Bar { fn ptr(p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~| NOTE: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked } } @@ -74,16 +83,22 @@ fn private(p: *const u8) { pub fn public(p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un } type Alias = *const u8; pub fn type_alias(p: Alias) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un } impl Bar { @@ -93,8 +108,11 @@ impl Bar { pub fn public(self, p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked } pub fn public_ok(self, p: *const u8) { diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index 8ebd4997f4f6e..fb8f4511e9951 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -7,31 +7,31 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f = note: `-D clippy::too-many-arguments` implied by `-D warnings` error: this function has too many arguments (8/7) - --> $DIR/functions.rs:11:1 + --> $DIR/functions.rs:13:1 | LL | / fn bad_multiline( +LL | | LL | | one: u32, LL | | two: u32, -LL | | three: &str, ... | LL | | eight: () LL | | ) { | |__^ error: this function has too many arguments (8/7) - --> $DIR/functions.rs:45:5 + --> $DIR/functions.rs:48:5 | LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this function has too many arguments (8/7) - --> $DIR/functions.rs:54:5 + --> $DIR/functions.rs:58:5 | LL | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:63:34 + --> $DIR/functions.rs:68:34 | LL | println!("{}", unsafe { *p }); | ^ @@ -39,67 +39,67 @@ LL | println!("{}", unsafe { *p }); = note: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:64:35 + --> $DIR/functions.rs:71:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:65:33 + --> $DIR/functions.rs:73:33 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:76:30 + --> $DIR/functions.rs:85:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:77:31 + --> $DIR/functions.rs:87:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:78:29 + --> $DIR/functions.rs:89:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:84:30 + --> $DIR/functions.rs:96:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:85:31 + --> $DIR/functions.rs:98:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:86:29 + --> $DIR/functions.rs:100:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:95:34 + --> $DIR/functions.rs:110:34 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:96:35 + --> $DIR/functions.rs:112:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:97:33 + --> $DIR/functions.rs:114:33 | LL | unsafe { std::ptr::read(p) }; | ^ diff --git a/tests/ui/functions_maxlines.rs b/tests/ui/functions_maxlines.rs index 5e1ee55e01040..a3496f56d4a62 100644 --- a/tests/ui/functions_maxlines.rs +++ b/tests/ui/functions_maxlines.rs @@ -56,6 +56,8 @@ fn good_lines() { } fn bad_lines() { + //~^ ERROR: this function has too many lines (102/100) + //~| NOTE: `-D clippy::too-many-lines` implied by `-D warnings` println!("Dont get confused by braces: {{}}"); println!("This is bad."); println!("This is bad."); diff --git a/tests/ui/functions_maxlines.stderr b/tests/ui/functions_maxlines.stderr index dc6c8ba2f154d..6551892363c49 100644 --- a/tests/ui/functions_maxlines.stderr +++ b/tests/ui/functions_maxlines.stderr @@ -2,9 +2,9 @@ error: this function has too many lines (102/100) --> $DIR/functions_maxlines.rs:58:1 | LL | / fn bad_lines() { +LL | | +LL | | LL | | println!("Dont get confused by braces: {{}}"); -LL | | println!("This is bad."); -LL | | println!("This is bad."); ... | LL | | println!("This is bad."); LL | | } diff --git a/tests/ui/future_not_send.rs b/tests/ui/future_not_send.rs index 858036692d68f..06090e2713dee 100644 --- a/tests/ui/future_not_send.rs +++ b/tests/ui/future_not_send.rs @@ -5,10 +5,12 @@ use std::rc::Rc; use std::sync::Arc; async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { + //~^ ERROR: future cannot be sent between threads safely async { true }.await } pub async fn public_future(rc: Rc<[u8]>) { + //~^ ERROR: future cannot be sent between threads safely async { true }.await; } @@ -17,10 +19,12 @@ pub async fn public_send(arc: Arc<[u8]>) -> bool { } async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { + //~^ ERROR: future cannot be sent between threads safely true } pub async fn public_future2(rc: Rc<[u8]>) {} +//~^ ERROR: future cannot be sent between threads safely pub async fn public_send2(arc: Arc<[u8]>) -> bool { false @@ -32,11 +36,13 @@ struct Dummy { impl Dummy { async fn private_future(&self) -> usize { + //~^ ERROR: future cannot be sent between threads safely async { true }.await; self.rc.len() } pub async fn public_future(&self) { + //~^ ERROR: future cannot be sent between threads safely self.private_future().await; } @@ -47,6 +53,7 @@ impl Dummy { } async fn generic_future(t: T) -> T +//~^ ERROR: future cannot be sent between threads safely where T: Send, { @@ -63,6 +70,7 @@ where } async fn unclear_future(t: T) {} +//~^ ERROR: future cannot be sent between threads safely fn main() { let rc = Rc::new([1, 2, 3]); diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 5c6348962a5eb..9628cf3a1b952 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -5,20 +5,22 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:20 + --> $DIR/future_not_send.rs:9:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | -- has type `std::rc::Rc<[u8]>` which is not `Send` +LL | LL | async { true }.await | ^^^^^ await occurs here, with `rc` maybe used later LL | } | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:20 + --> $DIR/future_not_send.rs:9:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ---- has type `&std::cell::Cell` which is not `Send` +LL | LL | async { true }.await | ^^^^^ await occurs here, with `cell` maybe used later LL | } @@ -27,16 +29,17 @@ LL | } = note: `-D clippy::future-not-send` implied by `-D warnings` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:11:42 + --> $DIR/future_not_send.rs:12:42 | LL | pub async fn public_future(rc: Rc<[u8]>) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:12:20 + --> $DIR/future_not_send.rs:14:20 | LL | pub async fn public_future(rc: Rc<[u8]>) { | -- has type `std::rc::Rc<[u8]>` which is not `Send` +LL | LL | async { true }.await; | ^^^^^ await occurs here, with `rc` maybe used later LL | } @@ -44,48 +47,49 @@ LL | } = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:19:63 + --> $DIR/future_not_send.rs:21:63 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future2` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:19:26 + --> $DIR/future_not_send.rs:21:26 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` - --> $DIR/future_not_send.rs:19:40 + --> $DIR/future_not_send.rs:21:40 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ has type `&std::cell::Cell` which is not `Send`, because `std::cell::Cell` is not `Sync` = note: `std::cell::Cell` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:23:43 + --> $DIR/future_not_send.rs:26:43 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^ future returned by `public_future2` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:23:29 + --> $DIR/future_not_send.rs:26:29 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:34:39 + --> $DIR/future_not_send.rs:38:39 | LL | async fn private_future(&self) -> usize { | ^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:35:24 + --> $DIR/future_not_send.rs:40:24 | LL | async fn private_future(&self) -> usize { | ----- has type `&Dummy` which is not `Send` +LL | LL | async { true }.await; | ^^^^^ await occurs here, with `&self` maybe used later LL | self.rc.len() @@ -94,16 +98,17 @@ LL | } = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:39:39 + --> $DIR/future_not_send.rs:44:39 | LL | pub async fn public_future(&self) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:40:31 + --> $DIR/future_not_send.rs:46:31 | LL | pub async fn public_future(&self) { | ----- has type `&Dummy` which is not `Send` +LL | LL | self.private_future().await; | ^^^^^ await occurs here, with `&self` maybe used later LL | } @@ -111,13 +116,13 @@ LL | } = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:49:37 + --> $DIR/future_not_send.rs:55:37 | LL | async fn generic_future(t: T) -> T | ^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:54:20 + --> $DIR/future_not_send.rs:61:20 | LL | let rt = &t; | -- has type `&T` which is not `Send` @@ -129,13 +134,13 @@ LL | } = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:65:34 + --> $DIR/future_not_send.rs:72:34 | LL | async fn unclear_future(t: T) {} | ^ future returned by `unclear_future` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:65:28 + --> $DIR/future_not_send.rs:72:28 | LL | async fn unclear_future(t: T) {} | ^ has type `T` which is not `Send` diff --git a/tests/ui/if_let_mutex.rs b/tests/ui/if_let_mutex.rs index 321feb0224ed1..cb6915e0ebaaa 100644 --- a/tests/ui/if_let_mutex.rs +++ b/tests/ui/if_let_mutex.rs @@ -8,6 +8,7 @@ fn do_stuff(_: T) {} fn if_let() { let m = Mutex::new(1_u8); if let Err(locked) = m.lock() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(locked); } else { let lock = m.lock().unwrap(); @@ -20,6 +21,7 @@ fn if_let() { fn if_let_option() { let m = Mutex::new(Some(0_u8)); if let Some(locked) = m.lock().unwrap().deref() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(locked); } else { let lock = m.lock().unwrap(); @@ -41,6 +43,7 @@ fn if_let_different_mutex() { fn mutex_ref(mutex: &Mutex) { if let Ok(i) = mutex.lock() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(i); } else { let _x = mutex.lock(); diff --git a/tests/ui/if_let_mutex.stderr b/tests/ui/if_let_mutex.stderr index da0cc25f0ab52..6bbaadbe85539 100644 --- a/tests/ui/if_let_mutex.stderr +++ b/tests/ui/if_let_mutex.stderr @@ -5,6 +5,7 @@ LL | if let Err(locked) = m.lock() { | ^ - this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(locked); LL | | } else { LL | | let lock = m.lock().unwrap(); @@ -17,12 +18,13 @@ LL | | }; = note: `-D clippy::if-let-mutex` implied by `-D warnings` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:22:5 + --> $DIR/if_let_mutex.rs:23:5 | LL | if let Some(locked) = m.lock().unwrap().deref() { | ^ - this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(locked); LL | | } else { LL | | let lock = m.lock().unwrap(); @@ -34,12 +36,13 @@ LL | | }; = help: move the lock call outside of the `if let ...` expression error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:43:5 + --> $DIR/if_let_mutex.rs:45:5 | LL | if let Ok(i) = mutex.lock() { | ^ ----- this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(i); LL | | } else { LL | | let _x = mutex.lock(); diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index b7012b43d2976..fd30e3702a275 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -10,11 +10,13 @@ fn bla() -> bool { fn main() { if !bla() { + //~^ ERROR: unnecessary boolean `not` operation println!("Bugs"); } else { println!("Bunny"); } if 4 != 5 { + //~^ ERROR: unnecessary `!=` operation println!("Bugs"); } else { println!("Bunny"); diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index 46671c15274f7..2a7500fdc61a0 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -2,6 +2,7 @@ error: unnecessary boolean `not` operation --> $DIR/if_not_else.rs:12:5 | LL | / if !bla() { +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); @@ -12,9 +13,10 @@ LL | | } = note: `-D clippy::if-not-else` implied by `-D warnings` error: unnecessary `!=` operation - --> $DIR/if_not_else.rs:17:5 + --> $DIR/if_not_else.rs:18:5 | LL | / if 4 != 5 { +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); diff --git a/tests/ui/if_then_some_else_none.rs b/tests/ui/if_then_some_else_none.rs index 0e89fdb0dfa28..8fa0f34a6c423 100644 --- a/tests/ui/if_then_some_else_none.rs +++ b/tests/ui/if_then_some_else_none.rs @@ -3,6 +3,7 @@ fn main() { // Should issue an error. let _ = if foo() { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some("foo") } else { @@ -11,6 +12,7 @@ fn main() { // Should issue an error when macros are used. let _ = if matches!(true, true) { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some(matches!(true, false)) } else { @@ -20,10 +22,12 @@ fn main() { // Should issue an error. Binary expression `o < 32` should be parenthesized. let x = Some(5); let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); + //~^ ERROR: this could be simplified with `bool::then_some` // Should issue an error. Unary expression `!x` should be parenthesized. let x = true; let _ = if !x { Some(0) } else { None }; + //~^ ERROR: this could be simplified with `bool::then_some` // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { @@ -79,6 +83,7 @@ fn _msrv_1_49() { #[clippy::msrv = "1.50"] fn _msrv_1_50() { let _ = if foo() { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some(150) } else { diff --git a/tests/ui/if_then_some_else_none.stderr b/tests/ui/if_then_some_else_none.stderr index d728a3c31a3ba..f63298a7fce86 100644 --- a/tests/ui/if_then_some_else_none.stderr +++ b/tests/ui/if_then_some_else_none.stderr @@ -3,6 +3,7 @@ error: this could be simplified with `bool::then` | LL | let _ = if foo() { | _____________^ +LL | | LL | | println!("true!"); LL | | Some("foo") LL | | } else { @@ -14,10 +15,11 @@ LL | | }; = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` error: this could be simplified with `bool::then` - --> $DIR/if_then_some_else_none.rs:13:13 + --> $DIR/if_then_some_else_none.rs:14:13 | LL | let _ = if matches!(true, true) { | _____________^ +LL | | LL | | println!("true!"); LL | | Some(matches!(true, false)) LL | | } else { @@ -28,7 +30,7 @@ LL | | }; = help: consider using `bool::then` like: `matches!(true, true).then(|| { /* snippet */ matches!(true, false) })` error: this could be simplified with `bool::then_some` - --> $DIR/if_then_some_else_none.rs:22:28 + --> $DIR/if_then_some_else_none.rs:24:28 | LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +38,7 @@ LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); = help: consider using `bool::then_some` like: `(o < 32).then_some(o)` error: this could be simplified with `bool::then_some` - --> $DIR/if_then_some_else_none.rs:26:13 + --> $DIR/if_then_some_else_none.rs:29:13 | LL | let _ = if !x { Some(0) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,10 +46,11 @@ LL | let _ = if !x { Some(0) } else { None }; = help: consider using `bool::then_some` like: `(!x).then_some(0)` error: this could be simplified with `bool::then` - --> $DIR/if_then_some_else_none.rs:81:13 + --> $DIR/if_then_some_else_none.rs:85:13 | LL | let _ = if foo() { | _____________^ +LL | | LL | | println!("true!"); LL | | Some(150) LL | | } else { diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs index aea52a852f987..7f452cb46e068 100644 --- a/tests/ui/impl.rs +++ b/tests/ui/impl.rs @@ -8,6 +8,7 @@ impl MyStruct { } impl MyStruct { + //~^ ERROR: multiple implementations of this structure fn second() {} } @@ -22,6 +23,7 @@ mod submod { } impl super::MyStruct { + //~^ ERROR: multiple implementations of this structure fn third() {} } } @@ -42,6 +44,7 @@ impl WithArgs { fn f2() {} } impl WithArgs { + //~^ ERROR: multiple implementations of this structure fn f3() {} } @@ -63,5 +66,6 @@ impl OneAllowedImpl {} #[allow(clippy::multiple_inherent_impl)] impl OneAllowedImpl {} impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. +//~^ ERROR: multiple implementations of this structure fn main() {} diff --git a/tests/ui/impl.stderr b/tests/ui/impl.stderr index e28b1bf0cdd94..2eac1ce3dd7b5 100644 --- a/tests/ui/impl.stderr +++ b/tests/ui/impl.stderr @@ -2,6 +2,7 @@ error: multiple implementations of this structure --> $DIR/impl.rs:10:1 | LL | / impl MyStruct { +LL | | LL | | fn second() {} LL | | } | |_^ @@ -16,9 +17,10 @@ LL | | } = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` error: multiple implementations of this structure - --> $DIR/impl.rs:24:5 + --> $DIR/impl.rs:25:5 | LL | / impl super::MyStruct { +LL | | LL | | fn third() {} LL | | } | |_____^ @@ -32,15 +34,16 @@ LL | | } | |_^ error: multiple implementations of this structure - --> $DIR/impl.rs:44:1 + --> $DIR/impl.rs:46:1 | LL | / impl WithArgs { +LL | | LL | | fn f3() {} LL | | } | |_^ | note: first implementation here - --> $DIR/impl.rs:41:1 + --> $DIR/impl.rs:43:1 | LL | / impl WithArgs { LL | | fn f2() {} @@ -48,13 +51,13 @@ LL | | } | |_^ error: multiple implementations of this structure - --> $DIR/impl.rs:65:1 + --> $DIR/impl.rs:68:1 | LL | impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. | ^^^^^^^^^^^^^^^^^^^^^^ | note: first implementation here - --> $DIR/impl.rs:62:1 + --> $DIR/impl.rs:65:1 | LL | impl OneAllowedImpl {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/impl_trait_in_params.rs b/tests/ui/impl_trait_in_params.rs index 8944f6b58fd43..b652e4a4abe2e 100644 --- a/tests/ui/impl_trait_in_params.rs +++ b/tests/ui/impl_trait_in_params.rs @@ -6,7 +6,10 @@ pub trait AnotherTrait {} // Should warn pub fn a(_: impl Trait) {} +//~^ ERROR: '`impl Trait` used as a function parameter' +//~| NOTE: `-D clippy::impl-trait-in-params` implied by `-D warnings` pub fn c(_: C, _: impl Trait) {} +//~^ ERROR: '`impl Trait` used as a function parameter' fn d(_: impl AnotherTrait) {} // Shouldn't warn diff --git a/tests/ui/impl_trait_in_params.stderr b/tests/ui/impl_trait_in_params.stderr index 80383743525fa..ad035abc635bb 100644 --- a/tests/ui/impl_trait_in_params.stderr +++ b/tests/ui/impl_trait_in_params.stderr @@ -11,7 +11,7 @@ LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {} | +++++++++++++++++++++++++++++++ error: '`impl Trait` used as a function parameter' - --> $DIR/impl_trait_in_params.rs:9:29 + --> $DIR/impl_trait_in_params.rs:11:29 | LL | pub fn c(_: C, _: impl Trait) {} | ^^^^^^^^^^ diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs index 2f8d5cf30c77a..1173a95d06599 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs @@ -21,6 +21,8 @@ impl cmp::Ord for A { } impl PartialOrd for A { + //~^ ERROR: incorrect implementation of `partial_cmp` on an `Ord` type + //~| NOTE: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default fn partial_cmp(&self, other: &Self) -> Option { // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't // automatically applied @@ -44,6 +46,7 @@ impl cmp::Ord for B { } impl PartialOrd for B { + //~^ ERROR: incorrect implementation of `partial_cmp` on an `Ord` type fn partial_cmp(&self, other: &Self) -> Option { // This calls `B.cmp`, not `Ord::cmp`! Some(self.cmp(other)) diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr index f4374c2812877..09d7a32e3342a 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr @@ -2,6 +2,8 @@ error: incorrect implementation of `partial_cmp` on an `Ord` type --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:23:1 | LL | / impl PartialOrd for A { +LL | | +LL | | LL | | fn partial_cmp(&self, other: &Self) -> Option { | | _____________________________________________________________- LL | || // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't @@ -15,9 +17,10 @@ LL | | } = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:46:1 + --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:48:1 | LL | / impl PartialOrd for B { +LL | | LL | | fn partial_cmp(&self, other: &Self) -> Option { | | _____________________________________________________________- LL | || // This calls `B.cmp`, not `Ord::cmp`! diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed index 1f0a9ca25a494..13f0cbe9cc887 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed @@ -12,18 +12,21 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some([slice_0, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_0); } // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some([slice_0, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_0); } // Try with long slice and small indices let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); if let Some([slice_0, _, slice_2, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_2); println!("{}", slice_0); } @@ -31,6 +34,7 @@ fn lintable_examples() { // Multiple bindings let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); if let SomeEnum::One([slice_0, ..]) | SomeEnum::Three([slice_0, ..]) = slice_wrapped { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_0); } @@ -38,6 +42,8 @@ fn lintable_examples() { let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); let b_wrapped: Option<[u32; 2]> = Some([4, 6]); if let (SomeEnum::Three([_, _, a_2, ..]), Some([_, b_1, ..])) = (a_wrapped, b_wrapped) { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~| ERROR: this binding can be a slice pattern to avoid indexing println!("{} -> {}", a_2, b_1); } @@ -45,6 +51,7 @@ fn lintable_examples() { // borrowed and `String` doesn't implement copy let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some([_, ref slice_1, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice_1); } println!("{:?}", slice); @@ -53,6 +60,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some([slice_0, ..]) = &slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice_0); } println!("{:?}", slice); @@ -122,6 +130,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some([slice_0, ..]) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_awesome { println!("This is awesome! {}", slice_0); } @@ -129,6 +138,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some([slice_0, ..]) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_super_awesome() { println!("This is super awesome! {}", slice_0); } diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.rs b/tests/ui/index_refutable_slice/if_let_slice_binding.rs index 0a3374d11b03f..d8d38c167fa57 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.rs +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.rs @@ -12,18 +12,21 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } // Try with long slice and small indices let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[2]); println!("{}", slice[0]); } @@ -31,6 +34,7 @@ fn lintable_examples() { // Multiple bindings let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } @@ -38,6 +42,8 @@ fn lintable_examples() { let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); let b_wrapped: Option<[u32; 2]> = Some([4, 6]); if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~| ERROR: this binding can be a slice pattern to avoid indexing println!("{} -> {}", a[2], b[1]); } @@ -45,6 +51,7 @@ fn lintable_examples() { // borrowed and `String` doesn't implement copy let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(ref slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice[1]); } println!("{:?}", slice); @@ -53,6 +60,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(slice) = &slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice[0]); } println!("{:?}", slice); @@ -122,6 +130,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some(slice) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_awesome { println!("This is awesome! {}", slice[0]); } @@ -129,6 +138,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some(slice) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_super_awesome() { println!("This is super awesome! {}", slice[0]); } diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.stderr b/tests/ui/index_refutable_slice/if_let_slice_binding.stderr index 0a13ac1354e57..f0e635954c5a9 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.stderr +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.stderr @@ -19,7 +19,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:20:17 + --> $DIR/if_let_slice_binding.rs:21:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -34,7 +34,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:26:17 + --> $DIR/if_let_slice_binding.rs:28:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -50,7 +50,7 @@ LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:33:26 + --> $DIR/if_let_slice_binding.rs:36:26 | LL | if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { | ^^^^^ @@ -65,7 +65,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:40:29 + --> $DIR/if_let_slice_binding.rs:44:29 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -80,7 +80,7 @@ LL | println!("{} -> {}", a_2, b[1]); | ~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:40:38 + --> $DIR/if_let_slice_binding.rs:44:38 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -95,7 +95,7 @@ LL | println!("{} -> {}", a[2], b_1); | ~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:47:21 + --> $DIR/if_let_slice_binding.rs:53:21 | LL | if let Some(ref slice) = slice { | ^^^^^ @@ -110,7 +110,7 @@ LL | println!("{:?}", slice_1); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:55:17 + --> $DIR/if_let_slice_binding.rs:62:17 | LL | if let Some(slice) = &slice { | ^^^^^ @@ -125,7 +125,7 @@ LL | println!("{:?}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:124:17 + --> $DIR/if_let_slice_binding.rs:132:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ @@ -140,7 +140,7 @@ LL | println!("This is awesome! {}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:131:17 + --> $DIR/if_let_slice_binding.rs:140:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ diff --git a/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed b/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed index d07b469cf3f01..72edc539f0431 100644 --- a/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed +++ b/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed @@ -21,6 +21,7 @@ fn main() { if_chain! { let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some([slice_0, ..]) = slice; + //~^ ERROR: this binding can be a slice pattern to avoid indexing then { println!("{}", slice_0); } diff --git a/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs b/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs index 406e82083f88f..7b474ba423b9a 100644 --- a/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs +++ b/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs @@ -21,6 +21,7 @@ fn main() { if_chain! { let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice; + //~^ ERROR: this binding can be a slice pattern to avoid indexing then { println!("{}", slice[0]); } diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index f7f7ea4103534..f0da5dfc60bd6 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -12,7 +12,9 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +//~^ ERROR: indexing may panic const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. +//~^ ERROR: indexing may panic const fn idx() -> usize { 1 @@ -25,6 +27,7 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; x[index]; + //~^ ERROR: indexing may panic // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[4]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. @@ -40,8 +43,10 @@ fn main() { x[const { idx4() }]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. const { &ARR[idx()] }; + //~^ ERROR: indexing may panic // This should be linted, since `suppress-restriction-lint-in-const` default is false. const { &ARR[idx4()] }; + //~^ ERROR: indexing may panic let y = &x; // Ok, referencing shouldn't affect this lint. See the issue 6021 @@ -51,8 +56,11 @@ fn main() { let v = vec![0; 5]; v[0]; + //~^ ERROR: indexing may panic v[10]; + //~^ ERROR: indexing may panic v[1 << 3]; + //~^ ERROR: indexing may panic // Out of bounds const N: usize = 15; @@ -63,5 +71,7 @@ fn main() { // Ok, should not produce stderr. x[M]; v[N]; + //~^ ERROR: indexing may panic v[M]; + //~^ ERROR: indexing may panic } diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 1db2eb1397cde..edb47d39412ba 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -9,7 +9,7 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = note: `-D clippy::indexing-slicing` implied by `-D warnings` error: indexing may panic - --> $DIR/indexing_slicing_index.rs:15:24 + --> $DIR/indexing_slicing_index.rs:16:24 | LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ @@ -18,19 +18,19 @@ LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. = note: the suggestion might not be applicable in constant blocks error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:44:14 + --> $DIR/indexing_slicing_index.rs:48:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant used - --> $DIR/indexing_slicing_index.rs:44:5 + --> $DIR/indexing_slicing_index.rs:48:5 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:27:5 + --> $DIR/indexing_slicing_index.rs:29:5 | LL | x[index]; | ^^^^^^^^ @@ -38,7 +38,7 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:42:14 + --> $DIR/indexing_slicing_index.rs:45:14 | LL | const { &ARR[idx()] }; | ^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | const { &ARR[idx()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:44:14 + --> $DIR/indexing_slicing_index.rs:48:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | const { &ARR[idx4()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:53:5 + --> $DIR/indexing_slicing_index.rs:58:5 | LL | v[0]; | ^^^^ @@ -64,7 +64,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:54:5 + --> $DIR/indexing_slicing_index.rs:60:5 | LL | v[10]; | ^^^^^ @@ -72,7 +72,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:55:5 + --> $DIR/indexing_slicing_index.rs:62:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -80,7 +80,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:65:5 + --> $DIR/indexing_slicing_index.rs:73:5 | LL | v[N]; | ^^^^ @@ -88,7 +88,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:66:5 + --> $DIR/indexing_slicing_index.rs:75:5 | LL | v[M]; | ^^^^ @@ -96,7 +96,7 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error[E0080]: evaluation of constant value failed - --> $DIR/indexing_slicing_index.rs:15:24 + --> $DIR/indexing_slicing_index.rs:16:24 | LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs index ea111a48b29fe..fc591021ed6b0 100644 --- a/tests/ui/indexing_slicing_slice.rs +++ b/tests/ui/indexing_slicing_slice.rs @@ -10,12 +10,22 @@ fn main() { let index_from: usize = 2; let index_to: usize = 3; &x[index..]; + //~^ ERROR: slicing may panic &x[..index]; + //~^ ERROR: slicing may panic &x[index_from..index_to]; + //~^ ERROR: slicing may panic &x[index_from..][..index_to]; + //~^ ERROR: slicing may panic + //~| ERROR: slicing may panic &x[5..][..10]; + //~^ ERROR: slicing may panic + //~| ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[0..][..3]; + //~^ ERROR: slicing may panic &x[1..][..5]; + //~^ ERROR: slicing may panic &x[0..].get(..3); // Ok, should not produce stderr. &x[0..3]; // Ok, should not produce stderr. @@ -23,15 +33,22 @@ fn main() { let y = &x; &y[1..2]; &y[0..=4]; + //~^ ERROR: range is out of bounds &y[..=4]; + //~^ ERROR: range is out of bounds &y[..]; // Ok, should not produce stderr. let v = vec![0; 5]; &v[10..100]; + //~^ ERROR: slicing may panic &x[10..][..100]; + //~^ ERROR: slicing may panic + //~| ERROR: range is out of bounds &v[10..]; + //~^ ERROR: slicing may panic &v[..100]; + //~^ ERROR: slicing may panic &v[..]; // Ok, should not produce stderr. } diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index 6a75d57453797..0f83ea52d01ba 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -8,7 +8,7 @@ LL | &x[index..]; = note: `-D clippy::indexing-slicing` implied by `-D warnings` error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:13:6 + --> $DIR/indexing_slicing_slice.rs:14:6 | LL | &x[..index]; | ^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | &x[..index]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:14:6 + --> $DIR/indexing_slicing_slice.rs:16:6 | LL | &x[index_from..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | &x[index_from..index_to]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:15:6 + --> $DIR/indexing_slicing_slice.rs:18:6 | LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | &x[index_from..][..index_to]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:15:6 + --> $DIR/indexing_slicing_slice.rs:18:6 | LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | &x[index_from..][..index_to]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:16:6 + --> $DIR/indexing_slicing_slice.rs:21:6 | LL | &x[5..][..10]; | ^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | &x[5..][..10]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:16:8 + --> $DIR/indexing_slicing_slice.rs:21:8 | LL | &x[5..][..10]; | ^ @@ -56,7 +56,7 @@ LL | &x[5..][..10]; = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:17:6 + --> $DIR/indexing_slicing_slice.rs:25:6 | LL | &x[0..][..3]; | ^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | &x[0..][..3]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:18:6 + --> $DIR/indexing_slicing_slice.rs:27:6 | LL | &x[1..][..5]; | ^^^^^^^^^^^ @@ -72,19 +72,19 @@ LL | &x[1..][..5]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:25:12 + --> $DIR/indexing_slicing_slice.rs:35:12 | LL | &y[0..=4]; | ^ error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:26:11 + --> $DIR/indexing_slicing_slice.rs:37:11 | LL | &y[..=4]; | ^ error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:31:6 + --> $DIR/indexing_slicing_slice.rs:43:6 | LL | &v[10..100]; | ^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | &v[10..100]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:32:6 + --> $DIR/indexing_slicing_slice.rs:45:6 | LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ @@ -100,13 +100,13 @@ LL | &x[10..][..100]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:32:8 + --> $DIR/indexing_slicing_slice.rs:45:8 | LL | &x[10..][..100]; | ^^ error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:33:6 + --> $DIR/indexing_slicing_slice.rs:48:6 | LL | &v[10..]; | ^^^^^^^ @@ -114,7 +114,7 @@ LL | &v[10..]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:34:6 + --> $DIR/indexing_slicing_slice.rs:50:6 | LL | &v[..100]; | ^^^^^^^^ diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 7821dd44812df..da95ba04b821b 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -9,10 +9,13 @@ fn square_is_lower_64(x: &u32) -> bool { #[deny(clippy::infinite_iter)] fn infinite_iters() { repeat(0_u8).collect::>(); + //~^ ERROR: infinite iteration detected // infinite iter (0..8_u32).take_while(square_is_lower_64).cycle().count(); + //~^ ERROR: infinite iteration detected // infinite iter (0..8_u64).chain(0..).max(); + //~^ ERROR: infinite iteration detected // infinite iter (0_usize..) .chain([0usize, 1, 2].iter().cloned()) @@ -20,6 +23,7 @@ fn infinite_iters() { .min(); // infinite iter (0..8_u32) + //~^ ERROR: infinite iteration detected .rev() .cycle() .map(|x| x + 1_u32) @@ -28,8 +32,10 @@ fn infinite_iters() { (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter (0_usize..).flat_map(|x| 0..x).product::(); + //~^ ERROR: infinite iteration detected // infinite iter (0_u64..).filter(|x| x % 2 == 0).last(); + //~^ ERROR: infinite iteration detected // not an infinite, because ranges are double-ended (0..42_u64).by_ref().last(); // iterator is not exhausted @@ -40,10 +46,13 @@ fn infinite_iters() { fn potential_infinite_iters() { // maybe infinite iter (0..).zip((0..).take_while(square_is_lower_64)).count(); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter repeat(42).take_while(|x| *x == 42).chain(0..42).max(); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (1..) + //~^ ERROR: possible infinite iteration detected .scan(0, |state, x| { *state += x; Some(*state) @@ -51,12 +60,16 @@ fn potential_infinite_iters() { .min(); // maybe infinite iter (0..).find(|x| *x == 24); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (0..).position(|x| x == 24); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (0..).any(|x| x == 24); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (0..).all(|x| x == 24); + //~^ ERROR: possible infinite iteration detected // not infinite (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); @@ -82,6 +95,8 @@ mod finite_collect { fn check_collect() { // Infinite iter let _: HashSet = (0..).collect(); + //~^ ERROR: infinite iteration detected + //~| NOTE: `#[deny(clippy::infinite_iter)]` on by default // Some data structures don't collect infinitely, such as `ArrayVec` let _: C = (0..).collect(); diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index 39d2fcc71aa69..d0d0f0db443bb 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -11,21 +11,22 @@ LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:13:5 + --> $DIR/infinite_iter.rs:14:5 | LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:15:5 + --> $DIR/infinite_iter.rs:17:5 | LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:22:5 + --> $DIR/infinite_iter.rs:25:5 | LL | / (0..8_u32) +LL | | LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) @@ -33,39 +34,40 @@ LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:30:5 + --> $DIR/infinite_iter.rs:34:5 | LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:32:5 + --> $DIR/infinite_iter.rs:37:5 | LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:42:5 + --> $DIR/infinite_iter.rs:48:5 | LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/infinite_iter.rs:39:8 + --> $DIR/infinite_iter.rs:45:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:44:5 + --> $DIR/infinite_iter.rs:51:5 | LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:46:5 + --> $DIR/infinite_iter.rs:54:5 | LL | / (1..) +LL | | LL | | .scan(0, |state, x| { LL | | *state += x; LL | | Some(*state) @@ -74,31 +76,31 @@ LL | | .min(); | |______________^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:53:5 + --> $DIR/infinite_iter.rs:62:5 | LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:55:5 + --> $DIR/infinite_iter.rs:65:5 | LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:57:5 + --> $DIR/infinite_iter.rs:68:5 | LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:59:5 + --> $DIR/infinite_iter.rs:71:5 | LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:84:31 + --> $DIR/infinite_iter.rs:97:31 | LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index d68889751d86a..281e12c7b938a 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -7,6 +7,8 @@ fn fn_constref(i: &i32) -> i32 { unimplemented!() } fn fn_mutref(i: &mut i32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` unimplemented!() } fn fooi() -> i32 { @@ -20,11 +22,15 @@ fn immutable_condition() { // Should warn when all vars mentioned are immutable let y = 0; while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - y is immutable"); } let x = 0; while y < 10 && x < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop let mut k = 1; k += 2; println!("KO - x and y immutable"); @@ -32,6 +38,8 @@ fn immutable_condition() { let cond = false; while !cond { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - cond immutable"); } @@ -76,15 +84,21 @@ fn unused_var() { let (mut i, mut j) = (0, 0); while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop j = 3; println!("KO - i not mentioned"); } while i < 3 && j > 0 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - i and j not mentioned"); } while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop let mut i = 5; fn_mutref(&mut i); println!("KO - shadowed"); @@ -100,11 +114,15 @@ fn used_immutable() { let mut i = 0; while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop fn_constref(&i); println!("KO - const reference"); } while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop fn_val(i); println!("KO - passed by value"); } @@ -171,6 +189,8 @@ impl Counter { fn print_n(&self, n: usize) { while self.count < n { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - {} is not mutated", self.count); } } @@ -179,6 +199,8 @@ impl Counter { fn while_loop_with_break_and_return() { let y = 0; while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop if y == 0 { break; } @@ -186,6 +208,8 @@ fn while_loop_with_break_and_return() { } while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop if y == 0 { return; } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 2312612d3aa00..5ba806be867f5 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:22:11 + --> $DIR/infinite_loop.rs:24:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: `#[deny(clippy::while_immutable_condition)]` on by default error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:27:11 + --> $DIR/infinite_loop.rs:31:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:34:11 + --> $DIR/infinite_loop.rs:40:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:78:11 + --> $DIR/infinite_loop.rs:86:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:83:11 + --> $DIR/infinite_loop.rs:93:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:87:11 + --> $DIR/infinite_loop.rs:99:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:102:11 + --> $DIR/infinite_loop.rs:116:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:107:11 + --> $DIR/infinite_loop.rs:123:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:173:15 + --> $DIR/infinite_loop.rs:191:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:181:11 + --> $DIR/infinite_loop.rs:201:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:188:11 + --> $DIR/infinite_loop.rs:210:11 | LL | while y < 10 { | ^^^^^^ diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs index adb0389a043f8..7b938cdd758c3 100644 --- a/tests/ui/inherent_to_string.rs +++ b/tests/ui/inherent_to_string.rs @@ -20,6 +20,7 @@ struct J; impl A { // Should be detected; emit warning fn to_string(&self) -> String { + //~^ ERROR: implementation of inherent method `to_string(&self) -> String` for type `A "A.to_string()".to_string() } @@ -44,6 +45,7 @@ impl B { impl C { // Should be detected and emit error as C also implements Display fn to_string(&self) -> String { + //~^ ERROR: type `C` implements inherent method `to_string(&self) -> String` which sha "C.to_string()".to_string() } } diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr index 579b3c8c56f7c..cfe8600e92606 100644 --- a/tests/ui/inherent_to_string.stderr +++ b/tests/ui/inherent_to_string.stderr @@ -2,6 +2,7 @@ error: implementation of inherent method `to_string(&self) -> String` for type ` --> $DIR/inherent_to_string.rs:22:5 | LL | / fn to_string(&self) -> String { +LL | | LL | | "A.to_string()".to_string() LL | | } | |_____^ @@ -10,9 +11,10 @@ LL | | } = note: `-D clippy::inherent-to-string` implied by `-D warnings` error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` - --> $DIR/inherent_to_string.rs:46:5 + --> $DIR/inherent_to_string.rs:47:5 | LL | / fn to_string(&self) -> String { +LL | | LL | | "C.to_string()".to_string() LL | | } | |_____^ diff --git a/tests/ui/inspect_for_each.rs b/tests/ui/inspect_for_each.rs index 7fe45c83bcacb..974690eaa8e4f 100644 --- a/tests/ui/inspect_for_each.rs +++ b/tests/ui/inspect_for_each.rs @@ -5,6 +5,7 @@ fn main() { let mut b: Vec = Vec::new(); a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { + //~^ ERROR: called `inspect(..).for_each(..)` on an `Iterator` let y = do_some(x); let z = do_more(y); b.push(z); diff --git a/tests/ui/inspect_for_each.stderr b/tests/ui/inspect_for_each.stderr index 67c2d5e53c78d..bdeb1d844609b 100644 --- a/tests/ui/inspect_for_each.stderr +++ b/tests/ui/inspect_for_each.stderr @@ -3,6 +3,7 @@ error: called `inspect(..).for_each(..)` on an `Iterator` | LL | a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { | ___________________^ +LL | | LL | | let y = do_some(x); LL | | let z = do_more(y); LL | | b.push(z); diff --git a/tests/ui/integer_division.rs b/tests/ui/integer_division.rs index 800c75257524a..137548fecf4a8 100644 --- a/tests/ui/integer_division.rs +++ b/tests/ui/integer_division.rs @@ -3,7 +3,10 @@ fn main() { let two = 2; let n = 1 / 2; + //~^ ERROR: integer division let o = 1 / two; + //~^ ERROR: integer division let p = two / 4; + //~^ ERROR: integer division let x = 1. / 2.0; } diff --git a/tests/ui/integer_division.stderr b/tests/ui/integer_division.stderr index ca80012792075..9bc41ef8385e7 100644 --- a/tests/ui/integer_division.stderr +++ b/tests/ui/integer_division.stderr @@ -8,7 +8,7 @@ LL | let n = 1 / 2; = note: `-D clippy::integer-division` implied by `-D warnings` error: integer division - --> $DIR/integer_division.rs:6:13 + --> $DIR/integer_division.rs:7:13 | LL | let o = 1 / two; | ^^^^^^^ @@ -16,7 +16,7 @@ LL | let o = 1 / two; = help: division of integers may cause loss of precision. consider using floats error: integer division - --> $DIR/integer_division.rs:7:13 + --> $DIR/integer_division.rs:9:13 | LL | let p = two / 4; | ^^^^^^^ diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index 697416dcee831..a9db15f209733 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -19,36 +19,61 @@ fn main() { // always false, since no u8 can be > 300 (u8 as u32) > 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~| NOTE: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` (u8 as i32) > 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as u32) == 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) == 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 < (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 < (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 == (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above (u8 as u32) <= 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) <= 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as u32) != 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) != 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 >= (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 >= (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 != (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // always false, since u8 -> i32 doesn't wrap (u8 as i32) < 0; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above (u8 as i32) >= 0; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // always false, since no u8 can be 1337 1337 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 1337 == (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above 1337 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 1337 != (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // Those are Ok: (u8 as u32) > 20; @@ -63,7 +88,9 @@ fn main() { (u8 as i8) == -1; (u8 as i8) != -1; (u8 as i32) > -1; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) < -1; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u32 as i32) < -5; (u32 as i32) < 10; @@ -80,6 +107,7 @@ fn main() { -5 > (u32 as i32); -5 >= (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 == (u32 as i32); } diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr index 03c3fb80aaabc..b201db3ddb14e 100644 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -7,157 +7,157 @@ LL | (u8 as u32) > 300; = note: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:22:5 + --> $DIR/invalid_upcast_comparisons.rs:24:5 | LL | (u8 as i32) > 300; | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:23:5 + --> $DIR/invalid_upcast_comparisons.rs:26:5 | LL | (u8 as u32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:24:5 + --> $DIR/invalid_upcast_comparisons.rs:28:5 | LL | (u8 as i32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:25:5 + --> $DIR/invalid_upcast_comparisons.rs:30:5 | LL | 300 < (u8 as u32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:26:5 + --> $DIR/invalid_upcast_comparisons.rs:32:5 | LL | 300 < (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:27:5 + --> $DIR/invalid_upcast_comparisons.rs:34:5 | LL | 300 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:28:5 + --> $DIR/invalid_upcast_comparisons.rs:36:5 | LL | 300 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:30:5 + --> $DIR/invalid_upcast_comparisons.rs:39:5 | LL | (u8 as u32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:31:5 + --> $DIR/invalid_upcast_comparisons.rs:41:5 | LL | (u8 as i32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:32:5 + --> $DIR/invalid_upcast_comparisons.rs:43:5 | LL | (u8 as u32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:33:5 + --> $DIR/invalid_upcast_comparisons.rs:45:5 | LL | (u8 as i32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:34:5 + --> $DIR/invalid_upcast_comparisons.rs:47:5 | LL | 300 >= (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:35:5 + --> $DIR/invalid_upcast_comparisons.rs:49:5 | LL | 300 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:36:5 + --> $DIR/invalid_upcast_comparisons.rs:51:5 | LL | 300 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:37:5 + --> $DIR/invalid_upcast_comparisons.rs:53:5 | LL | 300 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:40:5 + --> $DIR/invalid_upcast_comparisons.rs:57:5 | LL | (u8 as i32) < 0; | ^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:41:5 + --> $DIR/invalid_upcast_comparisons.rs:59:5 | LL | -5 != (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:43:5 + --> $DIR/invalid_upcast_comparisons.rs:62:5 | LL | (u8 as i32) >= 0; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:44:5 + --> $DIR/invalid_upcast_comparisons.rs:64:5 | LL | -5 == (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:47:5 + --> $DIR/invalid_upcast_comparisons.rs:68:5 | LL | 1337 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:48:5 + --> $DIR/invalid_upcast_comparisons.rs:70:5 | LL | 1337 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:50:5 + --> $DIR/invalid_upcast_comparisons.rs:73:5 | LL | 1337 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:51:5 + --> $DIR/invalid_upcast_comparisons.rs:75:5 | LL | 1337 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:65:5 + --> $DIR/invalid_upcast_comparisons.rs:90:5 | LL | (u8 as i32) > -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:66:5 + --> $DIR/invalid_upcast_comparisons.rs:92:5 | LL | (u8 as i32) < -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:82:5 + --> $DIR/invalid_upcast_comparisons.rs:109:5 | LL | -5 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/issue-7447.rs b/tests/ui/issue-7447.rs index de4362c4df70e..7e7ef209d4852 100644 --- a/tests/ui/issue-7447.rs +++ b/tests/ui/issue-7447.rs @@ -24,5 +24,8 @@ pub struct ByteView<'a> { fn main() { byte_view(panic!()); + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` group_entries(panic!()); + //~^ ERROR: sub-expression diverges } diff --git a/tests/ui/issue-7447.stderr b/tests/ui/issue-7447.stderr index 7a113740c6a47..27e102af62fbb 100644 --- a/tests/ui/issue-7447.stderr +++ b/tests/ui/issue-7447.stderr @@ -8,7 +8,7 @@ LL | byte_view(panic!()); = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges - --> $DIR/issue-7447.rs:27:19 + --> $DIR/issue-7447.rs:29:19 | LL | group_entries(panic!()); | ^^^^^^^^ diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index 8e0620e52b65f..23453207b4e5e 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -2,10 +2,13 @@ #![allow(clippy::uninlined_format_args)] async fn sink1<'a>(_: &'a str) {} // lint +//~^ ERROR: the following explicit lifetimes could be elided: 'a +//~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` async fn sink1_elided(_: &str) {} // ok // lint async fn one_to_one<'a>(s: &'a str) -> &'a str { + //~^ ERROR: the following explicit lifetimes could be elided: 'a s } @@ -26,6 +29,7 @@ struct Foo; impl Foo { // ok pub async fn new(&mut self) -> Self { + //~^ ERROR: methods called `new` usually take no `self` Foo {} } } diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index 5b60646ef21df..acfa01e9f2b31 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -7,13 +7,13 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint = note: `-D clippy::needless-lifetimes` implied by `-D warnings` error: the following explicit lifetimes could be elided: 'a - --> $DIR/issue_4266.rs:8:21 + --> $DIR/issue_4266.rs:10:21 | LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { | ^^ ^^ error: methods called `new` usually take no `self` - --> $DIR/issue_4266.rs:28:22 + --> $DIR/issue_4266.rs:31:22 | LL | pub async fn new(&mut self) -> Self { | ^^^^^^^^^ diff --git a/tests/ui/items_after_statement.rs b/tests/ui/items_after_statement.rs index f12cb8f22e270..943e7c1167605 100644 --- a/tests/ui/items_after_statement.rs +++ b/tests/ui/items_after_statement.rs @@ -11,6 +11,8 @@ fn ok() { fn last() { foo(); fn foo() { + //~^ ERROR: adding items after statements is confusing, since items exist from the sta + //~| NOTE: `-D clippy::items-after-statements` implied by `-D warnings` println!("foo"); } } @@ -18,6 +20,7 @@ fn last() { fn main() { foo(); fn foo() { + //~^ ERROR: adding items after statements is confusing, since items exist from the sta println!("foo"); } foo(); diff --git a/tests/ui/items_after_statement.stderr b/tests/ui/items_after_statement.stderr index f69635a977bd7..0e043b1742ff0 100644 --- a/tests/ui/items_after_statement.stderr +++ b/tests/ui/items_after_statement.stderr @@ -2,6 +2,8 @@ error: adding items after statements is confusing, since items exist from the st --> $DIR/items_after_statement.rs:13:5 | LL | / fn foo() { +LL | | +LL | | LL | | println!("foo"); LL | | } | |_____^ @@ -9,15 +11,16 @@ LL | | } = note: `-D clippy::items-after-statements` implied by `-D warnings` error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:20:5 + --> $DIR/items_after_statement.rs:22:5 | LL | / fn foo() { +LL | | LL | | println!("foo"); LL | | } | |_____^ error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:33:13 + --> $DIR/items_after_statement.rs:36:13 | LL | / fn say_something() { LL | | println!("something"); diff --git a/tests/ui/iter_not_returning_iterator.rs b/tests/ui/iter_not_returning_iterator.rs index cce216fc649b1..e694bc7ac62fb 100644 --- a/tests/ui/iter_not_returning_iterator.rs +++ b/tests/ui/iter_not_returning_iterator.rs @@ -28,10 +28,13 @@ struct Counter2 { impl Data2 { fn iter(&self) -> Counter2 { + //~^ ERROR: this method is named `iter` but its return type does not implement `Iterat + //~| NOTE: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` todo!() } fn iter_mut(&self) -> Counter2 { + //~^ ERROR: this method is named `iter_mut` but its return type does not implement `It todo!() } } @@ -48,6 +51,7 @@ impl Iterator for Counter { trait Iter { type I; fn iter(&self) -> Self::I; + //~^ ERROR: this method is named `iter` but its return type does not implement `Iterat } impl Iter for () { diff --git a/tests/ui/iter_not_returning_iterator.stderr b/tests/ui/iter_not_returning_iterator.stderr index 44f0295583695..3145ade4448ba 100644 --- a/tests/ui/iter_not_returning_iterator.stderr +++ b/tests/ui/iter_not_returning_iterator.stderr @@ -7,13 +7,13 @@ LL | fn iter(&self) -> Counter2 { = note: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` error: this method is named `iter_mut` but its return type does not implement `Iterator` - --> $DIR/iter_not_returning_iterator.rs:34:5 + --> $DIR/iter_not_returning_iterator.rs:36:5 | LL | fn iter_mut(&self) -> Counter2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this method is named `iter` but its return type does not implement `Iterator` - --> $DIR/iter_not_returning_iterator.rs:50:5 + --> $DIR/iter_not_returning_iterator.rs:53:5 | LL | fn iter(&self) -> Self::I; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_skip_next_unfixable.rs b/tests/ui/iter_skip_next_unfixable.rs index 4dd8cb599d52b..9c224f4117d3f 100644 --- a/tests/ui/iter_skip_next_unfixable.rs +++ b/tests/ui/iter_skip_next_unfixable.rs @@ -7,13 +7,16 @@ fn main() { let test_string = "1|1 2"; let sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator }; fn check(s: T) where T: Iterator, { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator } } diff --git a/tests/ui/iter_skip_next_unfixable.stderr b/tests/ui/iter_skip_next_unfixable.stderr index 4062706f94206..3160dc03a4fdb 100644 --- a/tests/ui/iter_skip_next_unfixable.stderr +++ b/tests/ui/iter_skip_next_unfixable.stderr @@ -12,25 +12,25 @@ LL | let sp = test_string.split('|').map(|s| s.trim()); = note: `-D clippy::iter-skip-next` implied by `-D warnings` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next_unfixable.rs:11:29 + --> $DIR/iter_skip_next_unfixable.rs:12:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | help: for this change `s` has to be mutable - --> $DIR/iter_skip_next_unfixable.rs:10:17 + --> $DIR/iter_skip_next_unfixable.rs:11:17 | LL | if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { | ^ error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next_unfixable.rs:17:29 + --> $DIR/iter_skip_next_unfixable.rs:19:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | help: for this change `s` has to be mutable - --> $DIR/iter_skip_next_unfixable.rs:13:17 + --> $DIR/iter_skip_next_unfixable.rs:15:17 | LL | fn check(s: T) | ^ diff --git a/tests/ui/iterator_step_by_zero.rs b/tests/ui/iterator_step_by_zero.rs index 33ec78e9a4160..0b51842df2e39 100644 --- a/tests/ui/iterator_step_by_zero.rs +++ b/tests/ui/iterator_step_by_zero.rs @@ -2,8 +2,12 @@ #[warn(clippy::iterator_step_by_zero)] fn main() { let _ = vec!["A", "B", "B"].iter().step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~| NOTE: `-D clippy::iterator-step-by-zero` implied by `-D warnings` let _ = "XXX".chars().step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let _ = (0..1).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime // No error, not an iterator. let y = NotIterator; @@ -13,14 +17,18 @@ fn main() { let _ = (0..1).step_by(1); let _ = (1..).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let _ = (1..=2).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let x = 0..1; let _ = x.step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime // check const eval let v1 = vec![1, 2, 3]; let _ = v1.iter().step_by(2 / 3); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime } struct NotIterator; diff --git a/tests/ui/iterator_step_by_zero.stderr b/tests/ui/iterator_step_by_zero.stderr index b470e2ed2eab9..fcf2930c26b29 100644 --- a/tests/ui/iterator_step_by_zero.stderr +++ b/tests/ui/iterator_step_by_zero.stderr @@ -7,37 +7,37 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0); = note: `-D clippy::iterator-step-by-zero` implied by `-D warnings` error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:5:13 + --> $DIR/iterator_step_by_zero.rs:7:13 | LL | let _ = "XXX".chars().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:6:13 + --> $DIR/iterator_step_by_zero.rs:9:13 | LL | let _ = (0..1).step_by(0); | ^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:15:13 + --> $DIR/iterator_step_by_zero.rs:19:13 | LL | let _ = (1..).step_by(0); | ^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:16:13 + --> $DIR/iterator_step_by_zero.rs:21:13 | LL | let _ = (1..=2).step_by(0); | ^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:19:13 + --> $DIR/iterator_step_by_zero.rs:25:13 | LL | let _ = x.step_by(0); | ^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:23:13 + --> $DIR/iterator_step_by_zero.rs:30:13 | LL | let _ = v1.iter().step_by(2 / 3); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index afe89cf6e94d8..4c192d1c8d1bd 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -9,16 +9,21 @@ async fn big_fut(_arg: [u8; 1024 * 16]) {} async fn wait() { let f = async { Box::pin(big_fut([0u8; 1024 * 16])).await; + //~^ ERROR: large future with a size of 16385 bytes + //~| NOTE: `-D clippy::large-futures` implied by `-D warnings` }; Box::pin(f).await + //~^ ERROR: large future with a size of 16386 bytes } async fn calls_fut(fut: impl std::future::Future) { loop { Box::pin(wait()).await; + //~^ ERROR: large future with a size of 16387 bytes if true { return fut.await; } else { Box::pin(wait()).await; + //~^ ERROR: large future with a size of 16387 bytes } } } @@ -26,7 +31,9 @@ async fn calls_fut(fut: impl std::future::Future) { pub async fn test() { let fut = big_fut([0u8; 1024 * 16]); Box::pin(foo()).await; + //~^ ERROR: large future with a size of 65540 bytes Box::pin(calls_fut(fut)).await; + //~^ ERROR: large future with a size of 49159 bytes } pub fn foo() -> impl std::future::Future { @@ -39,6 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { Box::pin(async { + //~^ ERROR: large future with a size of 65540 bytes let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index e0f6b3d9d3b44..557d89a9cf99d 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -9,16 +9,21 @@ async fn big_fut(_arg: [u8; 1024 * 16]) {} async fn wait() { let f = async { big_fut([0u8; 1024 * 16]).await; + //~^ ERROR: large future with a size of 16385 bytes + //~| NOTE: `-D clippy::large-futures` implied by `-D warnings` }; f.await + //~^ ERROR: large future with a size of 16386 bytes } async fn calls_fut(fut: impl std::future::Future) { loop { wait().await; + //~^ ERROR: large future with a size of 16387 bytes if true { return fut.await; } else { wait().await; + //~^ ERROR: large future with a size of 16387 bytes } } } @@ -26,7 +31,9 @@ async fn calls_fut(fut: impl std::future::Future) { pub async fn test() { let fut = big_fut([0u8; 1024 * 16]); foo().await; + //~^ ERROR: large future with a size of 65540 bytes calls_fut(fut).await; + //~^ ERROR: large future with a size of 49159 bytes } pub fn foo() -> impl std::future::Future { @@ -39,6 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { async { + //~^ ERROR: large future with a size of 65540 bytes let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index 5bcf054884e41..5a0f00b67ec4d 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -7,39 +7,40 @@ LL | big_fut([0u8; 1024 * 16]).await; = note: `-D clippy::large-futures` implied by `-D warnings` error: large future with a size of 16386 bytes - --> $DIR/large_futures.rs:13:5 + --> $DIR/large_futures.rs:15:5 | LL | f.await | ^ help: consider `Box::pin` on it: `Box::pin(f)` error: large future with a size of 16387 bytes - --> $DIR/large_futures.rs:17:9 + --> $DIR/large_futures.rs:20:9 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 16387 bytes - --> $DIR/large_futures.rs:21:13 + --> $DIR/large_futures.rs:25:13 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:28:5 + --> $DIR/large_futures.rs:33:5 | LL | foo().await; | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` error: large future with a size of 49159 bytes - --> $DIR/large_futures.rs:29:5 + --> $DIR/large_futures.rs:35:5 | LL | calls_fut(fut).await; | ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))` error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:41:5 + --> $DIR/large_futures.rs:48:5 | LL | / async { +LL | | LL | | let x = [0i32; 1024 * 16]; LL | | async {}.await; LL | | println!("{:?}", x); @@ -49,6 +50,7 @@ LL | | } help: consider `Box::pin` on it | LL ~ Box::pin(async { +LL + LL + let x = [0i32; 1024 * 16]; LL + async {}.await; LL + println!("{:?}", x); @@ -56,7 +58,7 @@ LL + }) | error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:52:13 + --> $DIR/large_futures.rs:60:13 | LL | / async { LL | | let x = [0i32; 1024 * 16]; diff --git a/tests/ui/large_stack_arrays.rs b/tests/ui/large_stack_arrays.rs index 3e9d5e6a4ca32..d5c4f95f8c422 100644 --- a/tests/ui/large_stack_arrays.rs +++ b/tests/ui/large_stack_arrays.rs @@ -27,17 +27,24 @@ fn issue_10741() { } let _x = [build(); 3]; + //~^ ERROR: allocating a local array larger than 512000 bytes let _y = [build(), build(), build()]; + //~^ ERROR: allocating a local array larger than 512000 bytes } fn main() { let bad = ( [0u32; 20_000_000], + //~^ ERROR: allocating a local array larger than 512000 bytes [S { data: [0; 32] }; 5000], + //~^ ERROR: allocating a local array larger than 512000 bytes [Some(""); 20_000_000], + //~^ ERROR: allocating a local array larger than 512000 bytes [E::T(0); 5000], + //~^ ERROR: allocating a local array larger than 512000 bytes [0u8; usize::MAX], + //~^ ERROR: allocating a local array larger than 512000 bytes ); let good = ( diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index 118d39566abee..5126f45278554 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -8,7 +8,7 @@ LL | let _x = [build(); 3]; = note: `-D clippy::large-stack-arrays` implied by `-D warnings` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:31:14 + --> $DIR/large_stack_arrays.rs:32:14 | LL | let _y = [build(), build(), build()]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _y = [build(), build(), build()]; = help: consider allocating on the heap with `vec![build(), build(), build()].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:36:9 + --> $DIR/large_stack_arrays.rs:38:9 | LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | [0u32; 20_000_000], = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:37:9 + --> $DIR/large_stack_arrays.rs:40:9 | LL | [S { data: [0; 32] }; 5000], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | [S { data: [0; 32] }; 5000], = help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:38:9 + --> $DIR/large_stack_arrays.rs:42:9 | LL | [Some(""); 20_000_000], | ^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | [Some(""); 20_000_000], = help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:39:9 + --> $DIR/large_stack_arrays.rs:44:9 | LL | [E::T(0); 5000], | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | [E::T(0); 5000], = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:40:9 + --> $DIR/large_stack_arrays.rs:46:9 | LL | [0u8; usize::MAX], | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/large_stack_frames.rs b/tests/ui/large_stack_frames.rs index cd9d0c8a67a8a..f32368f93975c 100644 --- a/tests/ui/large_stack_frames.rs +++ b/tests/ui/large_stack_frames.rs @@ -23,6 +23,8 @@ impl Default for ArrayDefault { } fn many_small_arrays() { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack let x = [0u8; 500_000]; let x2 = [0u8; 500_000]; let x3 = [0u8; 500_000]; @@ -32,10 +34,14 @@ fn many_small_arrays() { } fn large_return_value() -> ArrayDefault<1_000_000> { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack Default::default() } fn large_fn_arg(x: ArrayDefault<1_000_000>) { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack black_box(&x); } diff --git a/tests/ui/large_stack_frames.stderr b/tests/ui/large_stack_frames.stderr index d57df8596fe56..6b14badca69ff 100644 --- a/tests/ui/large_stack_frames.stderr +++ b/tests/ui/large_stack_frames.stderr @@ -2,9 +2,9 @@ error: this function allocates a large amount of stack space --> $DIR/large_stack_frames.rs:25:1 | LL | / fn many_small_arrays() { +LL | | +LL | | LL | | let x = [0u8; 500_000]; -LL | | let x2 = [0u8; 500_000]; -LL | | let x3 = [0u8; 500_000]; ... | LL | | black_box((&x, &x2, &x3, &x4, &x5)); LL | | } @@ -14,9 +14,11 @@ LL | | } = note: `-D clippy::large-stack-frames` implied by `-D warnings` error: this function allocates a large amount of stack space - --> $DIR/large_stack_frames.rs:34:1 + --> $DIR/large_stack_frames.rs:36:1 | LL | / fn large_return_value() -> ArrayDefault<1_000_000> { +LL | | +LL | | LL | | Default::default() LL | | } | |_^ @@ -24,9 +26,11 @@ LL | | } = note: allocating large amounts of stack space can overflow the stack error: this function allocates a large amount of stack space - --> $DIR/large_stack_frames.rs:38:1 + --> $DIR/large_stack_frames.rs:42:1 | LL | / fn large_fn_arg(x: ArrayDefault<1_000_000>) { +LL | | +LL | | LL | | black_box(&x); LL | | } | |_^ diff --git a/tests/ui/len_without_is_empty.rs b/tests/ui/len_without_is_empty.rs index 52aabefaed20a..ac6c3e06365c6 100644 --- a/tests/ui/len_without_is_empty.rs +++ b/tests/ui/len_without_is_empty.rs @@ -5,6 +5,8 @@ pub struct PubOne; impl PubOne { pub fn len(&self) -> isize { + //~^ ERROR: struct `PubOne` has a public `len` method, but no `is_empty` method + //~| NOTE: `-D clippy::len-without-is-empty` implied by `-D warnings` 1 } } @@ -53,6 +55,7 @@ impl PubAllowedStruct { } pub trait PubTraitsToo { + //~^ ERROR: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` fn len(&self) -> isize; } @@ -66,6 +69,7 @@ pub struct HasIsEmpty; impl HasIsEmpty { pub fn len(&self) -> isize { + //~^ ERROR: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` me 1 } @@ -78,6 +82,7 @@ pub struct HasWrongIsEmpty; impl HasWrongIsEmpty { pub fn len(&self) -> isize { + //~^ ERROR: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` met 1 } @@ -90,6 +95,7 @@ pub struct MismatchedSelf; impl MismatchedSelf { pub fn len(self) -> isize { + //~^ ERROR: struct `MismatchedSelf` has a public `len` method, but the `is_empty` meth 1 } @@ -169,6 +175,7 @@ pub trait InheritingEmpty: Empty { pub trait Foo: Sized {} pub trait DependsOnFoo: Foo { + //~^ ERROR: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` fn len(&mut self) -> usize; } @@ -214,6 +221,7 @@ impl OptionalLen2 { pub struct OptionalLen3; impl OptionalLen3 { pub fn len(&self) -> usize { + //~^ ERROR: struct `OptionalLen3` has a public `len` method, but the `is_empty` method 0 } @@ -226,6 +234,8 @@ impl OptionalLen3 { pub struct ResultLen; impl ResultLen { pub fn len(&self) -> Result { + //~^ ERROR: struct `ResultLen` has a public `len` method, but the `is_empty` method ha + //~| ERROR: this returns a `Result<_, ()>` Ok(0) } @@ -238,10 +248,12 @@ impl ResultLen { pub struct ResultLen2; impl ResultLen2 { pub fn len(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } pub fn is_empty(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(true) } } @@ -249,6 +261,7 @@ impl ResultLen2 { pub struct ResultLen3; impl ResultLen3 { pub fn len(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } @@ -290,6 +303,7 @@ impl AsyncLenWithoutIsEmpty { } pub async fn len(&self) -> usize { + //~^ ERROR: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empt usize::from(!self.async_task().await) } } @@ -302,6 +316,7 @@ impl AsyncOptionLenWithoutIsEmpty { } pub async fn len(&self) -> Option { + //~^ ERROR: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `i None } } @@ -323,6 +338,7 @@ impl AsyncResultLenWithoutIsEmpty { } pub async fn len(&self) -> Result { + //~^ ERROR: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `i Err(()) } } diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr index 1bce1734b81af..1042ea2e1b389 100644 --- a/tests/ui/len_without_is_empty.stderr +++ b/tests/ui/len_without_is_empty.stderr @@ -7,87 +7,89 @@ LL | pub fn len(&self) -> isize { = note: `-D clippy::len-without-is-empty` implied by `-D warnings` error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:55:1 + --> $DIR/len_without_is_empty.rs:57:1 | LL | / pub trait PubTraitsToo { +LL | | LL | | fn len(&self) -> isize; LL | | } | |_^ error: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` method - --> $DIR/len_without_is_empty.rs:68:5 + --> $DIR/len_without_is_empty.rs:71:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:72:5 + --> $DIR/len_without_is_empty.rs:76:5 | LL | fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:80:5 + --> $DIR/len_without_is_empty.rs:84:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:84:5 + --> $DIR/len_without_is_empty.rs:89:5 | LL | pub fn is_empty(&self, x: u32) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` error: struct `MismatchedSelf` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:92:5 + --> $DIR/len_without_is_empty.rs:97:5 | LL | pub fn len(self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:96:5 + --> $DIR/len_without_is_empty.rs:102:5 | LL | pub fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(self) -> bool` error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:171:1 + --> $DIR/len_without_is_empty.rs:177:1 | LL | / pub trait DependsOnFoo: Foo { +LL | | LL | | fn len(&mut self) -> usize; LL | | } | |_^ error: struct `OptionalLen3` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:216:5 + --> $DIR/len_without_is_empty.rs:223:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:221:5 + --> $DIR/len_without_is_empty.rs:229:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` error: struct `ResultLen` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:228:5 + --> $DIR/len_without_is_empty.rs:236:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:233:5 + --> $DIR/len_without_is_empty.rs:243:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` or `(&self) -> Result error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:228:5 + --> $DIR/len_without_is_empty.rs:236:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +98,7 @@ LL | pub fn len(&self) -> Result { = note: `-D clippy::result-unit-err` implied by `-D warnings` error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:240:5 + --> $DIR/len_without_is_empty.rs:250:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +106,7 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:244:5 + --> $DIR/len_without_is_empty.rs:255:5 | LL | pub fn is_empty(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +114,7 @@ LL | pub fn is_empty(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:251:5 + --> $DIR/len_without_is_empty.rs:263:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,19 +122,19 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:292:5 + --> $DIR/len_without_is_empty.rs:305:5 | LL | pub async fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:304:5 + --> $DIR/len_without_is_empty.rs:318:5 | LL | pub async fn len(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:325:5 + --> $DIR/len_without_is_empty.rs:340:5 | LL | pub async fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_and_return.fixed b/tests/ui/let_and_return.fixed index 32119996e3d9b..88b8ae6737583 100644 --- a/tests/ui/let_and_return.fixed +++ b/tests/ui/let_and_return.fixed @@ -7,12 +7,15 @@ fn test() -> i32 { let _y = 0; // no warning 5 + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn test_inner() -> i32 { if true { 5 + //~^ ERROR: returning the result of a `let` binding from a block } else { 0 } @@ -75,6 +78,7 @@ fn issue_3792() -> String { // https://github.com/rust-lang/rust/pull/93965 stdin.lock().lines().next().unwrap().unwrap() + //~^ ERROR: returning the result of a `let` binding from a block } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -165,6 +169,7 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { Arc::clone(&self.foo) as _ + //~^ ERROR: returning the result of a `let` binding from a block } } } diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index 64665cc906f61..f366842c5d771 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -7,12 +7,15 @@ fn test() -> i32 { let _y = 0; // no warning let x = 5; x + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn test_inner() -> i32 { if true { let x = 5; x + //~^ ERROR: returning the result of a `let` binding from a block } else { 0 } @@ -75,6 +78,7 @@ fn issue_3792() -> String { // https://github.com/rust-lang/rust/pull/93965 let line = stdin.lock().lines().next().unwrap().unwrap(); line + //~^ ERROR: returning the result of a `let` binding from a block } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -165,6 +169,7 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { let clone = Arc::clone(&self.foo); clone + //~^ ERROR: returning the result of a `let` binding from a block } } } diff --git a/tests/ui/let_and_return.stderr b/tests/ui/let_and_return.stderr index 4ca0a05c858fb..3f60b69df4567 100644 --- a/tests/ui/let_and_return.stderr +++ b/tests/ui/let_and_return.stderr @@ -14,7 +14,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:15:9 + --> $DIR/let_and_return.rs:17:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -28,7 +28,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:77:5 + --> $DIR/let_and_return.rs:80:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -42,7 +42,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:167:13 + --> $DIR/let_and_return.rs:171:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index 1271a1c123607..9869d945299e0 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -64,11 +64,15 @@ fn main() { issue985_alt(); let mut foo = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { foo = 42; } let mut bar = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { f(); bar = 42; @@ -77,6 +81,7 @@ fn main() { } let quz; + //~^ ERROR: `if _ { .. } else { .. }` is an expression if f() { quz = 42; } else { @@ -106,6 +111,8 @@ fn main() { // baz needs to be mut let mut baz = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { baz = 42; } diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index f2e0edb6fbc30..b739268dacd55 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -2,6 +2,8 @@ error: `if _ { .. } else { .. }` is an expression --> $DIR/let_if_seq.rs:66:5 | LL | / let mut foo = 0; +LL | | +LL | | LL | | if f() { LL | | foo = 42; LL | | } @@ -11,13 +13,13 @@ LL | | } = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:71:5 + --> $DIR/let_if_seq.rs:73:5 | LL | / let mut bar = 0; +LL | | +LL | | LL | | if f() { -LL | | f(); -LL | | bar = 42; -LL | | } else { +... | LL | | f(); LL | | } | |_____^ help: it is more idiomatic to write: `let bar = if f() { ..; 42 } else { ..; 0 };` @@ -25,9 +27,10 @@ LL | | } = note: you might not need `mut` at all error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:79:5 + --> $DIR/let_if_seq.rs:83:5 | LL | / let quz; +LL | | LL | | if f() { LL | | quz = 42; LL | | } else { @@ -36,9 +39,11 @@ LL | | } | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:108:5 + --> $DIR/let_if_seq.rs:113:5 | LL | / let mut baz = 0; +LL | | +LL | | LL | | if f() { LL | | baz = 42; LL | | } diff --git a/tests/ui/let_underscore_future.rs b/tests/ui/let_underscore_future.rs index f904868577db2..873ae667ab71a 100644 --- a/tests/ui/let_underscore_future.rs +++ b/tests/ui/let_underscore_future.rs @@ -9,12 +9,17 @@ fn custom() -> impl Future { } fn do_something_to_future(future: &mut impl Future) {} +//~^ ERROR: this argument is a mutable reference, but not used mutably +//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` fn main() { let _ = some_async_fn(); + //~^ ERROR: non-binding `let` on a future let _ = custom(); + //~^ ERROR: non-binding `let` on a future let mut future = some_async_fn(); do_something_to_future(&mut future); let _ = future; + //~^ ERROR: non-binding `let` on a future } diff --git a/tests/ui/let_underscore_future.stderr b/tests/ui/let_underscore_future.stderr index ff1e2b8c90195..e3a628236e708 100644 --- a/tests/ui/let_underscore_future.stderr +++ b/tests/ui/let_underscore_future.stderr @@ -1,5 +1,5 @@ error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:14:5 + --> $DIR/let_underscore_future.rs:16:5 | LL | let _ = some_async_fn(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let _ = some_async_fn(); = note: `-D clippy::let-underscore-future` implied by `-D warnings` error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:15:5 + --> $DIR/let_underscore_future.rs:18:5 | LL | let _ = custom(); | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = custom(); = help: consider awaiting the future or dropping explicitly with `std::mem::drop` error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:19:5 + --> $DIR/let_underscore_future.rs:23:5 | LL | let _ = future; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_underscore_lock.rs b/tests/ui/let_underscore_lock.rs index 87f12e2789f09..ccac73be79e4d 100644 --- a/tests/ui/let_underscore_lock.rs +++ b/tests/ui/let_underscore_lock.rs @@ -8,13 +8,17 @@ fn main() { let p_m: Mutex<()> = Mutex::const_new(RawMutex::INIT, ()); let _ = p_m.lock(); + //~^ ERROR: non-binding `let` on a synchronization lock let p_m1 = Mutex::new(0); let _ = p_m1.lock(); + //~^ ERROR: non-binding `let` on a synchronization lock let p_rw = RwLock::new(0); let _ = p_rw.read(); + //~^ ERROR: non-binding `let` on a synchronization lock let _ = p_rw.write(); + //~^ ERROR: non-binding `let` on a synchronization lock // These shouldn't throw an error. let _ = p_m; diff --git a/tests/ui/let_underscore_lock.stderr b/tests/ui/let_underscore_lock.stderr index 5027e6b3cbc77..9c9ff9c917c87 100644 --- a/tests/ui/let_underscore_lock.stderr +++ b/tests/ui/let_underscore_lock.stderr @@ -8,7 +8,7 @@ LL | let _ = p_m.lock(); = note: `-D clippy::let-underscore-lock` implied by `-D warnings` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:13:5 + --> $DIR/let_underscore_lock.rs:14:5 | LL | let _ = p_m1.lock(); | ^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = p_m1.lock(); = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:16:5 + --> $DIR/let_underscore_lock.rs:18:5 | LL | let _ = p_rw.read(); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = p_rw.read(); = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:17:5 + --> $DIR/let_underscore_lock.rs:20:5 | LL | let _ = p_rw.write(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index 1edb77c748bfb..3290d087724e6 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -65,30 +65,42 @@ impl Trait for S { fn main() { let _ = f(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = g(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = h(); let _ = l(0_u32); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let s = S {}; let _ = s.f(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = s.g(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = s.k(); let _ = S::h(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = S::p(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = S::a(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = if true { Ok(()) } else { Err(()) }; + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let a = Result::<(), ()>::Ok(()); let _ = a.is_ok(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = a.map(|_| ()); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = a; + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type #[allow(clippy::let_underscore_must_use)] let _ = a; diff --git a/tests/ui/let_underscore_must_use.stderr b/tests/ui/let_underscore_must_use.stderr index 28d760eb46ecc..5cd02a6e81221 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -8,7 +8,7 @@ LL | let _ = f(); = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:68:5 + --> $DIR/let_underscore_must_use.rs:69:5 | LL | let _ = g(); | ^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:70:5 + --> $DIR/let_underscore_must_use.rs:72:5 | LL | let _ = l(0_u32); | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = l(0_u32); = help: consider explicitly using function result error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:74:5 + --> $DIR/let_underscore_must_use.rs:77:5 | LL | let _ = s.f(); | ^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = s.f(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:75:5 + --> $DIR/let_underscore_must_use.rs:79:5 | LL | let _ = s.g(); | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _ = s.g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:78:5 + --> $DIR/let_underscore_must_use.rs:83:5 | LL | let _ = S::h(); | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _ = S::h(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:79:5 + --> $DIR/let_underscore_must_use.rs:85:5 | LL | let _ = S::p(); | ^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = S::p(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:81:5 + --> $DIR/let_underscore_must_use.rs:88:5 | LL | let _ = S::a(); | ^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _ = S::a(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:83:5 + --> $DIR/let_underscore_must_use.rs:91:5 | LL | let _ = if true { Ok(()) } else { Err(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let _ = if true { Ok(()) } else { Err(()) }; = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:87:5 + --> $DIR/let_underscore_must_use.rs:96:5 | LL | let _ = a.is_ok(); | ^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | let _ = a.is_ok(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:89:5 + --> $DIR/let_underscore_must_use.rs:99:5 | LL | let _ = a.map(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | let _ = a.map(|_| ()); = help: consider explicitly using expression value error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:91:5 + --> $DIR/let_underscore_must_use.rs:102:5 | LL | let _ = a; | ^^^^^^^^^^ diff --git a/tests/ui/linkedlist.rs b/tests/ui/linkedlist.rs index 690ea810a6214..e1e6cff980979 100644 --- a/tests/ui/linkedlist.rs +++ b/tests/ui/linkedlist.rs @@ -6,12 +6,17 @@ extern crate alloc; use alloc::collections::linked_list::LinkedList; const C: LinkedList = LinkedList::new(); +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu static S: LinkedList = LinkedList::new(); +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu trait Foo { type Baz = LinkedList; + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str fn foo(_: LinkedList); + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str const BAR: Option>; + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str } // Ok, we don’t want to warn for implementations; see issue #605. @@ -22,16 +27,20 @@ impl Foo for LinkedList { pub struct Bar { priv_linked_list_field: LinkedList, + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str pub pub_linked_list_field: LinkedList, } impl Bar { fn foo(_: LinkedList) {} + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str } // All of these test should be trigger the lint because they are not // part of the public api fn test(my_favorite_linked_list: LinkedList) {} +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu fn test_ret() -> Option> { + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu None } fn test_local_not_linted() { diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index c76c949613129..b31b0cd9314e6 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -8,7 +8,7 @@ LL | const C: LinkedList = LinkedList::new(); = note: `-D clippy::linkedlist` implied by `-D warnings` error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:9:11 + --> $DIR/linkedlist.rs:10:11 | LL | static S: LinkedList = LinkedList::new(); | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static S: LinkedList = LinkedList::new(); = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:12:16 + --> $DIR/linkedlist.rs:14:16 | LL | type Baz = LinkedList; | ^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type Baz = LinkedList; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:13:15 + --> $DIR/linkedlist.rs:16:15 | LL | fn foo(_: LinkedList); | ^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn foo(_: LinkedList); = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:14:23 + --> $DIR/linkedlist.rs:18:23 | LL | const BAR: Option>; | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | const BAR: Option>; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:24:29 + --> $DIR/linkedlist.rs:29:29 | LL | priv_linked_list_field: LinkedList, | ^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | priv_linked_list_field: LinkedList, = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:28:15 + --> $DIR/linkedlist.rs:34:15 | LL | fn foo(_: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn foo(_: LinkedList) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:33:34 + --> $DIR/linkedlist.rs:40:34 | LL | fn test(my_favorite_linked_list: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn test(my_favorite_linked_list: LinkedList) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:34:25 + --> $DIR/linkedlist.rs:42:25 | LL | fn test_ret() -> Option> { | ^^^^^^^^^^^^^^ diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index 1a276153c7383..c275b04d886bb 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -11,16 +11,32 @@ fn main() { let ok1 = 0xABCD; let ok3 = 0xab_cd; let ok4 = 0xab_cd_i32; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| NOTE: `-D clippy::separated-literal-suffix` implied by `-D warnings` let ok5 = 0xAB_CD_u32; + //~^ ERROR: integer type suffix should not be separated by an underscore let ok5 = 0xAB_CD_isize; + //~^ ERROR: integer type suffix should not be separated by an underscore let fail1 = 0xabCD; + //~^ ERROR: inconsistent casing in hexadecimal literal + //~| NOTE: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` let fail2 = 0xabCD_u32; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| ERROR: inconsistent casing in hexadecimal literal let fail2 = 0xabCD_isize; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| ERROR: inconsistent casing in hexadecimal literal let fail_multi_zero = 000_123usize; + //~^ ERROR: integer type suffix should be separated by an underscore + //~| NOTE: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + //~| ERROR: this is a decimal constant + //~| NOTE: `-D clippy::zero-prefixed-literal` implied by `-D warnings` let ok9 = 0; let ok10 = 0_i64; + //~^ ERROR: integer type suffix should not be separated by an underscore let fail8 = 0123; + //~^ ERROR: this is a decimal constant let ok11 = 0o123; let ok12 = 0b10_1010; @@ -30,13 +46,20 @@ fn main() { let ok15 = 0xab_cabc_abca_bcab_cabc; let ok16 = 0xFE_BAFE_ABAB_ABCD; let ok17 = 0x123_4567_8901_usize; + //~^ ERROR: integer type suffix should not be separated by an underscore let ok18 = 0xF; let fail19 = 12_3456_21; + //~^ ERROR: digits grouped inconsistently by underscores + //~| NOTE: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` let fail22 = 3__4___23; + //~^ ERROR: digits grouped inconsistently by underscores let fail23 = 3__16___23; + //~^ ERROR: digits grouped inconsistently by underscores let fail24 = 0xAB_ABC_AB; + //~^ ERROR: digits of hex, binary or octal literal not in groups of equal size + //~| NOTE: `-D clippy::unusual-byte-groupings` implied by `-D warnings` let fail25 = 0b01_100_101; let ok26 = 0x6_A0_BF; let ok27 = 0b1_0010_0101; @@ -45,6 +68,9 @@ fn main() { fn issue9651() { // lint but octal form is not possible here let _ = 08; + //~^ ERROR: this is a decimal constant let _ = 09; + //~^ ERROR: this is a decimal constant let _ = 089; + //~^ ERROR: this is a decimal constant } diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 2a7785d4fb245..7c79436752fca 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -7,19 +7,19 @@ LL | let ok4 = 0xab_cd_i32; = note: `-D clippy::separated-literal-suffix` implied by `-D warnings` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:14:15 + --> $DIR/literals.rs:16:15 | LL | let ok5 = 0xAB_CD_u32; | ^^^^^^^^^^^ help: remove the underscore: `0xAB_CDu32` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:15:15 + --> $DIR/literals.rs:18:15 | LL | let ok5 = 0xAB_CD_isize; | ^^^^^^^^^^^^^ help: remove the underscore: `0xAB_CDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:16:17 + --> $DIR/literals.rs:20:17 | LL | let fail1 = 0xabCD; | ^^^^^^ @@ -27,31 +27,31 @@ LL | let fail1 = 0xabCD; = note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:23:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ help: remove the underscore: `0xabCDu32` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:23:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:18:17 + --> $DIR/literals.rs:26:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ help: remove the underscore: `0xabCDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:18:17 + --> $DIR/literals.rs:26:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ error: integer type suffix should be separated by an underscore - --> $DIR/literals.rs:19:27 + --> $DIR/literals.rs:29:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` @@ -59,7 +59,7 @@ LL | let fail_multi_zero = 000_123usize; = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` error: this is a decimal constant - --> $DIR/literals.rs:19:27 + --> $DIR/literals.rs:29:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ @@ -75,13 +75,13 @@ LL | let fail_multi_zero = 0o123usize; | ~~~~~~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:22:16 + --> $DIR/literals.rs:36:16 | LL | let ok10 = 0_i64; | ^^^^^ help: remove the underscore: `0i64` error: this is a decimal constant - --> $DIR/literals.rs:23:17 + --> $DIR/literals.rs:38:17 | LL | let fail8 = 0123; | ^^^^ @@ -96,13 +96,13 @@ LL | let fail8 = 0o123; | ~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:32:16 + --> $DIR/literals.rs:48:16 | LL | let ok17 = 0x123_4567_8901_usize; | ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:35:18 + --> $DIR/literals.rs:52:18 | LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` @@ -110,19 +110,19 @@ LL | let fail19 = 12_3456_21; = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:36:18 + --> $DIR/literals.rs:55:18 | LL | let fail22 = 3__4___23; | ^^^^^^^^^ help: consider: `3_423` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:37:18 + --> $DIR/literals.rs:57:18 | LL | let fail23 = 3__16___23; | ^^^^^^^^^^ help: consider: `31_623` error: digits of hex, binary or octal literal not in groups of equal size - --> $DIR/literals.rs:39:18 + --> $DIR/literals.rs:60:18 | LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` @@ -130,7 +130,7 @@ LL | let fail24 = 0xAB_ABC_AB; = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` error: this is a decimal constant - --> $DIR/literals.rs:47:13 + --> $DIR/literals.rs:70:13 | LL | let _ = 08; | ^^ @@ -141,7 +141,7 @@ LL | let _ = 8; | ~ error: this is a decimal constant - --> $DIR/literals.rs:48:13 + --> $DIR/literals.rs:72:13 | LL | let _ = 09; | ^^ @@ -152,7 +152,7 @@ LL | let _ = 9; | ~ error: this is a decimal constant - --> $DIR/literals.rs:49:13 + --> $DIR/literals.rs:74:13 | LL | let _ = 089; | ^^^ diff --git a/tests/ui/manual_clamp.fixed b/tests/ui/manual_clamp.fixed index 592d172228147..c5355cce8e212 100644 --- a/tests/ui/manual_clamp.fixed +++ b/tests/ui/manual_clamp.fixed @@ -27,8 +27,12 @@ fn main() { let x3 = input.clamp(min, max); let x4 = input.clamp(min, max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x5 = input.clamp(min, max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x6 = input.clamp(min, max); @@ -60,22 +64,54 @@ fn main() { let input: i32 = cmp_min_max(1); // These can only be detected if exactly one of the arguments to the inner function is const. let x16 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x17 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x18 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x19 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x20 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x21 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x22 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x23 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let input: f64 = cmp_min_max(1) as f64; let x24 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x25 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x26 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x27 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x28 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x29 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x30 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x31 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() } let mut x32 = input; x32 = x32.clamp(min, max); diff --git a/tests/ui/manual_clamp.rs b/tests/ui/manual_clamp.rs index cdfd8e4c3fe3e..cacb40ae027f3 100644 --- a/tests/ui/manual_clamp.rs +++ b/tests/ui/manual_clamp.rs @@ -19,6 +19,8 @@ fn main() { let (input, min, max) = (0, -2, 3); // Lint let x0 = if max < input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min max } else if min > input { min @@ -27,6 +29,8 @@ fn main() { }; let x1 = if input > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min max } else if input < min { min @@ -35,6 +39,8 @@ fn main() { }; let x2 = if input < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if input > max { max @@ -43,6 +49,8 @@ fn main() { }; let x3 = if min > input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if max < input { max @@ -51,22 +59,32 @@ fn main() { }; let x4 = input.max(min).min(max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x5 = input.min(max).max(min); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x6 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if x > max => max, x if x < min => min, x => x, }; let x7 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if x < min => min, x if x > max => max, x => x, }; let x8 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if max < x => max, x if min > x => min, x => x, @@ -74,6 +92,8 @@ fn main() { let mut x9 = input; if x9 < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x9 = min; } if x9 > max { @@ -81,6 +101,8 @@ fn main() { } let x10 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if min > x => min, x if max < x => max, x => x, @@ -89,6 +111,8 @@ fn main() { let mut x11 = input; let _ = 1; if x11 > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x11 = max; } if x11 < min { @@ -97,6 +121,8 @@ fn main() { let mut x12 = input; if min > x12 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x12 = min; } if max < x12 { @@ -105,6 +131,8 @@ fn main() { let mut x13 = input; if max < x13 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x13 = max; } if min > x13 { @@ -112,6 +140,8 @@ fn main() { } let x14 = if input > CONST_MAX { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min CONST_MAX } else if input < CONST_MIN { CONST_MIN @@ -121,6 +151,8 @@ fn main() { { let (input, min, max) = (0.0f64, -2.0, 3.0); let x15 = if input > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() max } else if input < min { min @@ -132,25 +164,59 @@ fn main() { let input: i32 = cmp_min_max(1); // These can only be detected if exactly one of the arguments to the inner function is const. let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let input: f64 = cmp_min_max(1) as f64; let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() } let mut x32 = input; if x32 < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x32 = min; } else if x32 > max { x32 = max; @@ -159,6 +225,8 @@ fn main() { // It's important this be the last set of statements let mut x33 = input; if max < x33 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x33 = max; } if min > x33 { @@ -319,6 +387,8 @@ fn msrv_1_49() { fn msrv_1_50() { let (input, min, max) = (0, -1, 2); let _ = if input < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if input > max { max diff --git a/tests/ui/manual_clamp.stderr b/tests/ui/manual_clamp.stderr index 988ad1527e837..95e0cf5d4ec51 100644 --- a/tests/ui/manual_clamp.stderr +++ b/tests/ui/manual_clamp.stderr @@ -1,10 +1,11 @@ error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:76:5 + --> $DIR/manual_clamp.rs:94:5 | LL | / if x9 < min { +LL | | +LL | | LL | | x9 = min; -LL | | } -LL | | if x9 > max { +... | LL | | x9 = max; LL | | } | |_____^ help: replace with clamp: `x9 = x9.clamp(min, max);` @@ -13,12 +14,13 @@ LL | | } = note: `-D clippy::manual-clamp` implied by `-D warnings` error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:91:5 + --> $DIR/manual_clamp.rs:113:5 | LL | / if x11 > max { +LL | | +LL | | LL | | x11 = max; -LL | | } -LL | | if x11 < min { +... | LL | | x11 = min; LL | | } | |_____^ help: replace with clamp: `x11 = x11.clamp(min, max);` @@ -26,12 +28,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:99:5 + --> $DIR/manual_clamp.rs:123:5 | LL | / if min > x12 { +LL | | +LL | | LL | | x12 = min; -LL | | } -LL | | if max < x12 { +... | LL | | x12 = max; LL | | } | |_____^ help: replace with clamp: `x12 = x12.clamp(min, max);` @@ -39,12 +42,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:107:5 + --> $DIR/manual_clamp.rs:133:5 | LL | / if max < x13 { +LL | | +LL | | LL | | x13 = max; -LL | | } -LL | | if min > x13 { +... | LL | | x13 = min; LL | | } | |_____^ help: replace with clamp: `x13 = x13.clamp(min, max);` @@ -52,12 +56,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:161:5 + --> $DIR/manual_clamp.rs:227:5 | LL | / if max < x33 { +LL | | +LL | | LL | | x33 = max; -LL | | } -LL | | if min > x33 { +... | LL | | x33 = min; LL | | } | |_____^ help: replace with clamp: `x33 = x33.clamp(min, max);` @@ -69,10 +74,10 @@ error: clamp-like pattern without using clamp function | LL | let x0 = if max < input { | ______________^ +LL | | +LL | | LL | | max -LL | | } else if min > input { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -80,14 +85,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:29:14 + --> $DIR/manual_clamp.rs:31:14 | LL | let x1 = if input > max { | ______________^ +LL | | +LL | | LL | | max -LL | | } else if input < min { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -95,14 +100,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:37:14 + --> $DIR/manual_clamp.rs:41:14 | LL | let x2 = if input < min { | ______________^ +LL | | +LL | | LL | | min -LL | | } else if input > max { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -110,14 +115,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:45:14 + --> $DIR/manual_clamp.rs:51:14 | LL | let x3 = if min > input { | ______________^ +LL | | +LL | | LL | | min -LL | | } else if max < input { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -125,7 +130,7 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:53:14 + --> $DIR/manual_clamp.rs:61:14 | LL | let x4 = input.max(min).min(max); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)` @@ -133,7 +138,7 @@ LL | let x4 = input.max(min).min(max); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:55:14 + --> $DIR/manual_clamp.rs:65:14 | LL | let x5 = input.min(max).max(min); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)` @@ -141,10 +146,12 @@ LL | let x5 = input.min(max).max(min); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:57:14 + --> $DIR/manual_clamp.rs:69:14 | LL | let x6 = match input { | ______________^ +LL | | +LL | | LL | | x if x > max => max, LL | | x if x < min => min, LL | | x => x, @@ -154,10 +161,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:63:14 + --> $DIR/manual_clamp.rs:77:14 | LL | let x7 = match input { | ______________^ +LL | | +LL | | LL | | x if x < min => min, LL | | x if x > max => max, LL | | x => x, @@ -167,10 +176,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:69:14 + --> $DIR/manual_clamp.rs:85:14 | LL | let x8 = match input { | ______________^ +LL | | +LL | | LL | | x if max < x => max, LL | | x if min > x => min, LL | | x => x, @@ -180,10 +191,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:83:15 + --> $DIR/manual_clamp.rs:103:15 | LL | let x10 = match input { | _______________^ +LL | | +LL | | LL | | x if min > x => min, LL | | x if max < x => max, LL | | x => x, @@ -193,14 +206,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:114:15 + --> $DIR/manual_clamp.rs:142:15 | LL | let x14 = if input > CONST_MAX { | _______________^ +LL | | +LL | | LL | | CONST_MAX -LL | | } else if input < CONST_MIN { -LL | | CONST_MIN -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -208,14 +221,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:123:19 + --> $DIR/manual_clamp.rs:153:19 | LL | let x15 = if input > max { | ___________________^ +LL | | +LL | | LL | | max -LL | | } else if input < min { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_________^ help: replace with clamp: `input.clamp(min, max)` @@ -224,7 +237,7 @@ LL | | }; = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:134:19 + --> $DIR/manual_clamp.rs:166:19 | LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -232,7 +245,7 @@ LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:135:19 + --> $DIR/manual_clamp.rs:169:19 | LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -240,7 +253,7 @@ LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:136:19 + --> $DIR/manual_clamp.rs:172:19 | LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -248,7 +261,7 @@ LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:137:19 + --> $DIR/manual_clamp.rs:175:19 | LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -256,7 +269,7 @@ LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:138:19 + --> $DIR/manual_clamp.rs:178:19 | LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -264,7 +277,7 @@ LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:139:19 + --> $DIR/manual_clamp.rs:181:19 | LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -272,7 +285,7 @@ LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:140:19 + --> $DIR/manual_clamp.rs:184:19 | LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -280,7 +293,7 @@ LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:141:19 + --> $DIR/manual_clamp.rs:187:19 | LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -288,7 +301,7 @@ LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:143:19 + --> $DIR/manual_clamp.rs:191:19 | LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -297,7 +310,7 @@ LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:144:19 + --> $DIR/manual_clamp.rs:194:19 | LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -306,7 +319,7 @@ LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:145:19 + --> $DIR/manual_clamp.rs:197:19 | LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -315,7 +328,7 @@ LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:146:19 + --> $DIR/manual_clamp.rs:200:19 | LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -324,7 +337,7 @@ LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:147:19 + --> $DIR/manual_clamp.rs:203:19 | LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -333,7 +346,7 @@ LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:148:19 + --> $DIR/manual_clamp.rs:206:19 | LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -342,7 +355,7 @@ LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:149:19 + --> $DIR/manual_clamp.rs:209:19 | LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -351,7 +364,7 @@ LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:150:19 + --> $DIR/manual_clamp.rs:212:19 | LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -360,9 +373,11 @@ LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:153:5 + --> $DIR/manual_clamp.rs:217:5 | LL | / if x32 < min { +LL | | +LL | | LL | | x32 = min; LL | | } else if x32 > max { LL | | x32 = max; @@ -372,14 +387,14 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:321:13 + --> $DIR/manual_clamp.rs:389:13 | LL | let _ = if input < min { | _____________^ +LL | | +LL | | LL | | min -LL | | } else if input > max { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` diff --git a/tests/ui/manual_find.rs b/tests/ui/manual_find.rs index bab37c465353a..0a105b0359e50 100644 --- a/tests/ui/manual_find.rs +++ b/tests/ui/manual_find.rs @@ -3,6 +3,8 @@ //@no-rustfix fn vec_string(strings: Vec) -> Option { for s in strings { + //~^ ERROR: manual implementation of `Iterator::find` + //~| NOTE: you may need to dereference some variables if s == String::new() { return Some(s); } @@ -12,6 +14,8 @@ fn vec_string(strings: Vec) -> Option { fn tuple(arr: Vec<(String, i32)>) -> Option { for (s, _) in arr { + //~^ ERROR: manual implementation of `Iterator::find` + //~| NOTE: you may need to dereference some variables if s == String::new() { return Some(s); } diff --git a/tests/ui/manual_find.stderr b/tests/ui/manual_find.stderr index ea04bb066e61d..41aa00a8bc14b 100644 --- a/tests/ui/manual_find.stderr +++ b/tests/ui/manual_find.stderr @@ -2,9 +2,10 @@ error: manual implementation of `Iterator::find` --> $DIR/manual_find.rs:5:5 | LL | / for s in strings { +LL | | +LL | | LL | | if s == String::new() { -LL | | return Some(s); -LL | | } +... | LL | | } LL | | None | |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())` @@ -13,12 +14,13 @@ LL | | None = note: `-D clippy::manual-find` implied by `-D warnings` error: manual implementation of `Iterator::find` - --> $DIR/manual_find.rs:14:5 + --> $DIR/manual_find.rs:16:5 | LL | / for (s, _) in arr { +LL | | +LL | | LL | | if s == String::new() { -LL | | return Some(s); -LL | | } +... | LL | | } LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(s, _)| s).find(|s| s == String::new())` diff --git a/tests/ui/manual_flatten.rs b/tests/ui/manual_flatten.rs index b7ea0644d29a9..d57333ace040d 100644 --- a/tests/ui/manual_flatten.rs +++ b/tests/ui/manual_flatten.rs @@ -5,6 +5,7 @@ fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` expression let x = vec![Some(1), Some(2), Some(3)]; for n in x { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(y) = n { println!("{}", y); } @@ -13,6 +14,7 @@ fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` statement let y: Vec> = vec![]; for n in y.clone() { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); }; @@ -20,6 +22,7 @@ fn main() { // Test for loop over by reference for n in &y { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); } @@ -28,6 +31,7 @@ fn main() { // Test for loop over an implicit reference let z = &y; for n in z { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); } @@ -37,6 +41,7 @@ fn main() { let z = vec![Some(1), Some(2), Some(3)]; let z = z.iter(); for n in z { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(m) = n { println!("{}", m); } @@ -70,6 +75,7 @@ fn main() { let vec_of_ref = vec![&Some(1)]; for n in &vec_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -77,6 +83,7 @@ fn main() { let vec_of_ref = &vec_of_ref; for n in vec_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -84,6 +91,7 @@ fn main() { let slice_of_ref = &[&Some(1)]; for n in slice_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -114,6 +122,7 @@ fn main() { fn run_unformatted_tests() { // Skip rustfmt here on purpose so the suggestion does not fit in one line for n in vec![ + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element Some(1), Some(2), Some(3) diff --git a/tests/ui/manual_flatten.stderr b/tests/ui/manual_flatten.stderr index 180a6ff4e9a73..227bf3c5eaedf 100644 --- a/tests/ui/manual_flatten.stderr +++ b/tests/ui/manual_flatten.stderr @@ -5,6 +5,7 @@ LL | for n in x { | ^ - help: try: `x.into_iter().flatten()` | _____| | | +LL | | LL | | if let Some(y) = n { LL | | println!("{}", y); LL | | } @@ -12,7 +13,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:8:9 + --> $DIR/manual_flatten.rs:9:9 | LL | / if let Some(y) = n { LL | | println!("{}", y); @@ -21,12 +22,13 @@ LL | | } = note: `-D clippy::manual-flatten` implied by `-D warnings` error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:15:5 + --> $DIR/manual_flatten.rs:16:5 | LL | for n in y.clone() { | ^ --------- help: try: `y.clone().into_iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | }; @@ -34,7 +36,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:16:9 + --> $DIR/manual_flatten.rs:18:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -42,12 +44,13 @@ LL | | }; | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:22:5 + --> $DIR/manual_flatten.rs:24:5 | LL | for n in &y { | ^ -- help: try: `y.iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | } @@ -55,7 +58,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:23:9 + --> $DIR/manual_flatten.rs:26:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -63,12 +66,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:30:5 + --> $DIR/manual_flatten.rs:33:5 | LL | for n in z { | ^ - help: try: `z.iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | } @@ -76,7 +80,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:31:9 + --> $DIR/manual_flatten.rs:35:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -84,12 +88,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:39:5 + --> $DIR/manual_flatten.rs:43:5 | LL | for n in z { | ^ - help: try: `z.flatten()` | _____| | | +LL | | LL | | if let Some(m) = n { LL | | println!("{}", m); LL | | } @@ -97,7 +102,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:40:9 + --> $DIR/manual_flatten.rs:45:9 | LL | / if let Some(m) = n { LL | | println!("{}", m); @@ -105,12 +110,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:72:5 + --> $DIR/manual_flatten.rs:77:5 | LL | for n in &vec_of_ref { | ^ ----------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -118,7 +124,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:73:9 + --> $DIR/manual_flatten.rs:79:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -126,12 +132,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:79:5 + --> $DIR/manual_flatten.rs:85:5 | LL | for n in vec_of_ref { | ^ ---------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -139,7 +146,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:80:9 + --> $DIR/manual_flatten.rs:87:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -147,12 +154,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:86:5 + --> $DIR/manual_flatten.rs:93:5 | LL | for n in slice_of_ref { | ^ ------------ help: try: `slice_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -160,7 +168,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:87:9 + --> $DIR/manual_flatten.rs:95:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -168,19 +176,19 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:116:5 + --> $DIR/manual_flatten.rs:124:5 | LL | / for n in vec![ +LL | | LL | | Some(1), LL | | Some(2), -LL | | Some(3) ... | LL | | } LL | | } | |_____^ | help: remove the `if let` statement in the for loop and then... - --> $DIR/manual_flatten.rs:121:9 + --> $DIR/manual_flatten.rs:130:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -189,6 +197,7 @@ LL | | } help: try | LL ~ for n in vec![ +LL + LL + Some(1), LL + Some(2), LL + Some(3) diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index 0cb525566809f..6775fdc921f9a 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -23,13 +23,17 @@ fn main() {} fn fire() { let v = if let Some(v_some) = g() { v_some } else { return }; + //~^ ERROR: this could be rewritten as `let...else` + //~| NOTE: `-D clippy::manual-let-else` implied by `-D warnings` let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { return; }; let v = if let Some(v) = g() { + //~^ ERROR: this could be rewritten as `let...else` // Blocks around the identity should have no impact { { v } @@ -43,14 +47,18 @@ fn fire() { // continue and break diverge loop { let v = if let Some(v_some) = g() { v_some } else { continue }; + //~^ ERROR: this could be rewritten as `let...else` let v = if let Some(v_some) = g() { v_some } else { break }; + //~^ ERROR: this could be rewritten as `let...else` } // panic also diverges let v = if let Some(v_some) = g() { v_some } else { panic!() }; + //~^ ERROR: this could be rewritten as `let...else` // abort also diverges let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { std::process::abort() @@ -58,6 +66,7 @@ fn fire() { // If whose two branches diverge also diverges let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { if true { return } else { panic!() } @@ -65,6 +74,7 @@ fn fire() { // Diverging after an if still makes the block diverge: let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { if true {} @@ -75,6 +85,7 @@ fn fire() { // Note: the corresponding let-else requires a ; at the end of the match // as otherwise the type checker does not turn it into a ! type. let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match () { @@ -85,9 +96,11 @@ fn fire() { // An if's expression can cause divergence: let v = if let Some(v_some) = g() { v_some } else { if panic!() {} }; + //~^ ERROR: this could be rewritten as `let...else` // An expression of a match can cause divergence: let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match panic!() { @@ -97,6 +110,7 @@ fn fire() { // Top level else if let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else if true { return; @@ -106,6 +120,7 @@ fn fire() { // All match arms diverge let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match (g(), g()) { @@ -123,6 +138,7 @@ fn fire() { // Tuples supported for the declared variables let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { return; @@ -130,6 +146,7 @@ fn fire() { // Tuples supported with multiple bindings let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { + //~^ ERROR: this could be rewritten as `let...else` (w_some, v_some) } else { return; @@ -148,25 +165,31 @@ fn fire() { } let v = if let Variant::A(a, 0) = e() { a } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // `mut v` is inserted into the pattern let mut v = if let Variant::B(b) = e() { b } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // Nesting works let nested = Ok(Some(e())); let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { + //~^ ERROR: this could be rewritten as `let...else` b } else { return; }; // dot dot works let v = if let Variant::A(.., a) = e() { a } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // () is preserved: a bit of an edge case but make sure it stays around let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // Tuple structs work let w = if let Some(S { v: x }) = Some(S { v: 0 }) { + //~^ ERROR: this could be rewritten as `let...else` x } else { return; @@ -174,6 +197,7 @@ fn fire() { // Field init shorthand is suggested let v = if let Some(S { v: x }) = Some(S { v: 0 }) { + //~^ ERROR: this could be rewritten as `let...else` x } else { return; @@ -181,6 +205,7 @@ fn fire() { // Multi-field structs also work let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { + //~^ ERROR: this could be rewritten as `let...else` (x, v, w) } else { return; @@ -297,6 +322,7 @@ fn not_fire() { let ff = Some(1); let _ = match ff { + //~^ ERROR: this could be rewritten as `let...else` Some(value) => value, _ => macro_call!(), }; diff --git a/tests/ui/manual_let_else.stderr b/tests/ui/manual_let_else.stderr index 912302b17a8f4..309ce3986f370 100644 --- a/tests/ui/manual_let_else.stderr +++ b/tests/ui/manual_let_else.stderr @@ -7,9 +7,10 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; = note: `-D clippy::manual-let-else` implied by `-D warnings` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:26:5 + --> $DIR/manual_let_else.rs:28:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | return; @@ -24,12 +25,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:32:5 + --> $DIR/manual_let_else.rs:35:5 | LL | / let v = if let Some(v) = g() { +LL | | LL | | // Blocks around the identity should have no impact LL | | { -LL | | { v } ... | LL | | return; LL | | }; @@ -45,27 +46,28 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:45:9 + --> $DIR/manual_let_else.rs:49:9 | LL | let v = if let Some(v_some) = g() { v_some } else { continue }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:46:9 + --> $DIR/manual_let_else.rs:51:9 | LL | let v = if let Some(v_some) = g() { v_some } else { break }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { break };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:50:5 + --> $DIR/manual_let_else.rs:56:5 | LL | let v = if let Some(v_some) = g() { v_some } else { panic!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { panic!() };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:53:5 + --> $DIR/manual_let_else.rs:60:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | std::process::abort() @@ -80,9 +82,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:60:5 + --> $DIR/manual_let_else.rs:68:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | if true { return } else { panic!() } @@ -97,9 +100,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:67:5 + --> $DIR/manual_let_else.rs:76:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | if true {} @@ -116,12 +120,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:77:5 + --> $DIR/manual_let_else.rs:87:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match () { ... | LL | | } LL | | }; @@ -138,19 +142,19 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:87:5 + --> $DIR/manual_let_else.rs:98:5 | LL | let v = if let Some(v_some) = g() { v_some } else { if panic!() {} }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { if panic!() {} };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:90:5 + --> $DIR/manual_let_else.rs:102:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match panic!() { -LL | | _ => {}, +... | LL | | } LL | | }; | |______^ @@ -165,13 +169,13 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:99:5 + --> $DIR/manual_let_else.rs:112:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else if true { -LL | | return; -LL | | } else { +... | LL | | panic!("diverge"); LL | | }; | |______^ @@ -186,12 +190,12 @@ LL + } }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:108:5 + --> $DIR/manual_let_else.rs:122:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match (g(), g()) { ... | LL | | } LL | | }; @@ -215,9 +219,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:125:5 + --> $DIR/manual_let_else.rs:140:5 | LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { +LL | | LL | | v_some LL | | } else { LL | | return; @@ -232,9 +237,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:132:5 + --> $DIR/manual_let_else.rs:148:5 | LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { +LL | | LL | | (w_some, v_some) LL | | } else { LL | | return; @@ -249,7 +255,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:141:13 + --> $DIR/manual_let_else.rs:158:13 | LL | let $n = if let Some(v) = $e { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };` @@ -260,21 +266,22 @@ LL | create_binding_if_some!(w, g()); = note: this error originates in the macro `create_binding_if_some` (in Nightly builds, run with -Z macro-backtrace for more info) error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:150:5 + --> $DIR/manual_let_else.rs:167:5 | LL | let v = if let Variant::A(a, 0) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(v, 0) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:153:5 + --> $DIR/manual_let_else.rs:171:5 | LL | let mut v = if let Variant::B(b) = e() { b } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::B(mut v) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:157:5 + --> $DIR/manual_let_else.rs:176:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { +LL | | LL | | b LL | | } else { LL | | return; @@ -289,21 +296,22 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:163:5 + --> $DIR/manual_let_else.rs:183:5 | LL | let v = if let Variant::A(.., a) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(.., v) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:166:5 + --> $DIR/manual_let_else.rs:187:5 | LL | let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let (Some(w), ()) = (g(), ()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:169:5 + --> $DIR/manual_let_else.rs:191:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { +LL | | LL | | x LL | | } else { LL | | return; @@ -318,9 +326,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:176:5 + --> $DIR/manual_let_else.rs:199:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { +LL | | LL | | x LL | | } else { LL | | return; @@ -335,9 +344,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:183:5 + --> $DIR/manual_let_else.rs:207:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { +LL | | LL | | (x, v, w) LL | | } else { LL | | return; @@ -352,9 +362,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:299:5 + --> $DIR/manual_let_else.rs:324:5 | LL | / let _ = match ff { +LL | | LL | | Some(value) => value, LL | | _ => macro_call!(), LL | | }; diff --git a/tests/ui/manual_let_else_match.rs b/tests/ui/manual_let_else_match.rs index 73ff69eec4ed7..e6af47384200e 100644 --- a/tests/ui/manual_let_else_match.rs +++ b/tests/ui/manual_let_else_match.rs @@ -34,11 +34,14 @@ fn main() {} fn fire() { let v = match g() { + //~^ ERROR: this could be rewritten as `let...else` + //~| NOTE: `-D clippy::manual-let-else` implied by `-D warnings` Some(v_some) => v_some, None => return, }; let v = match g() { + //~^ ERROR: this could be rewritten as `let...else` Some(v_some) => v_some, _ => return, }; @@ -46,11 +49,13 @@ fn fire() { loop { // More complex pattern for the identity arm and diverging arm let v = match h() { + //~^ ERROR: this could be rewritten as `let...else` (Some(v), None) | (None, Some(v)) => v, (Some(_), Some(_)) | (None, None) => continue, }; // Custom enums are supported as long as the "else" arm is a simple _ let v = match build_enum() { + //~^ ERROR: this could be rewritten as `let...else` Variant::Bar(v) | Variant::Baz(v) => v, _ => continue, }; @@ -59,12 +64,14 @@ fn fire() { // There is a _ in the diverging arm // TODO also support unused bindings aka _v let v = match f() { + //~^ ERROR: this could be rewritten as `let...else` Ok(v) => v, Err(_) => return, }; // Err(()) is an allowed pattern let v = match f().map_err(|_| ()) { + //~^ ERROR: this could be rewritten as `let...else` Ok(v) => v, Err(()) => return, }; @@ -72,17 +79,20 @@ fn fire() { let f = Variant::Bar(1); let _value = match f { + //~^ ERROR: this could be rewritten as `let...else` Variant::Bar(v) | Variant::Baz(v) => v, _ => return, }; let _value = match Some(build_enum()) { + //~^ ERROR: this could be rewritten as `let...else` Some(Variant::Bar(v) | Variant::Baz(v)) => v, _ => return, }; let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; let data = match data.as_slice() { + //~^ ERROR: this could be rewritten as `let...else` [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, _ => return, }; diff --git a/tests/ui/manual_let_else_match.stderr b/tests/ui/manual_let_else_match.stderr index 3fd9a637605b5..fb7d83f32440b 100644 --- a/tests/ui/manual_let_else_match.stderr +++ b/tests/ui/manual_let_else_match.stderr @@ -2,6 +2,8 @@ error: this could be rewritten as `let...else` --> $DIR/manual_let_else_match.rs:36:5 | LL | / let v = match g() { +LL | | +LL | | LL | | Some(v_some) => v_some, LL | | None => return, LL | | }; @@ -10,72 +12,80 @@ LL | | }; = note: `-D clippy::manual-let-else` implied by `-D warnings` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:41:5 + --> $DIR/manual_let_else_match.rs:43:5 | LL | / let v = match g() { +LL | | LL | | Some(v_some) => v_some, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:48:9 + --> $DIR/manual_let_else_match.rs:51:9 | LL | / let v = match h() { +LL | | LL | | (Some(v), None) | (None, Some(v)) => v, LL | | (Some(_), Some(_)) | (None, None) => continue, LL | | }; | |__________^ help: consider writing: `let ((Some(v), None) | (None, Some(v))) = h() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:53:9 + --> $DIR/manual_let_else_match.rs:57:9 | LL | / let v = match build_enum() { +LL | | LL | | Variant::Bar(v) | Variant::Baz(v) => v, LL | | _ => continue, LL | | }; | |__________^ help: consider writing: `let (Variant::Bar(v) | Variant::Baz(v)) = build_enum() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:61:5 + --> $DIR/manual_let_else_match.rs:66:5 | LL | / let v = match f() { +LL | | LL | | Ok(v) => v, LL | | Err(_) => return, LL | | }; | |______^ help: consider writing: `let Ok(v) = f() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:67:5 + --> $DIR/manual_let_else_match.rs:73:5 | LL | / let v = match f().map_err(|_| ()) { +LL | | LL | | Ok(v) => v, LL | | Err(()) => return, LL | | }; | |______^ help: consider writing: `let Ok(v) = f().map_err(|_| ()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:74:5 + --> $DIR/manual_let_else_match.rs:81:5 | LL | / let _value = match f { +LL | | LL | | Variant::Bar(v) | Variant::Baz(v) => v, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let (Variant::Bar(_value) | Variant::Baz(_value)) = f else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:79:5 + --> $DIR/manual_let_else_match.rs:87:5 | LL | / let _value = match Some(build_enum()) { +LL | | LL | | Some(Variant::Bar(v) | Variant::Baz(v)) => v, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let Some(Variant::Bar(_value) | Variant::Baz(_value)) = Some(build_enum()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:85:5 + --> $DIR/manual_let_else_match.rs:94:5 | LL | / let data = match data.as_slice() { +LL | | LL | | [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, LL | | _ => return, LL | | }; diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs index 5f70221ec6eef..786d7e6e24454 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/tests/ui/manual_memcpy/with_loop_counters.rs @@ -3,48 +3,57 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices + //~| NOTE: `-D clippy::manual-memcpy` implied by `-D warnings` dst[i] = src[count]; count += 1; } let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; count += 1; } let mut count = 3; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; count += 1; } let mut count = 3; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 0; for i in 3..(3 + src.len()) { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 3; for i in 5..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count - 2]; count += 1; } let mut count = 2; for i in 0..dst.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 5; for i in 3..10 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } @@ -52,6 +61,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 3; let mut count2 = 30; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; dst2[count2] = src[i]; count += 1; @@ -62,6 +72,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) // arithmetic ones let mut count = 0 << 1; for i in 0..1 << 1 { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i + 2]; count += 1; } @@ -69,6 +80,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) // make sure incrementing expressions without semicolons at the end of loops are handled correctly. let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1 } diff --git a/tests/ui/manual_memcpy/with_loop_counters.stderr b/tests/ui/manual_memcpy/with_loop_counters.stderr index 79d40c0bcb1d9..e23c95dc8a4af 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -2,6 +2,8 @@ error: it looks like you're manually copying between slices --> $DIR/with_loop_counters.rs:5:5 | LL | / for i in 3..src.len() { +LL | | +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } @@ -10,72 +12,80 @@ LL | | } = note: `-D clippy::manual-memcpy` implied by `-D warnings` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:11:5 + --> $DIR/with_loop_counters.rs:13:5 | LL | / for i in 3..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[..(src.len() - 3)].copy_from_slice(&src[3..]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:17:5 + --> $DIR/with_loop_counters.rs:20:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..(src.len() + 3)].copy_from_slice(&src[..]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:23:5 + --> $DIR/with_loop_counters.rs:27:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[3..(src.len() + 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:29:5 + --> $DIR/with_loop_counters.rs:34:5 | LL | / for i in 3..(3 + src.len()) { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].copy_from_slice(&src[..(3 + src.len() - 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:35:5 + --> $DIR/with_loop_counters.rs:41:5 | LL | / for i in 5..src.len() { +LL | | LL | | dst[i] = src[count - 2]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[5..src.len()].copy_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:41:5 + --> $DIR/with_loop_counters.rs:48:5 | LL | / for i in 0..dst.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[2..(dst.len() + 2)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:47:5 + --> $DIR/with_loop_counters.rs:55:5 | LL | / for i in 3..10 { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..10].copy_from_slice(&src[5..(10 + 5 - 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:54:5 + --> $DIR/with_loop_counters.rs:63:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | dst2[count2] = src[i]; LL | | count += 1; @@ -90,18 +100,20 @@ LL + dst2[30..(src.len() + 30)].copy_from_slice(&src[..]); | error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:64:5 + --> $DIR/with_loop_counters.rs:74:5 | LL | / for i in 0..1 << 1 { +LL | | LL | | dst[count] = src[i + 2]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].copy_from_slice(&src[2..((1 << 1) + 2)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:71:5 + --> $DIR/with_loop_counters.rs:82:5 | LL | / for i in 3..src.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1 LL | | } diff --git a/tests/ui/manual_memcpy/without_loop_counters.rs b/tests/ui/manual_memcpy/without_loop_counters.rs index 1a1db6a632998..a224001a3dfd6 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/tests/ui/manual_memcpy/without_loop_counters.rs @@ -6,26 +6,32 @@ const LOOP_OFFSET: usize = 5000; pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // plain manual memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices + //~| NOTE: `-D clippy::manual-memcpy` implied by `-D warnings` dst[i] = src[i]; } // dst offset memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i + 10] = src[i]; } // src offset memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i + 10]; } // src offset memcpy for i in 11..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - 10]; } // overwrite entire dst for i in 0..dst.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i]; } @@ -39,6 +45,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // multiple copies - suggest two memcpy statements for i in 10..256 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - 5]; dst2[i + 500] = src[i] } @@ -51,6 +58,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let some_var = 5; // Offset in variable for i in 10..LOOP_OFFSET { + //~^ ERROR: it looks like you're manually copying between slices dst[i + LOOP_OFFSET] = src[i - some_var]; } @@ -64,6 +72,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // make sure vectors are supported for i in 0..src_vec.len() { + //~^ ERROR: it looks like you're manually copying between slices dst_vec[i] = src_vec[i]; } @@ -93,20 +102,24 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let from = 1; for i in from..from + src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - from]; } for i in from..from + 3 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - from]; } #[allow(clippy::identity_op)] for i in 0..5 { + //~^ ERROR: it looks like you're manually copying between slices dst[i - 0] = src[i]; } #[allow(clippy::reversed_empty_ranges)] for i in 0..0 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i]; } @@ -130,6 +143,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { #[warn(clippy::needless_range_loop, clippy::manual_memcpy)] pub fn manual_clone(src: &[String], dst: &mut [String]) { for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i].clone(); } } diff --git a/tests/ui/manual_memcpy/without_loop_counters.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr index 1c6a7d5c04e0a..4f02c698a0d6b 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -2,6 +2,8 @@ error: it looks like you're manually copying between slices --> $DIR/without_loop_counters.rs:8:5 | LL | / for i in 0..src.len() { +LL | | +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[..]);` @@ -9,41 +11,46 @@ LL | | } = note: `-D clippy::manual-memcpy` implied by `-D warnings` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:13:5 + --> $DIR/without_loop_counters.rs:15:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i + 10] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[10..(src.len() + 10)].copy_from_slice(&src[..]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:18:5 + --> $DIR/without_loop_counters.rs:21:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[i + 10]; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[10..(src.len() + 10)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:23:5 + --> $DIR/without_loop_counters.rs:27:5 | LL | / for i in 11..src.len() { +LL | | LL | | dst[i] = src[i - 10]; LL | | } | |_____^ help: try replacing the loop by: `dst[11..src.len()].copy_from_slice(&src[(11 - 10)..(src.len() - 10)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:28:5 + --> $DIR/without_loop_counters.rs:33:5 | LL | / for i in 0..dst.len() { +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..dst.len()]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:41:5 + --> $DIR/without_loop_counters.rs:47:5 | LL | / for i in 10..256 { +LL | | LL | | dst[i] = src[i - 5]; LL | | dst2[i + 500] = src[i] LL | | } @@ -56,57 +63,64 @@ LL + dst2[(10 + 500)..(256 + 500)].copy_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:53:5 + --> $DIR/without_loop_counters.rs:60:5 | LL | / for i in 10..LOOP_OFFSET { +LL | | LL | | dst[i + LOOP_OFFSET] = src[i - some_var]; LL | | } | |_____^ help: try replacing the loop by: `dst[(10 + LOOP_OFFSET)..(LOOP_OFFSET + LOOP_OFFSET)].copy_from_slice(&src[(10 - some_var)..(LOOP_OFFSET - some_var)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:66:5 + --> $DIR/without_loop_counters.rs:74:5 | LL | / for i in 0..src_vec.len() { +LL | | LL | | dst_vec[i] = src_vec[i]; LL | | } | |_____^ help: try replacing the loop by: `dst_vec[..src_vec.len()].copy_from_slice(&src_vec[..]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:95:5 + --> $DIR/without_loop_counters.rs:104:5 | LL | / for i in from..from + src.len() { +LL | | LL | | dst[i] = src[i - from]; LL | | } | |_____^ help: try replacing the loop by: `dst[from..(from + src.len())].copy_from_slice(&src[..(from + src.len() - from)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:99:5 + --> $DIR/without_loop_counters.rs:109:5 | LL | / for i in from..from + 3 { +LL | | LL | | dst[i] = src[i - from]; LL | | } | |_____^ help: try replacing the loop by: `dst[from..(from + 3)].copy_from_slice(&src[..(from + 3 - from)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:104:5 + --> $DIR/without_loop_counters.rs:115:5 | LL | / for i in 0..5 { +LL | | LL | | dst[i - 0] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src[..5]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:109:5 + --> $DIR/without_loop_counters.rs:121:5 | LL | / for i in 0..0 { +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:132:5 + --> $DIR/without_loop_counters.rs:145:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[i].clone(); LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..]);` diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs index b5199065017a8..0e439dabfd651 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -3,6 +3,7 @@ #![allow(unused)] //@no-rustfix enum E { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern A, B, #[doc(hidden)] @@ -12,6 +13,7 @@ enum E { // user forgot to remove the marker #[non_exhaustive] enum Ep { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern A, B, #[doc(hidden)] diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index 087f766be70d2..ab068d4827e71 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -6,6 +6,7 @@ LL | enum E { | | | _help: add the attribute: `#[non_exhaustive] enum E` | | +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -14,16 +15,17 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:9:5 + --> $DIR/manual_non_exhaustive_enum.rs:10:5 | LL | _C, | ^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_enum.rs:14:1 + --> $DIR/manual_non_exhaustive_enum.rs:15:1 | LL | / enum Ep { +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -32,7 +34,7 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:18:5 + --> $DIR/manual_non_exhaustive_enum.rs:20:5 | LL | _C, | ^^ diff --git a/tests/ui/manual_non_exhaustive_struct.rs b/tests/ui/manual_non_exhaustive_struct.rs index 9935427f50100..4b2803ccc4a79 100644 --- a/tests/ui/manual_non_exhaustive_struct.rs +++ b/tests/ui/manual_non_exhaustive_struct.rs @@ -3,6 +3,7 @@ //@no-rustfix mod structs { struct S { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern pub a: i32, pub b: i32, _c: (), @@ -11,6 +12,7 @@ mod structs { // user forgot to remove the private field #[non_exhaustive] struct Sp { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern pub a: i32, pub b: i32, _c: (), @@ -52,10 +54,12 @@ mod structs { mod tuple_structs { struct T(pub i32, pub i32, ()); + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern // user forgot to remove the private field #[non_exhaustive] struct Tp(pub i32, pub i32, ()); + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern // some other fields are private, should be ignored struct PrivateFields(pub i32, i32, ()); diff --git a/tests/ui/manual_non_exhaustive_struct.stderr b/tests/ui/manual_non_exhaustive_struct.stderr index d0bed8e11211a..c062af6356c46 100644 --- a/tests/ui/manual_non_exhaustive_struct.stderr +++ b/tests/ui/manual_non_exhaustive_struct.stderr @@ -6,6 +6,7 @@ LL | struct S { | | | _____help: add the attribute: `#[non_exhaustive] struct S` | | +LL | | LL | | pub a: i32, LL | | pub b: i32, LL | | _c: (), @@ -13,16 +14,17 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:8:9 + --> $DIR/manual_non_exhaustive_struct.rs:9:9 | LL | _c: (), | ^^^^^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:13:5 + --> $DIR/manual_non_exhaustive_struct.rs:14:5 | LL | / struct Sp { +LL | | LL | | pub a: i32, LL | | pub b: i32, LL | | _c: (), @@ -30,13 +32,13 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:16:9 + --> $DIR/manual_non_exhaustive_struct.rs:18:9 | LL | _c: (), | ^^^^^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:54:5 + --> $DIR/manual_non_exhaustive_struct.rs:56:5 | LL | struct T(pub i32, pub i32, ()); | --------^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,19 +46,19 @@ LL | struct T(pub i32, pub i32, ()); | help: add the attribute: `#[non_exhaustive] struct T` | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:54:32 + --> $DIR/manual_non_exhaustive_struct.rs:56:32 | LL | struct T(pub i32, pub i32, ()); | ^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:58:5 + --> $DIR/manual_non_exhaustive_struct.rs:61:5 | LL | struct Tp(pub i32, pub i32, ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:58:33 + --> $DIR/manual_non_exhaustive_struct.rs:61:33 | LL | struct Tp(pub i32, pub i32, ()); | ^^ diff --git a/tests/ui/manual_strip.rs b/tests/ui/manual_strip.rs index 99c83354419d7..8bd0300e6bcce 100644 --- a/tests/ui/manual_strip.rs +++ b/tests/ui/manual_strip.rs @@ -5,6 +5,7 @@ fn main() { if s.starts_with("ab") { str::to_string(&s["ab".len()..]); + //~^ ERROR: stripping a prefix manually s["ab".len()..].to_string(); str::to_string(&s[2..]); @@ -13,6 +14,7 @@ fn main() { if s.ends_with("bc") { str::to_string(&s[..s.len() - "bc".len()]); + //~^ ERROR: stripping a suffix manually s[..s.len() - "bc".len()].to_string(); str::to_string(&s[..s.len() - 2]); @@ -22,6 +24,7 @@ fn main() { // Character patterns if s.starts_with('a') { str::to_string(&s[1..]); + //~^ ERROR: stripping a prefix manually s[1..].to_string(); } @@ -29,12 +32,14 @@ fn main() { let prefix = "ab"; if s.starts_with(prefix) { str::to_string(&s[prefix.len()..]); + //~^ ERROR: stripping a prefix manually } // Constant prefix const PREFIX: &str = "ab"; if s.starts_with(PREFIX) { str::to_string(&s[PREFIX.len()..]); + //~^ ERROR: stripping a prefix manually str::to_string(&s[2..]); } @@ -42,12 +47,14 @@ fn main() { const TARGET: &str = "abc"; if TARGET.starts_with(prefix) { str::to_string(&TARGET[prefix.len()..]); + //~^ ERROR: stripping a prefix manually } // String target - not mutated. let s1: String = "abc".into(); if s1.starts_with("ab") { s1[2..].to_uppercase(); + //~^ ERROR: stripping a prefix manually } // String target - mutated. (Don't lint.) @@ -78,5 +85,6 @@ fn msrv_1_45() { let s = "abc"; if s.starts_with('a') { s[1..].to_string(); + //~^ ERROR: stripping a prefix manually } } diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index f592e898fc928..e7be2b4b9cec2 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -14,6 +14,7 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix("ab") { LL ~ str::to_string(); +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -21,13 +22,13 @@ LL ~ .to_string(); | error: stripping a suffix manually - --> $DIR/manual_strip.rs:15:24 + --> $DIR/manual_strip.rs:16:24 | LL | str::to_string(&s[..s.len() - "bc".len()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the suffix was tested here - --> $DIR/manual_strip.rs:14:5 + --> $DIR/manual_strip.rs:15:5 | LL | if s.ends_with("bc") { | ^^^^^^^^^^^^^^^^^^^^^ @@ -35,6 +36,7 @@ help: try using the `strip_suffix` method | LL ~ if let Some() = s.strip_suffix("bc") { LL ~ str::to_string(); +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -42,13 +44,13 @@ LL ~ .to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:24:24 + --> $DIR/manual_strip.rs:26:24 | LL | str::to_string(&s[1..]); | ^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:23:5 + --> $DIR/manual_strip.rs:25:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -56,17 +58,18 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix('a') { LL ~ str::to_string(); +LL | LL ~ .to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:31:24 + --> $DIR/manual_strip.rs:34:24 | LL | str::to_string(&s[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:30:5 + --> $DIR/manual_strip.rs:33:5 | LL | if s.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,13 +80,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:37:24 + --> $DIR/manual_strip.rs:41:24 | LL | str::to_string(&s[PREFIX.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:36:5 + --> $DIR/manual_strip.rs:40:5 | LL | if s.starts_with(PREFIX) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,17 +94,18 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix(PREFIX) { LL ~ str::to_string(); +LL | LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:44:24 + --> $DIR/manual_strip.rs:49:24 | LL | str::to_string(&TARGET[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:43:5 + --> $DIR/manual_strip.rs:48:5 | LL | if TARGET.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,13 +116,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:50:9 + --> $DIR/manual_strip.rs:56:9 | LL | s1[2..].to_uppercase(); | ^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:49:5 + --> $DIR/manual_strip.rs:55:5 | LL | if s1.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,13 +133,13 @@ LL ~ .to_uppercase(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:80:9 + --> $DIR/manual_strip.rs:87:9 | LL | s[1..].to_string(); | ^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:79:5 + --> $DIR/manual_strip.rs:86:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/many_single_char_names.rs b/tests/ui/many_single_char_names.rs index 88fcce66873aa..68578340d90e1 100644 --- a/tests/ui/many_single_char_names.rs +++ b/tests/ui/many_single_char_names.rs @@ -3,6 +3,10 @@ fn bla() { let a: i32; + //~^ ERROR: 5 bindings with single-character names in scope + //~| NOTE: `-D clippy::many-single-char-names` implied by `-D warnings` + //~| ERROR: 6 bindings with single-character names in scope + //~| ERROR: 5 bindings with single-character names in scope let (b, c, d): (i32, i64, i16); { { @@ -28,9 +32,11 @@ fn bla() { } fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} +//~^ ERROR: 8 bindings with single-character names in scope fn bindings2() { let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); + //~^ ERROR: 8 bindings with single-character names in scope } fn shadowing() { diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr index ade0f84bc5065..4f5a69a9b6092 100644 --- a/tests/ui/many_single_char_names.stderr +++ b/tests/ui/many_single_char_names.stderr @@ -3,6 +3,7 @@ error: 5 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -16,6 +17,7 @@ error: 6 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -29,6 +31,7 @@ error: 5 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -36,13 +39,13 @@ LL | e => panic!(), | ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:30:13 + --> $DIR/many_single_char_names.rs:34:13 | LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} | ^ ^ ^ ^ ^ ^ ^ ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:33:10 + --> $DIR/many_single_char_names.rs:38:10 | LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); | ^ ^ ^ ^ ^ ^ ^ ^ diff --git a/tests/ui/map_err.rs b/tests/ui/map_err.rs index bb35ab1a14efa..07c51784407a6 100644 --- a/tests/ui/map_err.rs +++ b/tests/ui/map_err.rs @@ -20,6 +20,7 @@ fn main() -> Result<(), Errors> { let x = u32::try_from(-123_i32); println!("{:?}", x.map_err(|_| Errors::Ignored)); + //~^ ERROR: `map_err(|_|...` wildcard pattern discards the original error // Should not warn you because you explicitly ignore the parameter // using a named wildcard value diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs index fca4fe0bcb780..76916d4659197 100644 --- a/tests/ui/map_flatten.rs +++ b/tests/ui/map_flatten.rs @@ -6,6 +6,8 @@ fn long_span() { let _: Option = Some(1) .map(|x| { + //~^ ERROR: called `map(..).flatten()` on `Option` + //~| NOTE: `-D clippy::map-flatten` implied by `-D warnings` if x <= 5 { Some(x) } else { @@ -16,6 +18,7 @@ fn long_span() { let _: Result = Ok(1) .map(|x| { + //~^ ERROR: called `map(..).flatten()` on `Result` if x == 1 { Ok(x) } else { @@ -28,6 +31,7 @@ fn long_span() { fn do_something() { } let _: Result = result .map(|res| { + //~^ ERROR: called `map(..).flatten()` on `Result` if res > 0 { do_something(); Ok(res) @@ -40,6 +44,7 @@ fn long_span() { let _: Vec<_> = vec![5_i8; 6] .into_iter() .map(|some_value| { + //~^ ERROR: called `map(..).flatten()` on `Iterator` if some_value > 3 { Some(some_value) } else { diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr index 4b2630d685847..88fdd04c02367 100644 --- a/tests/ui/map_flatten.stderr +++ b/tests/ui/map_flatten.stderr @@ -3,9 +3,9 @@ error: called `map(..).flatten()` on `Option` | LL | .map(|x| { | __________^ +LL | | +LL | | LL | | if x <= 5 { -LL | | Some(x) -LL | | } else { ... | LL | | }) LL | | .flatten(); @@ -15,6 +15,8 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { +LL + +LL + LL + if x <= 5 { LL + Some(x) LL + } else { @@ -24,13 +26,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten.rs:18:10 + --> $DIR/map_flatten.rs:20:10 | LL | .map(|x| { | __________^ +LL | | LL | | if x == 1 { LL | | Ok(x) -LL | | } else { ... | LL | | }) LL | | .flatten(); @@ -39,6 +41,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { +LL + LL + if x == 1 { LL + Ok(x) LL + } else { @@ -48,13 +51,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten.rs:30:10 + --> $DIR/map_flatten.rs:33:10 | LL | .map(|res| { | __________^ +LL | | LL | | if res > 0 { LL | | do_something(); -LL | | Ok(res) ... | LL | | }) LL | | .flatten(); @@ -63,6 +66,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|res| { +LL + LL + if res > 0 { LL + do_something(); LL + Ok(res) @@ -73,13 +77,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten.rs:42:10 + --> $DIR/map_flatten.rs:46:10 | LL | .map(|some_value| { | __________^ +LL | | LL | | if some_value > 3 { LL | | Some(some_value) -LL | | } else { ... | LL | | }) LL | | .flatten() @@ -88,6 +92,7 @@ LL | | .flatten() help: try replacing `map` with `filter_map` and remove the `.flatten()` | LL ~ .filter_map(|some_value| { +LL + LL + if some_value > 3 { LL + Some(some_value) LL + } else { diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index d7a379f9ac320..f84af393e47fa 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -5,17 +5,20 @@ fn match_bool() { let test: bool = true; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression true => 0, false => 42, }; let option = 1; match option == 1 { + //~^ ERROR: you seem to be trying to match on a boolean expression true => 1, false => 0, }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression true => (), false => { println!("Noooo!"); @@ -23,6 +26,7 @@ fn match_bool() { }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression false => { println!("Noooo!"); }, @@ -30,6 +34,11 @@ fn match_bool() { }; match test && test { + //~^ ERROR: this boolean expression can be simplified + //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings` + //~| ERROR: you seem to be trying to match on a boolean expression + //~| ERROR: equal expressions as operands to `&&` + //~| NOTE: `#[deny(clippy::eq_op)]` on by default false => { println!("Noooo!"); }, @@ -37,6 +46,7 @@ fn match_bool() { }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression false => { println!("Noooo!"); }, diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 32311f73db345..351ebfc08cdbd 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/match_bool.rs:32:11 + --> $DIR/match_bool.rs:36:11 | LL | match test && test { | ^^^^^^^^^^^^ help: try: `test` @@ -10,6 +10,7 @@ error: you seem to be trying to match on a boolean expression --> $DIR/match_bool.rs:7:5 | LL | / match test { +LL | | LL | | true => 0, LL | | false => 42, LL | | }; @@ -22,18 +23,20 @@ LL | #![deny(clippy::match_bool)] | ^^^^^^^^^^^^^^^^^^ error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:13:5 + --> $DIR/match_bool.rs:14:5 | LL | / match option == 1 { +LL | | LL | | true => 1, LL | | false => 0, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:18:5 + --> $DIR/match_bool.rs:20:5 | LL | / match test { +LL | | LL | | true => (), LL | | false => { LL | | println!("Noooo!"); @@ -49,9 +52,10 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:25:5 + --> $DIR/match_bool.rs:28:5 | LL | / match test { +LL | | LL | | false => { LL | | println!("Noooo!"); LL | | }, @@ -67,12 +71,13 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:32:5 + --> $DIR/match_bool.rs:36:5 | LL | / match test && test { -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, +LL | | +LL | | +LL | | +... | LL | | _ => (), LL | | }; | |_____^ @@ -85,7 +90,7 @@ LL ~ }; | error: equal expressions as operands to `&&` - --> $DIR/match_bool.rs:32:11 + --> $DIR/match_bool.rs:36:11 | LL | match test && test { | ^^^^^^^^^^^^ @@ -93,12 +98,12 @@ LL | match test && test { = note: `#[deny(clippy::eq_op)]` on by default error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:39:5 + --> $DIR/match_bool.rs:48:5 | LL | / match test { +LL | | LL | | false => { LL | | println!("Noooo!"); -LL | | }, ... | LL | | }, LL | | }; diff --git a/tests/ui/match_on_vec_items.rs b/tests/ui/match_on_vec_items.rs index 45a74f5c5ddea..f7b8500faa4a0 100644 --- a/tests/ui/match_on_vec_items.rs +++ b/tests/ui/match_on_vec_items.rs @@ -8,6 +8,8 @@ fn match_with_wildcard() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic + //~| NOTE: `-D clippy::match-on-vec-items` implied by `-D warnings` 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -15,6 +17,7 @@ fn match_with_wildcard() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, @@ -28,6 +31,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), num => {}, @@ -35,6 +39,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), [ref sub @ ..] => {}, @@ -48,6 +53,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), _ => println!("Hello, World!"), @@ -55,6 +61,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => println!("Hello, World!"), @@ -68,6 +75,7 @@ fn match_vec_ref() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -75,6 +83,7 @@ fn match_vec_ref() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, diff --git a/tests/ui/match_on_vec_items.stderr b/tests/ui/match_on_vec_items.stderr index fc4a3ce19463f..71038aaad49fb 100644 --- a/tests/ui/match_on_vec_items.stderr +++ b/tests/ui/match_on_vec_items.stderr @@ -7,43 +7,43 @@ LL | match arr[idx] { = note: `-D clippy::match-on-vec-items` implied by `-D warnings` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:17:11 + --> $DIR/match_on_vec_items.rs:19:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:30:11 + --> $DIR/match_on_vec_items.rs:33:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:37:11 + --> $DIR/match_on_vec_items.rs:41:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:50:11 + --> $DIR/match_on_vec_items.rs:55:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:57:11 + --> $DIR/match_on_vec_items.rs:63:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:70:11 + --> $DIR/match_on_vec_items.rs:77:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:77:11 + --> $DIR/match_on_vec_items.rs:85:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs index b78c1fd06d44d..c2c2f28392d77 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -10,12 +10,14 @@ fn overlapping() { match 42 { 0..=10 => println!("0..=10"), + //~^ ERROR: some ranges overlap 0..=11 => println!("0..=11"), _ => (), } match 42 { 0..=5 => println!("0..=5"), + //~^ ERROR: some ranges overlap 6..=7 => println!("6..=7"), FOO..=11 => println!("FOO..=11"), _ => (), @@ -53,6 +55,7 @@ fn overlapping() { match 42 { 0..11 => println!("0..11"), + //~^ ERROR: some ranges overlap 0..=11 => println!("0..=11"), _ => (), } @@ -78,11 +81,13 @@ fn overlapping() { match 42 { 5..14 => println!("5..14"), 0..=10 => println!("0..=10"), + //~^ ERROR: some ranges overlap _ => (), } match 42 { 0..7 => println!("0..7"), + //~^ ERROR: some ranges overlap 0..=10 => println!("0..=10"), _ => (), } @@ -95,6 +100,7 @@ fn overlapping() { match 42 { ..=23 => println!("..=23"), + //~^ ERROR: some ranges overlap ..26 => println!("..26"), _ => (), } @@ -104,6 +110,7 @@ fn overlapping() { 5..=10 => (), 0..=20 => (), 21..=30 => (), + //~^ ERROR: some ranges overlap 21..=40 => (), _ => (), } @@ -118,6 +125,7 @@ fn overlapping() { // Only warn about the first if there are multiple overlaps match 42u128 { 0..=0x0000_0000_0000_00ff => (), + //~^ ERROR: some ranges overlap 0..=0x0000_0000_0000_ffff => (), 0..=0x0000_0000_ffff_ffff => (), 0..=0xffff_ffff_ffff_ffff => (), diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr index b98d4799e42ca..ceec40e8def0f 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -5,92 +5,92 @@ LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:13:9 + --> $DIR/match_overlapping_arm.rs:14:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:18:9 + --> $DIR/match_overlapping_arm.rs:19:9 | LL | 0..=5 => println!("0..=5"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:20:9 + --> $DIR/match_overlapping_arm.rs:22:9 | LL | FOO..=11 => println!("FOO..=11"), | ^^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:55:9 + --> $DIR/match_overlapping_arm.rs:57:9 | LL | 0..11 => println!("0..11"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:56:9 + --> $DIR/match_overlapping_arm.rs:59:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:80:9 + --> $DIR/match_overlapping_arm.rs:83:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:79:9 + --> $DIR/match_overlapping_arm.rs:82:9 | LL | 5..14 => println!("5..14"), | ^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:85:9 + --> $DIR/match_overlapping_arm.rs:89:9 | LL | 0..7 => println!("0..7"), | ^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:86:9 + --> $DIR/match_overlapping_arm.rs:91:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:97:9 + --> $DIR/match_overlapping_arm.rs:102:9 | LL | ..=23 => println!("..=23"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:98:9 + --> $DIR/match_overlapping_arm.rs:104:9 | LL | ..26 => println!("..26"), | ^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:106:9 + --> $DIR/match_overlapping_arm.rs:112:9 | LL | 21..=30 => (), | ^^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:107:9 + --> $DIR/match_overlapping_arm.rs:114:9 | LL | 21..=40 => (), | ^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:120:9 + --> $DIR/match_overlapping_arm.rs:127:9 | LL | 0..=0x0000_0000_0000_00ff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:121:9 + --> $DIR/match_overlapping_arm.rs:129:9 | LL | 0..=0x0000_0000_0000_ffff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index 096858f3a67d5..1ee048bf7f6c3 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -39,6 +39,7 @@ pub fn g(x: Ordering) { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => panic!(), + //~^ ERROR: this match arm has an identical body to the `_` wildcard arm _ => panic!(), } } @@ -52,6 +53,7 @@ mod g { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => panic!(), + //~^ ERROR: this match arm has an identical body to the `_` wildcard arm _ => panic!(), } } diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index 088f7d5c06242..9ee8f14ad90e2 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -6,21 +6,21 @@ LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:42:9 + --> $DIR/match_same_arms_non_exhaustive.rs:43:9 | LL | _ => panic!(), | ^^^^^^^^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms_non_exhaustive.rs:54:13 + --> $DIR/match_same_arms_non_exhaustive.rs:55:13 | LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:55:13 + --> $DIR/match_same_arms_non_exhaustive.rs:57:13 | LL | _ => panic!(), | ^^^^^^^^^^^^^ diff --git a/tests/ui/match_wild_err_arm.rs b/tests/ui/match_wild_err_arm.rs index 5a552e4ae51a5..7bdd75d7f4639 100644 --- a/tests/ui/match_wild_err_arm.rs +++ b/tests/ui/match_wild_err_arm.rs @@ -22,18 +22,24 @@ fn match_wild_err_arm() { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => panic!("err"), + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => panic!(), + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => { + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms panic!(); }, } @@ -42,6 +48,8 @@ fn match_wild_err_arm() { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_e) => panic!(), + //~^ ERROR: `Err(_e)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } // Allowed when used in `panic!`. diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr index a9f54feacdb58..696ba7303a96c 100644 --- a/tests/ui/match_wild_err_arm.stderr +++ b/tests/ui/match_wild_err_arm.stderr @@ -8,7 +8,7 @@ LL | Err(_) => panic!("err"), = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:30:9 + --> $DIR/match_wild_err_arm.rs:32:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -16,7 +16,7 @@ LL | Err(_) => panic!(), = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:36:9 + --> $DIR/match_wild_err_arm.rs:40:9 | LL | Err(_) => { | ^^^^^^ @@ -24,7 +24,7 @@ LL | Err(_) => { = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_e)` matches all errors - --> $DIR/match_wild_err_arm.rs:44:9 + --> $DIR/match_wild_err_arm.rs:50:9 | LL | Err(_e) => panic!(), | ^^^^^^^ diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index b6c8d9e53d80e..1f508b3bca289 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -12,15 +12,23 @@ fn main() { let six: Arc = Arc::new(6); memstuff::forget(six); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::sync::Arc` let seven: Rc = Rc::new(7); std::mem::forget(seven); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::rc::Rc` let eight: Vec = vec![8]; forgetSomething(eight); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::vec::Vec` let string = String::new(); std::mem::forget(string); + //~^ ERROR: usage of `mem::forget` on type with `Drop` fields + //~| NOTE: argument has type `std::string::String` std::mem::forget(7); } diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 8004b2aa8db7a..dd2ea7518559f 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -8,7 +8,7 @@ LL | memstuff::forget(six); = note: `-D clippy::mem-forget` implied by `-D warnings` error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:17:5 + --> $DIR/mem_forget.rs:19:5 | LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | std::mem::forget(seven); = note: argument has type `std::rc::Rc` error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:20:5 + --> $DIR/mem_forget.rs:24:5 | LL | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | forgetSomething(eight); = note: argument has type `std::vec::Vec` error: usage of `mem::forget` on type with `Drop` fields - --> $DIR/mem_forget.rs:23:5 + --> $DIR/mem_forget.rs:29:5 | LL | std::mem::forget(string); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/methods_unfixable.rs b/tests/ui/methods_unfixable.rs index e12b8136d2b9c..ee59983a7573e 100644 --- a/tests/ui/methods_unfixable.rs +++ b/tests/ui/methods_unfixable.rs @@ -7,4 +7,5 @@ fn main() { pub fn issue10029() { let iter = (0..10); let _ = iter.filter(|_| true).next(); + //~^ ERROR: called `filter(..).next()` on an `Iterator`. This is more succinctly expre } diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs index 1215a02286c28..cf64f85f9bb5f 100644 --- a/tests/ui/min_max.rs +++ b/tests/ui/min_max.rs @@ -20,11 +20,17 @@ impl NotOrd { fn main() { let x = 2usize; min(1, max(3, x)); + //~^ ERROR: this `min`/`max` combination leads to constant result + //~| NOTE: `-D clippy::min-max` implied by `-D warnings` min(max(3, x), 1); + //~^ ERROR: this `min`/`max` combination leads to constant result max(min(x, 1), 3); + //~^ ERROR: this `min`/`max` combination leads to constant result max(3, min(x, 1)); + //~^ ERROR: this `min`/`max` combination leads to constant result my_max(3, my_min(x, 1)); + //~^ ERROR: this `min`/`max` combination leads to constant result min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x @@ -35,24 +41,32 @@ fn main() { let s = "Hello"; min("Apple", max("Zoo", s)); + //~^ ERROR: this `min`/`max` combination leads to constant result max(min(s, "Apple"), "Zoo"); + //~^ ERROR: this `min`/`max` combination leads to constant result max("Apple", min(s, "Zoo")); // ok let f = 3f32; x.min(1).max(3); + //~^ ERROR: this `min`/`max` combination leads to constant result x.max(3).min(1); + //~^ ERROR: this `min`/`max` combination leads to constant result f.max(3f32).min(1f32); + //~^ ERROR: this `min`/`max` combination leads to constant result x.max(1).min(3); // ok x.min(3).max(1); // ok f.min(3f32).max(1f32); // ok max(x.min(1), 3); + //~^ ERROR: this `min`/`max` combination leads to constant result min(x.max(1), 3); // ok s.max("Zoo").min("Apple"); + //~^ ERROR: this `min`/`max` combination leads to constant result s.min("Apple").max("Zoo"); + //~^ ERROR: this `min`/`max` combination leads to constant result s.min("Zoo").max("Apple"); // ok diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index 402b094f4f77b..128394e627ca9 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -7,73 +7,73 @@ LL | min(1, max(3, x)); = note: `-D clippy::min-max` implied by `-D warnings` error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:23:5 + --> $DIR/min_max.rs:25:5 | LL | min(max(3, x), 1); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:24:5 + --> $DIR/min_max.rs:27:5 | LL | max(min(x, 1), 3); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:25:5 + --> $DIR/min_max.rs:29:5 | LL | max(3, min(x, 1)); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:27:5 + --> $DIR/min_max.rs:32:5 | LL | my_max(3, my_min(x, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:37:5 + --> $DIR/min_max.rs:43:5 | LL | min("Apple", max("Zoo", s)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:38:5 + --> $DIR/min_max.rs:45:5 | LL | max(min(s, "Apple"), "Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:43:5 + --> $DIR/min_max.rs:51:5 | LL | x.min(1).max(3); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:44:5 + --> $DIR/min_max.rs:53:5 | LL | x.max(3).min(1); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:45:5 + --> $DIR/min_max.rs:55:5 | LL | f.max(3f32).min(1f32); | ^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:51:5 + --> $DIR/min_max.rs:62:5 | LL | max(x.min(1), 3); | ^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:54:5 + --> $DIR/min_max.rs:66:5 | LL | s.max("Zoo").min("Apple"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:55:5 + --> $DIR/min_max.rs:68:5 | LL | s.min("Apple").max("Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/min_rust_version_attr.rs b/tests/ui/min_rust_version_attr.rs index 955e7eb727634..5fe3306d6fc83 100644 --- a/tests/ui/min_rust_version_attr.rs +++ b/tests/ui/min_rust_version_attr.rs @@ -11,11 +11,13 @@ fn just_under_msrv() { #[clippy::msrv = "1.43.0"] fn meets_msrv() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } #[clippy::msrv = "1.44.0"] fn just_above_msrv() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } #[clippy::msrv = "1.42"] @@ -26,6 +28,7 @@ fn no_patch_under() { #[clippy::msrv = "1.43"] fn no_patch_meets() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } fn inner_attr_under() { @@ -36,6 +39,7 @@ fn inner_attr_under() { fn inner_attr_meets() { #![clippy::msrv = "1.43"] let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } // https://github.com/rust-lang/rust-clippy/issues/6920 @@ -46,6 +50,7 @@ fn scoping() { // Should warn let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found mod a { #![clippy::msrv = "1.42.0"] @@ -53,6 +58,7 @@ fn scoping() { fn should_warn() { #![clippy::msrv = "1.43.0"] let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } fn should_not_warn() { diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr index 7e2135584efde..3c8555c62446c 100644 --- a/tests/ui/min_rust_version_attr.stderr +++ b/tests/ui/min_rust_version_attr.stderr @@ -8,7 +8,7 @@ LL | let log2_10 = 3.321928094887362; = note: `#[deny(clippy::approx_constant)]` on by default error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:18:19 + --> $DIR/min_rust_version_attr.rs:19:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:28:19 + --> $DIR/min_rust_version_attr.rs:30:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:38:19 + --> $DIR/min_rust_version_attr.rs:41:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:48:19 + --> $DIR/min_rust_version_attr.rs:52:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:55:27 + --> $DIR/min_rust_version_attr.rs:60:27 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/min_rust_version_invalid_attr.rs b/tests/ui/min_rust_version_invalid_attr.rs index 02892f329af67..c8a0d6641675a 100644 --- a/tests/ui/min_rust_version_invalid_attr.rs +++ b/tests/ui/min_rust_version_invalid_attr.rs @@ -1,18 +1,23 @@ #![feature(custom_inner_attributes)] #![clippy::msrv = "invalid.version"] +//~^ ERROR: `invalid.version` is not a valid Rust version fn main() {} #[clippy::msrv = "invalid.version"] +//~^ ERROR: `invalid.version` is not a valid Rust version fn outer_attr() {} mod multiple { #![clippy::msrv = "1.40"] #![clippy::msrv = "=1.35.0"] + //~^ ERROR: `msrv` is defined multiple times #![clippy::msrv = "1.10.1"] + //~^ ERROR: `msrv` is defined multiple times mod foo { #![clippy::msrv = "1"] #![clippy::msrv = "1.0.0"] + //~^ ERROR: `msrv` is defined multiple times } } diff --git a/tests/ui/min_rust_version_invalid_attr.stderr b/tests/ui/min_rust_version_invalid_attr.stderr index 675b780315251..8d4071e258ebc 100644 --- a/tests/ui/min_rust_version_invalid_attr.stderr +++ b/tests/ui/min_rust_version_invalid_attr.stderr @@ -5,43 +5,43 @@ LL | #![clippy::msrv = "invalid.version"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `invalid.version` is not a valid Rust version - --> $DIR/min_rust_version_invalid_attr.rs:6:1 + --> $DIR/min_rust_version_invalid_attr.rs:7:1 | LL | #[clippy::msrv = "invalid.version"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:11:5 + --> $DIR/min_rust_version_invalid_attr.rs:13:5 | LL | #![clippy::msrv = "=1.35.0"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:10:5 + --> $DIR/min_rust_version_invalid_attr.rs:12:5 | LL | #![clippy::msrv = "1.40"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:12:5 + --> $DIR/min_rust_version_invalid_attr.rs:15:5 | LL | #![clippy::msrv = "1.10.1"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:10:5 + --> $DIR/min_rust_version_invalid_attr.rs:12:5 | LL | #![clippy::msrv = "1.40"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:16:9 + --> $DIR/min_rust_version_invalid_attr.rs:20:9 | LL | #![clippy::msrv = "1.0.0"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:15:9 + --> $DIR/min_rust_version_invalid_attr.rs:19:9 | LL | #![clippy::msrv = "1"] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mismatching_type_param_order.rs b/tests/ui/mismatching_type_param_order.rs index 40c1fcae1fd3f..af2882e41fb10 100644 --- a/tests/ui/mismatching_type_param_order.rs +++ b/tests/ui/mismatching_type_param_order.rs @@ -9,9 +9,12 @@ fn main() { // lint on both params impl Foo {} + //~^ ERROR: `Foo` has a similarly named generic type parameter `B` in its declaration, + //~| ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, // lint on the 2nd param impl Foo {} + //~^ ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, // should not lint impl Foo {} @@ -23,6 +26,8 @@ fn main() { // should not lint on lifetimes impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} + //~^ ERROR: `FooLifetime` has a similarly named generic type parameter `B` in its decl + //~| ERROR: `FooLifetime` has a similarly named generic type parameter `A` in its decl struct Bar { x: i32, @@ -39,6 +44,9 @@ fn main() { } impl FooEnum {} + //~^ ERROR: `FooEnum` has a similarly named generic type parameter `C` in its declarat + //~| ERROR: `FooEnum` has a similarly named generic type parameter `A` in its declarat + //~| ERROR: `FooEnum` has a similarly named generic type parameter `B` in its declarat // also works for unions union FooUnion @@ -50,6 +58,8 @@ fn main() { } impl FooUnion where A: Copy {} + //~^ ERROR: `FooUnion` has a similarly named generic type parameter `B` in its declara + //~| ERROR: `FooUnion` has a similarly named generic type parameter `A` in its declara impl FooUnion where diff --git a/tests/ui/mismatching_type_param_order.stderr b/tests/ui/mismatching_type_param_order.stderr index 204d499055774..b3200a51d7857 100644 --- a/tests/ui/mismatching_type_param_order.stderr +++ b/tests/ui/mismatching_type_param_order.stderr @@ -16,7 +16,7 @@ LL | impl Foo {} = help: try `B`, or a name that does not conflict with `Foo`'s generic params error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:14:23 + --> $DIR/mismatching_type_param_order.rs:16:23 | LL | impl Foo {} | ^ @@ -24,7 +24,7 @@ LL | impl Foo {} = help: try `B`, or a name that does not conflict with `Foo`'s generic params error: `FooLifetime` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:25:44 + --> $DIR/mismatching_type_param_order.rs:28:44 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -32,7 +32,7 @@ LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} = help: try `A`, or a name that does not conflict with `FooLifetime`'s generic params error: `FooLifetime` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:25:47 + --> $DIR/mismatching_type_param_order.rs:28:47 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -40,7 +40,7 @@ LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} = help: try `B`, or a name that does not conflict with `FooLifetime`'s generic params error: `FooEnum` has a similarly named generic type parameter `C` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:27 + --> $DIR/mismatching_type_param_order.rs:46:27 | LL | impl FooEnum {} | ^ @@ -48,7 +48,7 @@ LL | impl FooEnum {} = help: try `A`, or a name that does not conflict with `FooEnum`'s generic params error: `FooEnum` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:30 + --> $DIR/mismatching_type_param_order.rs:46:30 | LL | impl FooEnum {} | ^ @@ -56,7 +56,7 @@ LL | impl FooEnum {} = help: try `B`, or a name that does not conflict with `FooEnum`'s generic params error: `FooEnum` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:33 + --> $DIR/mismatching_type_param_order.rs:46:33 | LL | impl FooEnum {} | ^ @@ -64,7 +64,7 @@ LL | impl FooEnum {} = help: try `C`, or a name that does not conflict with `FooEnum`'s generic params error: `FooUnion` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:52:31 + --> $DIR/mismatching_type_param_order.rs:60:31 | LL | impl FooUnion where A: Copy {} | ^ @@ -72,7 +72,7 @@ LL | impl FooUnion where A: Copy {} = help: try `A`, or a name that does not conflict with `FooUnion`'s generic params error: `FooUnion` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:52:34 + --> $DIR/mismatching_type_param_order.rs:60:34 | LL | impl FooUnion where A: Copy {} | ^ diff --git a/tests/ui/misnamed_getters.fixed b/tests/ui/misnamed_getters.fixed index fd7d127655872..2a7a2067ee083 100644 --- a/tests/ui/misnamed_getters.fixed +++ b/tests/ui/misnamed_getters.fixed @@ -9,25 +9,32 @@ struct A { impl A { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings` &self.a } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.b } fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn c(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.c } fn c_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.c } } @@ -39,17 +46,21 @@ union B { impl B { unsafe fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.a } unsafe fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } unsafe fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.b } unsafe fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } @@ -62,17 +73,21 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.a } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } unsafe fn b_unchecked(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.b } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } @@ -105,16 +120,20 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.a } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn d(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.d } fn d_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.d } } diff --git a/tests/ui/misnamed_getters.rs b/tests/ui/misnamed_getters.rs index 03e7dac7df94c..56ddc46c4d4a7 100644 --- a/tests/ui/misnamed_getters.rs +++ b/tests/ui/misnamed_getters.rs @@ -9,25 +9,32 @@ struct A { impl A { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings` &self.b } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn c(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn c_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } } @@ -39,17 +46,21 @@ union B { impl B { unsafe fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } unsafe fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } unsafe fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } unsafe fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } @@ -62,17 +73,21 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } unsafe fn b_unchecked(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } @@ -105,16 +120,20 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn d(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn d_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } } diff --git a/tests/ui/misnamed_getters.stderr b/tests/ui/misnamed_getters.stderr index 1e38a83d019a6..58f6f3eb7387c 100644 --- a/tests/ui/misnamed_getters.stderr +++ b/tests/ui/misnamed_getters.stderr @@ -2,6 +2,8 @@ error: getter function appears to return the wrong field --> $DIR/misnamed_getters.rs:11:5 | LL | / fn a(&self) -> &u8 { +LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } @@ -10,153 +12,170 @@ LL | | } = note: `-D clippy::misnamed-getters` implied by `-D warnings` error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:14:5 + --> $DIR/misnamed_getters.rs:16:5 | LL | / fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:18:5 + --> $DIR/misnamed_getters.rs:21:5 | LL | / fn b(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:22:5 + --> $DIR/misnamed_getters.rs:26:5 | LL | / fn b_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:26:5 + --> $DIR/misnamed_getters.rs:31:5 | LL | / fn c(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:30:5 + --> $DIR/misnamed_getters.rs:36:5 | LL | / fn c_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:41:5 + --> $DIR/misnamed_getters.rs:48:5 | LL | / unsafe fn a(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:44:5 + --> $DIR/misnamed_getters.rs:52:5 | LL | / unsafe fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:48:5 + --> $DIR/misnamed_getters.rs:57:5 | LL | / unsafe fn b(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:52:5 + --> $DIR/misnamed_getters.rs:62:5 | LL | / unsafe fn b_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:64:5 + --> $DIR/misnamed_getters.rs:75:5 | LL | / unsafe fn a_unchecked(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:67:5 + --> $DIR/misnamed_getters.rs:79:5 | LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:71:5 + --> $DIR/misnamed_getters.rs:84:5 | LL | / unsafe fn b_unchecked(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:75:5 + --> $DIR/misnamed_getters.rs:89:5 | LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:107:5 + --> $DIR/misnamed_getters.rs:122:5 | LL | / fn a(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:110:5 + --> $DIR/misnamed_getters.rs:126:5 | LL | / fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:114:5 + --> $DIR/misnamed_getters.rs:131:5 | LL | / fn d(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.d` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:117:5 + --> $DIR/misnamed_getters.rs:135:5 | LL | / fn d_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.d` LL | | } diff --git a/tests/ui/missing_assert_message.rs b/tests/ui/missing_assert_message.rs index af1358f61b5cb..2ad8e0127edf7 100644 --- a/tests/ui/missing_assert_message.rs +++ b/tests/ui/missing_assert_message.rs @@ -10,29 +10,45 @@ macro_rules! bar { // Should trigger warning fn asserts_without_message() { assert!(foo()); + //~^ ERROR: assert without any message assert_eq!(foo(), foo()); + //~^ ERROR: assert without any message assert_ne!(foo(), foo()); + //~^ ERROR: assert without any message debug_assert!(foo()); + //~^ ERROR: assert without any message debug_assert_eq!(foo(), foo()); + //~^ ERROR: assert without any message debug_assert_ne!(foo(), foo()); + //~^ ERROR: assert without any message } // Should trigger warning fn asserts_without_message_but_with_macro_calls() { assert!(bar!(true)); + //~^ ERROR: assert without any message assert!(bar!(true, false)); + //~^ ERROR: assert without any message assert_eq!(bar!(true), foo()); + //~^ ERROR: assert without any message assert_ne!(bar!(true, true), bar!(true)); + //~^ ERROR: assert without any message } // Should trigger warning fn asserts_with_trailing_commas() { assert!(foo(),); + //~^ ERROR: assert without any message assert_eq!(foo(), foo(),); + //~^ ERROR: assert without any message assert_ne!(foo(), foo(),); + //~^ ERROR: assert without any message debug_assert!(foo(),); + //~^ ERROR: assert without any message debug_assert_eq!(foo(), foo(),); + //~^ ERROR: assert without any message debug_assert_ne!(foo(), foo(),); + //~^ ERROR: assert without any message } // Should not trigger warning diff --git a/tests/ui/missing_assert_message.stderr b/tests/ui/missing_assert_message.stderr index 33a5c1f8e0526..00b9a36e9091f 100644 --- a/tests/ui/missing_assert_message.stderr +++ b/tests/ui/missing_assert_message.stderr @@ -8,7 +8,7 @@ LL | assert!(foo()); = note: `-D clippy::missing-assert-message` implied by `-D warnings` error: assert without any message - --> $DIR/missing_assert_message.rs:13:5 + --> $DIR/missing_assert_message.rs:14:5 | LL | assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | assert_eq!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:14:5 + --> $DIR/missing_assert_message.rs:16:5 | LL | assert_ne!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | assert_ne!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:15:5 + --> $DIR/missing_assert_message.rs:18:5 | LL | debug_assert!(foo()); | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | debug_assert!(foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:16:5 + --> $DIR/missing_assert_message.rs:20:5 | LL | debug_assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | debug_assert_eq!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:17:5 + --> $DIR/missing_assert_message.rs:22:5 | LL | debug_assert_ne!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | debug_assert_ne!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:22:5 + --> $DIR/missing_assert_message.rs:28:5 | LL | assert!(bar!(true)); | ^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | assert!(bar!(true)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:23:5 + --> $DIR/missing_assert_message.rs:30:5 | LL | assert!(bar!(true, false)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | assert!(bar!(true, false)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:24:5 + --> $DIR/missing_assert_message.rs:32:5 | LL | assert_eq!(bar!(true), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | assert_eq!(bar!(true), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:25:5 + --> $DIR/missing_assert_message.rs:34:5 | LL | assert_ne!(bar!(true, true), bar!(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | assert_ne!(bar!(true, true), bar!(true)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:30:5 + --> $DIR/missing_assert_message.rs:40:5 | LL | assert!(foo(),); | ^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | assert!(foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:31:5 + --> $DIR/missing_assert_message.rs:42:5 | LL | assert_eq!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | assert_eq!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:32:5 + --> $DIR/missing_assert_message.rs:44:5 | LL | assert_ne!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | assert_ne!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:33:5 + --> $DIR/missing_assert_message.rs:46:5 | LL | debug_assert!(foo(),); | ^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | debug_assert!(foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:34:5 + --> $DIR/missing_assert_message.rs:48:5 | LL | debug_assert_eq!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | debug_assert_eq!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:35:5 + --> $DIR/missing_assert_message.rs:50:5 | LL | debug_assert_ne!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_const_for_fn/could_be_const.rs b/tests/ui/missing_const_for_fn/could_be_const.rs index 3aaee67e1d971..6985c2d0c1956 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -12,37 +12,45 @@ struct Game { impl Game { // Could be const pub fn new() -> Self { + //~^ ERROR: this could be a `const fn` + //~| NOTE: `-D clippy::missing-const-for-fn` implied by `-D warnings` Self { guess: 42 } } fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { + //~^ ERROR: this could be a `const fn` b } } // Could be const fn one() -> i32 { + //~^ ERROR: this could be a `const fn` 1 } // Could also be const fn two() -> i32 { + //~^ ERROR: this could be a `const fn` let abc = 2; abc } // Could be const (since Rust 1.39) fn string() -> String { + //~^ ERROR: this could be a `const fn` String::new() } // Could be const unsafe fn four() -> i32 { + //~^ ERROR: this could be a `const fn` 4 } // Could also be const fn generic(t: T) -> T { + //~^ ERROR: this could be a `const fn` t } @@ -51,6 +59,7 @@ fn sub(x: u32) -> usize { } fn generic_arr(t: [T; 1]) -> T { + //~^ ERROR: this could be a `const fn` t[0] } @@ -64,6 +73,7 @@ mod with_drop { impl B { // This can be const, because `a` is passed by reference pub fn b(self, a: &A) -> B { + //~^ ERROR: this could be a `const fn` B } } @@ -73,6 +83,7 @@ mod with_drop { mod const_fn_stabilized_before_msrv { // This could be const because `u8::is_ascii_digit` is a stable const function in 1.47. fn const_fn_stabilized_before_msrv(byte: u8) { + //~^ ERROR: this could be a `const fn` byte.is_ascii_digit(); } } @@ -84,6 +95,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] fn msrv_1_46() -> i32 { + //~^ ERROR: this could be a `const fn` 46 } diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 66cf4e3152934..5c6f9e8a7f0d6 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -2,6 +2,8 @@ error: this could be a `const fn` --> $DIR/could_be_const.rs:14:5 | LL | / pub fn new() -> Self { +LL | | +LL | | LL | | Self { guess: 42 } LL | | } | |_____^ @@ -9,82 +11,92 @@ LL | | } = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` error: this could be a `const fn` - --> $DIR/could_be_const.rs:18:5 + --> $DIR/could_be_const.rs:20:5 | LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { +LL | | LL | | b LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:24:1 + --> $DIR/could_be_const.rs:27:1 | LL | / fn one() -> i32 { +LL | | LL | | 1 LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:29:1 + --> $DIR/could_be_const.rs:33:1 | LL | / fn two() -> i32 { +LL | | LL | | let abc = 2; LL | | abc LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:35:1 + --> $DIR/could_be_const.rs:40:1 | LL | / fn string() -> String { +LL | | LL | | String::new() LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:40:1 + --> $DIR/could_be_const.rs:46:1 | LL | / unsafe fn four() -> i32 { +LL | | LL | | 4 LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:45:1 + --> $DIR/could_be_const.rs:52:1 | LL | / fn generic(t: T) -> T { +LL | | LL | | t LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:53:1 + --> $DIR/could_be_const.rs:61:1 | LL | / fn generic_arr(t: [T; 1]) -> T { +LL | | LL | | t[0] LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:66:9 + --> $DIR/could_be_const.rs:75:9 | LL | / pub fn b(self, a: &A) -> B { +LL | | LL | | B LL | | } | |_________^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:75:5 + --> $DIR/could_be_const.rs:85:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { +LL | | LL | | byte.is_ascii_digit(); LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:86:1 + --> $DIR/could_be_const.rs:97:1 | LL | / fn msrv_1_46() -> i32 { +LL | | LL | | 46 LL | | } | |_^ diff --git a/tests/ui/missing_doc_crate_missing.rs b/tests/ui/missing_doc_crate_missing.rs index 51fd57df8df1d..73584ac8c67d3 100644 --- a/tests/ui/missing_doc_crate_missing.rs +++ b/tests/ui/missing_doc_crate_missing.rs @@ -1,3 +1,5 @@ #![warn(clippy::missing_docs_in_private_items)] +//~^ ERROR: missing documentation for the crate +//~| NOTE: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` fn main() {} diff --git a/tests/ui/missing_doc_crate_missing.stderr b/tests/ui/missing_doc_crate_missing.stderr index 19516bf5fab0e..75e033cc94b48 100644 --- a/tests/ui/missing_doc_crate_missing.stderr +++ b/tests/ui/missing_doc_crate_missing.stderr @@ -3,6 +3,8 @@ error: missing documentation for the crate | LL | / #![warn(clippy::missing_docs_in_private_items)] LL | | +LL | | +LL | | LL | | fn main() {} | |____________^ | diff --git a/tests/ui/missing_fields_in_debug.rs b/tests/ui/missing_fields_in_debug.rs index c156d394eceaa..e91e8ab7f475e 100644 --- a/tests/ui/missing_fields_in_debug.rs +++ b/tests/ui/missing_fields_in_debug.rs @@ -11,6 +11,7 @@ struct NamedStruct1Ignored { } impl fmt::Debug for NamedStruct1Ignored { + //~^ ERROR: manual `Debug` impl does not include all fields // unused field: hidden fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -29,6 +30,7 @@ struct NamedStructMultipleIgnored { } impl fmt::Debug for NamedStructMultipleIgnored { + //~^ ERROR: manual `Debug` impl does not include all fields // unused fields: hidden, hidden2, hidden4 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -90,6 +92,7 @@ struct MultiExprDebugImpl { // ok impl fmt::Debug for MultiExprDebugImpl { + //~^ ERROR: manual `Debug` impl does not include all fields fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = formatter.debug_struct("MultiExprDebugImpl"); f.field("a", &self.a); diff --git a/tests/ui/missing_fields_in_debug.stderr b/tests/ui/missing_fields_in_debug.stderr index ef9d02abab7db..51b5e7b314ace 100644 --- a/tests/ui/missing_fields_in_debug.stderr +++ b/tests/ui/missing_fields_in_debug.stderr @@ -2,9 +2,9 @@ error: manual `Debug` impl does not include all fields --> $DIR/missing_fields_in_debug.rs:13:1 | LL | / impl fmt::Debug for NamedStruct1Ignored { +LL | | LL | | // unused field: hidden LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | formatter ... | LL | | } LL | | } @@ -20,29 +20,29 @@ LL | hidden: u32, = note: `-D clippy::missing-fields-in-debug` implied by `-D warnings` error: manual `Debug` impl does not include all fields - --> $DIR/missing_fields_in_debug.rs:31:1 + --> $DIR/missing_fields_in_debug.rs:32:1 | LL | / impl fmt::Debug for NamedStructMultipleIgnored { +LL | | LL | | // unused fields: hidden, hidden2, hidden4 LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | formatter ... | LL | | } LL | | } | |_^ | note: this field is unused - --> $DIR/missing_fields_in_debug.rs:25:5 + --> $DIR/missing_fields_in_debug.rs:26:5 | LL | hidden: u32, | ^^^^^^^^^^^ note: this field is unused - --> $DIR/missing_fields_in_debug.rs:26:5 + --> $DIR/missing_fields_in_debug.rs:27:5 | LL | hidden2: String, | ^^^^^^^^^^^^^^^ note: this field is unused - --> $DIR/missing_fields_in_debug.rs:28:5 + --> $DIR/missing_fields_in_debug.rs:29:5 | LL | hidden4: ((((u8), u16), u32), u64), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,19 +50,19 @@ LL | hidden4: ((((u8), u16), u32), u64), = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields error: manual `Debug` impl does not include all fields - --> $DIR/missing_fields_in_debug.rs:92:1 + --> $DIR/missing_fields_in_debug.rs:94:1 | LL | / impl fmt::Debug for MultiExprDebugImpl { +LL | | LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { LL | | let mut f = formatter.debug_struct("MultiExprDebugImpl"); -LL | | f.field("a", &self.a); -LL | | f.finish() +... | LL | | } LL | | } | |_^ | note: this field is unused - --> $DIR/missing_fields_in_debug.rs:88:5 + --> $DIR/missing_fields_in_debug.rs:90:5 | LL | b: String, | ^^^^^^^^^ diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index c5cf97d3cd655..dca85b94d5ee5 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -18,6 +18,8 @@ pub mod pub_module {} // ok fn foo() {} // missing #[inline] pub fn pub_foo() {} +//~^ ERROR: missing `#[inline]` for a function +//~| NOTE: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -35,6 +37,7 @@ pub trait PubBar { fn PubBar_a(); // ok // missing #[inline] fn PubBar_b() {} + //~^ ERROR: missing `#[inline]` for a default trait method #[inline] fn PubBar_c() {} // ok } @@ -50,10 +53,13 @@ impl PubBar for Foo { impl PubBar for PubFoo { // missing #[inline] fn PubBar_a() {} + //~^ ERROR: missing `#[inline]` for a method // missing #[inline] fn PubBar_b() {} + //~^ ERROR: missing `#[inline]` for a method // missing #[inline] fn PubBar_c() {} + //~^ ERROR: missing `#[inline]` for a method } // do not need inline because Foo is not exported @@ -65,6 +71,7 @@ impl Foo { impl PubFoo { // missing #[inline] pub fn PubFooImpl() {} + //~^ ERROR: missing `#[inline]` for a method } // do not lint this since users cannot control the external code diff --git a/tests/ui/missing_inline.stderr b/tests/ui/missing_inline.stderr index 73f876c1d1a31..be24af49273f2 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -7,31 +7,31 @@ LL | pub fn pub_foo() {} = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` error: missing `#[inline]` for a default trait method - --> $DIR/missing_inline.rs:37:5 + --> $DIR/missing_inline.rs:39:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:52:5 + --> $DIR/missing_inline.rs:55:5 | LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:54:5 + --> $DIR/missing_inline.rs:58:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:56:5 + --> $DIR/missing_inline.rs:61:5 | LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:67:5 + --> $DIR/missing_inline.rs:73:5 | LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_trait_methods.rs b/tests/ui/missing_trait_methods.rs index 8df885919a3e6..1b09b717ff70a 100644 --- a/tests/ui/missing_trait_methods.rs +++ b/tests/ui/missing_trait_methods.rs @@ -20,8 +20,10 @@ trait B { struct Partial; impl A for Partial {} +//~^ ERROR: missing trait method provided by default: `provided` impl B for Partial { + //~^ ERROR: missing trait method provided by default: `b` fn required() {} fn a(_: usize) -> usize { diff --git a/tests/ui/missing_trait_methods.stderr b/tests/ui/missing_trait_methods.stderr index 0c5205e196572..8f50e76135c4d 100644 --- a/tests/ui/missing_trait_methods.stderr +++ b/tests/ui/missing_trait_methods.stderr @@ -12,7 +12,7 @@ LL | fn provided() {} = note: `-D clippy::missing-trait-methods` implied by `-D warnings` error: missing trait method provided by default: `b` - --> $DIR/missing_trait_methods.rs:24:1 + --> $DIR/missing_trait_methods.rs:25:1 | LL | impl B for Partial { | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mixed_read_write_in_expression.rs b/tests/ui/mixed_read_write_in_expression.rs index 6efc7657ec0c9..241536abdfbd7 100644 --- a/tests/ui/mixed_read_write_in_expression.rs +++ b/tests/ui/mixed_read_write_in_expression.rs @@ -12,9 +12,11 @@ fn main() { x = 1; 1 } + x; + //~^ ERROR: unsequenced read of `x` // Example from iss#277 x += { + //~^ ERROR: unsequenced read of `x` x = 20; 2 }; @@ -28,6 +30,7 @@ fn main() { let base = Foo { a: 4, b: 5 }; let foo = Foo { a: x, + //~^ ERROR: unsequenced read of `x` ..{ x = 6; base @@ -37,6 +40,7 @@ fn main() { let closure = || { let mut x = 0; x += { + //~^ ERROR: unsequenced read of `x` x = 20; 2 }; diff --git a/tests/ui/mixed_read_write_in_expression.stderr b/tests/ui/mixed_read_write_in_expression.stderr index 8cc68b0ac7b43..e0b405ddece9b 100644 --- a/tests/ui/mixed_read_write_in_expression.stderr +++ b/tests/ui/mixed_read_write_in_expression.stderr @@ -12,37 +12,37 @@ LL | x = 1; = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings` error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:17:5 + --> $DIR/mixed_read_write_in_expression.rs:18:5 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:18:9 + --> $DIR/mixed_read_write_in_expression.rs:20:9 | LL | x = 20; | ^^^^^^ error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:30:12 + --> $DIR/mixed_read_write_in_expression.rs:32:12 | LL | a: x, | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:32:13 + --> $DIR/mixed_read_write_in_expression.rs:35:13 | LL | x = 6; | ^^^^^ error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:39:9 + --> $DIR/mixed_read_write_in_expression.rs:42:9 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:40:13 + --> $DIR/mixed_read_write_in_expression.rs:44:13 | LL | x = 20; | ^^^^^^ diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs index 802c3ec39b64b..ad46e0c29aee3 100644 --- a/tests/ui/module_inception.rs +++ b/tests/ui/module_inception.rs @@ -3,11 +3,14 @@ pub mod foo2 { pub mod bar2 { pub mod bar2 { + //~^ ERROR: module has the same name as its containing module + //~| NOTE: `-D clippy::module-inception` implied by `-D warnings` pub mod foo2 {} } pub mod foo2 {} } pub mod foo2 { + //~^ ERROR: module has the same name as its containing module pub mod bar2 {} } } @@ -15,11 +18,13 @@ pub mod foo2 { mod foo { mod bar { mod bar { + //~^ ERROR: module has the same name as its containing module mod foo {} } mod foo {} } mod foo { + //~^ ERROR: module has the same name as its containing module mod bar {} } } diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr index ebb8e296f4646..b4f80a5bc7c2f 100644 --- a/tests/ui/module_inception.stderr +++ b/tests/ui/module_inception.stderr @@ -2,6 +2,8 @@ error: module has the same name as its containing module --> $DIR/module_inception.rs:5:9 | LL | / pub mod bar2 { +LL | | +LL | | LL | | pub mod foo2 {} LL | | } | |_________^ @@ -9,25 +11,28 @@ LL | | } = note: `-D clippy::module-inception` implied by `-D warnings` error: module has the same name as its containing module - --> $DIR/module_inception.rs:10:5 + --> $DIR/module_inception.rs:12:5 | LL | / pub mod foo2 { +LL | | LL | | pub mod bar2 {} LL | | } | |_____^ error: module has the same name as its containing module - --> $DIR/module_inception.rs:17:9 + --> $DIR/module_inception.rs:20:9 | LL | / mod bar { +LL | | LL | | mod foo {} LL | | } | |_________^ error: module has the same name as its containing module - --> $DIR/module_inception.rs:22:5 + --> $DIR/module_inception.rs:26:5 | LL | / mod foo { +LL | | LL | | mod bar {} LL | | } | |_____^ diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index fb2c7612343c8..a6cf03890983f 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -6,10 +6,16 @@ mod foo { pub fn foo() {} pub fn foo_bar() {} + //~^ ERROR: item name starts with its containing module's name + //~| NOTE: `-D clippy::module-name-repetitions` implied by `-D warnings` pub fn bar_foo() {} + //~^ ERROR: item name ends with its containing module's name pub struct FooCake; + //~^ ERROR: item name starts with its containing module's name pub enum CakeFoo {} + //~^ ERROR: item name ends with its containing module's name pub struct Foo7Bar; + //~^ ERROR: item name starts with its containing module's name // Should not warn pub struct Foobar; diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index 277801194a1d5..3c7fa1def2ba2 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -7,25 +7,25 @@ LL | pub fn foo_bar() {} = note: `-D clippy::module-name-repetitions` implied by `-D warnings` error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:9:12 + --> $DIR/module_name_repetitions.rs:11:12 | LL | pub fn bar_foo() {} | ^^^^^^^ error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:10:16 + --> $DIR/module_name_repetitions.rs:13:16 | LL | pub struct FooCake; | ^^^^^^^ error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:11:14 + --> $DIR/module_name_repetitions.rs:15:14 | LL | pub enum CakeFoo {} | ^^^^^^^ error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:12:16 + --> $DIR/module_name_repetitions.rs:17:16 | LL | pub struct Foo7Bar; | ^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_float.rs b/tests/ui/modulo_arithmetic_float.rs index b1861f07cd189..37895ea09e72c 100644 --- a/tests/ui/modulo_arithmetic_float.rs +++ b/tests/ui/modulo_arithmetic_float.rs @@ -4,22 +4,42 @@ fn main() { // Lint when both sides are const and of the opposite sign -1.6 % 2.1; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1.600 % + //~| NOTE: double check for expected result especially when interoperating with differ 1.6 % -2.1; + //~^ ERROR: you are using modulo operator on constants with different signs: `1.600 % + //~| NOTE: double check for expected result especially when interoperating with differ (1.1 - 2.3) % (1.1 + 2.3); + //~^ ERROR: you are using modulo operator on constants with different signs: `-1.200 % + //~| NOTE: double check for expected result especially when interoperating with differ (1.1 + 2.3) % (1.1 - 2.3); + //~^ ERROR: you are using modulo operator on constants with different signs: `3.400 % + //~| NOTE: double check for expected result especially when interoperating with differ // Lint on floating point numbers let a_f32: f32 = -1.6; let mut b_f32: f32 = 2.1; a_f32 % b_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f32 % a_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f32 %= a_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_f64: f64 = -1.6; let mut b_f64: f64 = 2.1; a_f64 % b_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f64 % a_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f64 %= a_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ // No lint when both sides are const and of the same sign 1.6 % 2.1; diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr index 36106de31f0bc..3faf8c5aee1c1 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -8,7 +8,7 @@ LL | -1.6 % 2.1; = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> $DIR/modulo_arithmetic_float.rs:7:5 + --> $DIR/modulo_arithmetic_float.rs:9:5 | LL | 1.6 % -2.1; | ^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | 1.6 % -2.1; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `-1.200 % 3.400` - --> $DIR/modulo_arithmetic_float.rs:8:5 + --> $DIR/modulo_arithmetic_float.rs:12:5 | LL | (1.1 - 2.3) % (1.1 + 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | (1.1 - 2.3) % (1.1 + 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `3.400 % -1.200` - --> $DIR/modulo_arithmetic_float.rs:9:5 + --> $DIR/modulo_arithmetic_float.rs:15:5 | LL | (1.1 + 2.3) % (1.1 - 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | (1.1 + 2.3) % (1.1 - 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:14:5 + --> $DIR/modulo_arithmetic_float.rs:22:5 | LL | a_f32 % b_f32; | ^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | a_f32 % b_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:15:5 + --> $DIR/modulo_arithmetic_float.rs:25:5 | LL | b_f32 % a_f32; | ^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | b_f32 % a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:16:5 + --> $DIR/modulo_arithmetic_float.rs:28:5 | LL | b_f32 %= a_f32; | ^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | b_f32 %= a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:20:5 + --> $DIR/modulo_arithmetic_float.rs:34:5 | LL | a_f64 % b_f64; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | a_f64 % b_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:21:5 + --> $DIR/modulo_arithmetic_float.rs:37:5 | LL | b_f64 % a_f64; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | b_f64 % a_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:22:5 + --> $DIR/modulo_arithmetic_float.rs:40:5 | LL | b_f64 %= a_f64; | ^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral.rs b/tests/ui/modulo_arithmetic_integral.rs index fc1acc39ebc77..4dbed24026cf5 100644 --- a/tests/ui/modulo_arithmetic_integral.rs +++ b/tests/ui/modulo_arithmetic_integral.rs @@ -6,43 +6,77 @@ fn main() { let a = -1; let mut b = 2; a % b; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b % a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b %= a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i8: i8 = 1; let mut b_i8: i8 = 2; a_i8 % b_i8; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i8 %= a_i8; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i16: i16 = 1; let mut b_i16: i16 = 2; a_i16 % b_i16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i16 %= a_i16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i32: i32 = 1; let mut b_i32: i32 = 2; a_i32 % b_i32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i32 %= a_i32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i64: i64 = 1; let mut b_i64: i64 = 2; a_i64 % b_i64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i64 %= a_i64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i128: i128 = 1; let mut b_i128: i128 = 2; a_i128 % b_i128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i128 %= a_i128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_isize: isize = 1; let mut b_isize: isize = 2; a_isize % b_isize; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_isize %= a_isize; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a = 1; let mut b = 2; a % b; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b %= a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ // No lint on unsigned integral value let a_u8: u8 = 17; diff --git a/tests/ui/modulo_arithmetic_integral.stderr b/tests/ui/modulo_arithmetic_integral.stderr index 9ff676ff6bcb1..6d61afa0c3114 100644 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ b/tests/ui/modulo_arithmetic_integral.stderr @@ -9,7 +9,7 @@ LL | a % b; = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:9:5 + --> $DIR/modulo_arithmetic_integral.rs:11:5 | LL | b % a; | ^^^^^ @@ -18,7 +18,7 @@ LL | b % a; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:10:5 + --> $DIR/modulo_arithmetic_integral.rs:14:5 | LL | b %= a; | ^^^^^^ @@ -27,7 +27,7 @@ LL | b %= a; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:14:5 + --> $DIR/modulo_arithmetic_integral.rs:20:5 | LL | a_i8 % b_i8; | ^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | a_i8 % b_i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:15:5 + --> $DIR/modulo_arithmetic_integral.rs:23:5 | LL | b_i8 %= a_i8; | ^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | b_i8 %= a_i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:19:5 + --> $DIR/modulo_arithmetic_integral.rs:29:5 | LL | a_i16 % b_i16; | ^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | a_i16 % b_i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:20:5 + --> $DIR/modulo_arithmetic_integral.rs:32:5 | LL | b_i16 %= a_i16; | ^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | b_i16 %= a_i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:24:5 + --> $DIR/modulo_arithmetic_integral.rs:38:5 | LL | a_i32 % b_i32; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | a_i32 % b_i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:25:5 + --> $DIR/modulo_arithmetic_integral.rs:41:5 | LL | b_i32 %= a_i32; | ^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | b_i32 %= a_i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:29:5 + --> $DIR/modulo_arithmetic_integral.rs:47:5 | LL | a_i64 % b_i64; | ^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | a_i64 % b_i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:30:5 + --> $DIR/modulo_arithmetic_integral.rs:50:5 | LL | b_i64 %= a_i64; | ^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | b_i64 %= a_i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:34:5 + --> $DIR/modulo_arithmetic_integral.rs:56:5 | LL | a_i128 % b_i128; | ^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | a_i128 % b_i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:35:5 + --> $DIR/modulo_arithmetic_integral.rs:59:5 | LL | b_i128 %= a_i128; | ^^^^^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | b_i128 %= a_i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:39:5 + --> $DIR/modulo_arithmetic_integral.rs:65:5 | LL | a_isize % b_isize; | ^^^^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | a_isize % b_isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:40:5 + --> $DIR/modulo_arithmetic_integral.rs:68:5 | LL | b_isize %= a_isize; | ^^^^^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | b_isize %= a_isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:44:5 + --> $DIR/modulo_arithmetic_integral.rs:74:5 | LL | a % b; | ^^^^^ @@ -144,7 +144,7 @@ LL | a % b; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:45:5 + --> $DIR/modulo_arithmetic_integral.rs:77:5 | LL | b %= a; | ^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral_const.rs b/tests/ui/modulo_arithmetic_integral_const.rs index 3ebe46bc5be7c..dbc679a69825c 100644 --- a/tests/ui/modulo_arithmetic_integral_const.rs +++ b/tests/ui/modulo_arithmetic_integral_const.rs @@ -9,23 +9,57 @@ fn main() { // Lint when both sides are const and of the opposite sign -1 % 2; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1 % -2; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ (1 - 2) % (1 + 2); + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 3` + //~| NOTE: double check for expected result especially when interoperating with differ (1 + 2) % (1 - 2); + //~^ ERROR: you are using modulo operator on constants with different signs: `3 % -1` + //~| NOTE: double check for expected result especially when interoperating with differ 35 * (7 - 4 * 2) % (-500 * -600); + //~^ ERROR: you are using modulo operator on constants with different signs: `-35 % 30 + //~| NOTE: double check for expected result especially when interoperating with differ -1i8 % 2i8; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i8 % -2i8; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i16 % 2i16; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i16 % -2i16; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i32 % 2i32; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i32 % -2i32; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i64 % 2i64; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i64 % -2i64; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i128 % 2i128; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i128 % -2i128; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1isize % 2isize; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1isize % -2isize; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ // No lint when both sides are const and of the same sign 1 % 2; diff --git a/tests/ui/modulo_arithmetic_integral_const.stderr b/tests/ui/modulo_arithmetic_integral_const.stderr index 1453d44f488f3..59267b0e79696 100644 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/tests/ui/modulo_arithmetic_integral_const.stderr @@ -9,7 +9,7 @@ LL | -1 % 2; = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:12:5 + --> $DIR/modulo_arithmetic_integral_const.rs:14:5 | LL | 1 % -2; | ^^^^^^ @@ -18,7 +18,7 @@ LL | 1 % -2; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 3` - --> $DIR/modulo_arithmetic_integral_const.rs:13:5 + --> $DIR/modulo_arithmetic_integral_const.rs:17:5 | LL | (1 - 2) % (1 + 2); | ^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | (1 - 2) % (1 + 2); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `3 % -1` - --> $DIR/modulo_arithmetic_integral_const.rs:14:5 + --> $DIR/modulo_arithmetic_integral_const.rs:20:5 | LL | (1 + 2) % (1 - 2); | ^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | (1 + 2) % (1 - 2); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-35 % 300000` - --> $DIR/modulo_arithmetic_integral_const.rs:15:5 + --> $DIR/modulo_arithmetic_integral_const.rs:23:5 | LL | 35 * (7 - 4 * 2) % (-500 * -600); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | 35 * (7 - 4 * 2) % (-500 * -600); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:17:5 + --> $DIR/modulo_arithmetic_integral_const.rs:27:5 | LL | -1i8 % 2i8; | ^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | -1i8 % 2i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:18:5 + --> $DIR/modulo_arithmetic_integral_const.rs:30:5 | LL | 1i8 % -2i8; | ^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | 1i8 % -2i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:19:5 + --> $DIR/modulo_arithmetic_integral_const.rs:33:5 | LL | -1i16 % 2i16; | ^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | -1i16 % 2i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:20:5 + --> $DIR/modulo_arithmetic_integral_const.rs:36:5 | LL | 1i16 % -2i16; | ^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | 1i16 % -2i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:21:5 + --> $DIR/modulo_arithmetic_integral_const.rs:39:5 | LL | -1i32 % 2i32; | ^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | -1i32 % 2i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:22:5 + --> $DIR/modulo_arithmetic_integral_const.rs:42:5 | LL | 1i32 % -2i32; | ^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | 1i32 % -2i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:23:5 + --> $DIR/modulo_arithmetic_integral_const.rs:45:5 | LL | -1i64 % 2i64; | ^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | -1i64 % 2i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:24:5 + --> $DIR/modulo_arithmetic_integral_const.rs:48:5 | LL | 1i64 % -2i64; | ^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | 1i64 % -2i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:25:5 + --> $DIR/modulo_arithmetic_integral_const.rs:51:5 | LL | -1i128 % 2i128; | ^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | -1i128 % 2i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:26:5 + --> $DIR/modulo_arithmetic_integral_const.rs:54:5 | LL | 1i128 % -2i128; | ^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | 1i128 % -2i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:27:5 + --> $DIR/modulo_arithmetic_integral_const.rs:57:5 | LL | -1isize % 2isize; | ^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | -1isize % 2isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:28:5 + --> $DIR/modulo_arithmetic_integral_const.rs:60:5 | LL | 1isize % -2isize; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index 656b0b5cedcc2..c1dbe9d9a8787 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -6,23 +6,34 @@ static STATIC_NEG_ONE: i64 = 1 - 2; fn main() { 10 % 1; + //~^ ERROR: any number modulo 1 will be 0 + //~| NOTE: `-D clippy::modulo-one` implied by `-D warnings` 10 % -1; + //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 10 % 2; // also caught by rustc i32::MIN % (-1); + //~^ ERROR: this operation will panic at runtime + //~| NOTE: `#[deny(unconditional_panic)]` on by default + //~| ERROR: any number modulo -1 will panic/overflow or result in 0 const ONE: u32 = 1 * 1; const NEG_ONE: i64 = 1 - 2; const INT_MIN: i64 = i64::MIN; 2 % ONE; + //~^ ERROR: any number modulo 1 will be 0 // NOT caught by lint 5 % STATIC_ONE; 2 % NEG_ONE; + //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 // NOT caught by lint 5 % STATIC_NEG_ONE; // also caught by rustc INT_MIN % NEG_ONE; + //~^ ERROR: this operation will panic at runtime + //~| ERROR: any number modulo -1 will panic/overflow or result in 0 // ONLY caught by rustc INT_MIN % STATIC_NEG_ONE; + //~^ ERROR: this operation will panic at runtime } diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 0793e6386930b..62e23ee9a595f 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -1,5 +1,5 @@ error: this operation will panic at runtime - --> $DIR/modulo_one.rs:12:5 + --> $DIR/modulo_one.rs:15:5 | LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow @@ -7,13 +7,13 @@ LL | i32::MIN % (-1); = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/modulo_one.rs:25:5 + --> $DIR/modulo_one.rs:33:5 | LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: this operation will panic at runtime - --> $DIR/modulo_one.rs:27:5 + --> $DIR/modulo_one.rs:37:5 | LL | INT_MIN % STATIC_NEG_ONE; | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow @@ -27,31 +27,31 @@ LL | 10 % 1; = note: `-D clippy::modulo-one` implied by `-D warnings` error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:9:5 + --> $DIR/modulo_one.rs:11:5 | LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:12:5 + --> $DIR/modulo_one.rs:15:5 | LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:18:5 + --> $DIR/modulo_one.rs:24:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:28:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:25:5 + --> $DIR/modulo_one.rs:33:5 | LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/multi_assignments.rs b/tests/ui/multi_assignments.rs index b186bf8bbdb42..cdbf13b68889e 100644 --- a/tests/ui/multi_assignments.rs +++ b/tests/ui/multi_assignments.rs @@ -2,8 +2,15 @@ fn main() { let (mut a, mut b, mut c, mut d) = ((), (), (), ()); a = b = c; + //~^ ERROR: assignments don't nest intuitively + //~| NOTE: `-D clippy::multi-assignments` implied by `-D warnings` a = b = c = d; + //~^ ERROR: assignments don't nest intuitively + //~| ERROR: assignments don't nest intuitively a = b = { c }; + //~^ ERROR: assignments don't nest intuitively a = { b = c }; + //~^ ERROR: assignments don't nest intuitively a = (b = c); + //~^ ERROR: assignments don't nest intuitively } diff --git a/tests/ui/multi_assignments.stderr b/tests/ui/multi_assignments.stderr index d6c42bb698cf9..813e920f74d74 100644 --- a/tests/ui/multi_assignments.stderr +++ b/tests/ui/multi_assignments.stderr @@ -7,31 +7,31 @@ LL | a = b = c; = note: `-D clippy::multi-assignments` implied by `-D warnings` error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:5:5 + --> $DIR/multi_assignments.rs:7:5 | LL | a = b = c = d; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:5:9 + --> $DIR/multi_assignments.rs:7:9 | LL | a = b = c = d; | ^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:6:5 + --> $DIR/multi_assignments.rs:10:5 | LL | a = b = { c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:7:5 + --> $DIR/multi_assignments.rs:12:5 | LL | a = { b = c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:8:5 + --> $DIR/multi_assignments.rs:14:5 | LL | a = (b = c); | ^^^^^^^^^^^ diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs index 8c0c23b657065..0ab6d77de1e1d 100644 --- a/tests/ui/mut_from_ref.rs +++ b/tests/ui/mut_from_ref.rs @@ -5,12 +5,14 @@ struct Foo; impl Foo { fn this_wont_hurt_a_bit(&self) -> &mut Foo { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } } trait Ouch { fn ouch(x: &Foo) -> &mut Foo; + //~^ ERROR: mutable borrow from immutable input(s) } impl Ouch for Foo { @@ -20,14 +22,17 @@ impl Ouch for Foo { } fn fail(x: &u32) -> &mut u16 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } @@ -42,6 +47,7 @@ fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 { } unsafe fn also_broken(x: &u32) -> &mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unimplemented!() } diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index c20ff54bf949b..1c3df2b54fca0 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -12,61 +12,61 @@ LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { = note: `-D clippy::mut-from-ref` implied by `-D warnings` error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:13:25 + --> $DIR/mut_from_ref.rs:14:25 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:13:16 + --> $DIR/mut_from_ref.rs:14:16 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:22:21 + --> $DIR/mut_from_ref.rs:24:21 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:22:12 + --> $DIR/mut_from_ref.rs:24:12 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:26:50 + --> $DIR/mut_from_ref.rs:29:50 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:26:25 + --> $DIR/mut_from_ref.rs:29:25 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:30:67 + --> $DIR/mut_from_ref.rs:34:67 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:30:27 + --> $DIR/mut_from_ref.rs:34:27 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^ ^^^^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:44:35 + --> $DIR/mut_from_ref.rs:49:35 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:44:26 + --> $DIR/mut_from_ref.rs:49:26 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^ diff --git a/tests/ui/mut_key.rs b/tests/ui/mut_key.rs index 24cf2fbbf12ac..8069213217683 100644 --- a/tests/ui/mut_key.rs +++ b/tests/ui/mut_key.rs @@ -29,7 +29,13 @@ impl Hash for Key { } fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { + //~^ ERROR: mutable key type + //~| NOTE: `-D clippy::mutable-key-type` implied by `-D warnings` + //~| ERROR: mutable key type + //~| ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` let _other: HashMap = HashMap::new(); + //~^ ERROR: mutable key type m.keys().cloned().collect() } @@ -57,6 +63,7 @@ fn generics_are_ok_too(_m: &mut HashSet) { fn tuples(_m: &mut HashMap<((), U), ()>) {} fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} +//~^ ERROR: mutable key type fn main() { let _ = should_not_take_this_arg(&mut HashMap::new(), 1); @@ -69,18 +76,31 @@ fn main() { raw_mut_ptr_is_ok(&mut HashMap::new()); let _map = HashMap::, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::<&mut Cell, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::<&mut usize, usize>::new(); + //~^ ERROR: mutable key type // Collection types from `std` who's impl of `Hash` or `Ord` delegate their type parameters let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::, ()>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::, usize>::new(); + //~^ ERROR: mutable key type // Smart pointers from `std` who's impl of `Hash` or `Ord` delegate their type parameters let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type } diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr index 3f756f5f0e598..bce9d4b589274 100644 --- a/tests/ui/mut_key.stderr +++ b/tests/ui/mut_key.stderr @@ -13,91 +13,91 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash | ^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:32:5 + --> $DIR/mut_key.rs:37:5 | LL | let _other: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:59:22 + --> $DIR/mut_key.rs:65:22 | LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:71:5 + --> $DIR/mut_key.rs:78:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:72:5 + --> $DIR/mut_key.rs:80:5 | LL | let _map = HashMap::<&mut Cell, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:73:5 + --> $DIR/mut_key.rs:82:5 | LL | let _map = HashMap::<&mut usize, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:75:5 + --> $DIR/mut_key.rs:85:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:76:5 + --> $DIR/mut_key.rs:87:5 | LL | let _map = HashMap::, ()>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:77:5 + --> $DIR/mut_key.rs:89:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:78:5 + --> $DIR/mut_key.rs:91:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:79:5 + --> $DIR/mut_key.rs:93:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:80:5 + --> $DIR/mut_key.rs:95:5 | LL | let _map = HashMap::>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:81:5 + --> $DIR/mut_key.rs:97:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:83:5 + --> $DIR/mut_key.rs:100:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:84:5 + --> $DIR/mut_key.rs:102:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:85:5 + --> $DIR/mut_key.rs:104:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index 2c0d71ef0dd15..7aebbf4981ee8 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -6,6 +6,8 @@ fn mut_range_bound_upper() { let mut m = 4; for i in 0..m { m = 5; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged } } @@ -13,6 +15,8 @@ fn mut_range_bound_lower() { let mut m = 4; for i in m..10 { m *= 2; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged } } @@ -21,7 +25,11 @@ fn mut_range_bound_both() { let mut n = 6; for i in m..n { m = 5; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged n = 7; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged } } @@ -36,6 +44,8 @@ fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { let n = &mut m; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged *n += 1; } } @@ -69,6 +79,8 @@ fn mut_range_bound_no_immediate_break() { for i in 0..m { // warning because it is not immediately followed by break m = 2; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged if m == 4 { break; } @@ -79,6 +91,8 @@ fn mut_range_bound_no_immediate_break() { if n == 4 { // FIXME: warning because it is not immediately followed by break n = 1; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged let _ = 2; break; } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index 6183135fc9c13..c9de5393a2b17 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -8,7 +8,7 @@ LL | m = 5; = note: `-D clippy::mut-range-bound` implied by `-D warnings` error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:15:9 + --> $DIR/mut_range_bound.rs:17:9 | LL | m *= 2; | ^ @@ -16,7 +16,7 @@ LL | m *= 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:23:9 + --> $DIR/mut_range_bound.rs:27:9 | LL | m = 5; | ^ @@ -24,7 +24,7 @@ LL | m = 5; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:24:9 + --> $DIR/mut_range_bound.rs:30:9 | LL | n = 7; | ^ @@ -32,7 +32,7 @@ LL | n = 7; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:38:22 + --> $DIR/mut_range_bound.rs:46:22 | LL | let n = &mut m; | ^ @@ -40,7 +40,7 @@ LL | let n = &mut m; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:71:9 + --> $DIR/mut_range_bound.rs:81:9 | LL | m = 2; | ^ @@ -48,7 +48,7 @@ LL | m = 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:81:13 + --> $DIR/mut_range_bound.rs:93:13 | LL | n = 1; | ^ diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index 80edfb261e8ef..f3db226e4e7fc 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -22,18 +22,24 @@ impl MyStruct { fn takes_an_immutable_reference(&self, a: &i32) {} fn takes_a_mutable_reference(&self, a: &mut i32) {} + //~^ ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` } #[warn(clippy::unnecessary_mut_passed)] fn main() { // Functions takes_an_immutable_reference(&mut 42); + //~^ ERROR: the function `takes_an_immutable_reference` doesn't need a mutable referen + //~| NOTE: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` let as_ptr: fn(&i32) = takes_an_immutable_reference; as_ptr(&mut 42); + //~^ ERROR: the function `as_ptr` doesn't need a mutable reference // Methods let my_struct = MyStruct; my_struct.takes_an_immutable_reference(&mut 42); + //~^ ERROR: the method `takes_an_immutable_reference` doesn't need a mutable reference // No error diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index d8a71d264610a..4346560cea51e 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -1,5 +1,5 @@ error: the function `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:30:34 + --> $DIR/mut_reference.rs:32:34 | LL | takes_an_immutable_reference(&mut 42); | ^^^^^^^ @@ -7,13 +7,13 @@ LL | takes_an_immutable_reference(&mut 42); = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` error: the function `as_ptr` doesn't need a mutable reference - --> $DIR/mut_reference.rs:32:12 + --> $DIR/mut_reference.rs:36:12 | LL | as_ptr(&mut 42); | ^^^^^^^ error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:36:44 + --> $DIR/mut_reference.rs:41:44 | LL | my_struct.takes_an_immutable_reference(&mut 42); | ^^^^^^^ diff --git a/tests/ui/mutex_atomic.rs b/tests/ui/mutex_atomic.rs index 47b3dad398977..198b95d8c9486 100644 --- a/tests/ui/mutex_atomic.rs +++ b/tests/ui/mutex_atomic.rs @@ -6,12 +6,21 @@ fn main() { use std::sync::Mutex; Mutex::new(true); + //~^ ERROR: consider using an `AtomicBool` instead of a `Mutex` here; if you just want + //~| NOTE: `-D clippy::mutex-atomic` implied by `-D warnings` Mutex::new(5usize); + //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan Mutex::new(9isize); + //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan let mut x = 4u32; Mutex::new(&x as *const u32); + //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want Mutex::new(&mut x as *mut u32); + //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want Mutex::new(0u32); + //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan + //~| NOTE: `-D clippy::mutex-integer` implied by `-D warnings` Mutex::new(0i32); + //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan Mutex::new(0f32); // there are no float atomics, so this should not lint } diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 262028a8723a3..2f669067da6fa 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -7,31 +7,31 @@ LL | Mutex::new(true); = note: `-D clippy::mutex-atomic` implied by `-D warnings` error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:9:5 + --> $DIR/mutex_atomic.rs:11:5 | LL | Mutex::new(5usize); | ^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:10:5 + --> $DIR/mutex_atomic.rs:13:5 | LL | Mutex::new(9isize); | ^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:12:5 + --> $DIR/mutex_atomic.rs:16:5 | LL | Mutex::new(&x as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:13:5 + --> $DIR/mutex_atomic.rs:18:5 | LL | Mutex::new(&mut x as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:14:5 + --> $DIR/mutex_atomic.rs:20:5 | LL | Mutex::new(0u32); | ^^^^^^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | Mutex::new(0u32); = note: `-D clippy::mutex-integer` implied by `-D warnings` error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:15:5 + --> $DIR/mutex_atomic.rs:23:5 | LL | Mutex::new(0i32); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_borrow_pat.fixed b/tests/ui/needless_borrow_pat.fixed index a9091d784a7f8..8f8887f08a270 100644 --- a/tests/ui/needless_borrow_pat.fixed +++ b/tests/ui/needless_borrow_pat.fixed @@ -57,18 +57,22 @@ fn main() { // Err, reference to a &String let _: &String = match Some(&x) { Some(x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::needless-borrow` implied by `-D warnings` None => return, }; // Err, reference to a &String. let _: &String = match Some(&x) { Some(x) => x, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(x); x @@ -79,16 +83,19 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(x) => m1!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _ = |&x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; }; // Err, reference to a &String let (y,) = (&x,); + //~^ ERROR: this pattern creates a reference to a reference let _: &String = y; let y = &&x; @@ -99,6 +106,7 @@ fn main() { // Err, reference to a &u32. Don't suggest adding a reference to the field access. let _: u32 = match Some(&x) { Some(x) => x.0, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; @@ -109,12 +117,14 @@ fn main() { // Err, reference to &u32. let _: &u32 = match E::A(&0) { E::A(x) | E::B(x) => x, + //~^ ERROR: this pattern creates a reference to a reference }; // Err, reference to &String. if_chain! { if true; if let Some(x) = Some(&String::new()); + //~^ ERROR: this pattern creates a reference to a reference then { f1(x); } @@ -123,6 +133,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; x } @@ -130,6 +141,7 @@ fn f2<'a>(&x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } @@ -138,6 +150,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } diff --git a/tests/ui/needless_borrow_pat.rs b/tests/ui/needless_borrow_pat.rs index 222e8e617995d..56dbd923f2560 100644 --- a/tests/ui/needless_borrow_pat.rs +++ b/tests/ui/needless_borrow_pat.rs @@ -57,18 +57,22 @@ fn main() { // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::needless-borrow` implied by `-D warnings` None => return, }; // Err, reference to a &String. let _: &String = match Some(&x) { Some(ref x) => *x, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(*x); x @@ -79,16 +83,19 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m1!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _ = |&ref x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; }; // Err, reference to a &String let (ref y,) = (&x,); + //~^ ERROR: this pattern creates a reference to a reference let _: &String = *y; let y = &&x; @@ -99,6 +106,7 @@ fn main() { // Err, reference to a &u32. Don't suggest adding a reference to the field access. let _: u32 = match Some(&x) { Some(ref x) => x.0, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; @@ -109,12 +117,14 @@ fn main() { // Err, reference to &u32. let _: &u32 = match E::A(&0) { E::A(ref x) | E::B(ref x) => *x, + //~^ ERROR: this pattern creates a reference to a reference }; // Err, reference to &String. if_chain! { if true; if let Some(ref x) = Some(&String::new()); + //~^ ERROR: this pattern creates a reference to a reference then { f1(x); } @@ -123,6 +133,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; *x } @@ -130,6 +141,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } @@ -138,6 +150,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = *x; } } diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 2d9b8f1590213..4eac32fcd9cfa 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -7,7 +7,7 @@ LL | Some(ref x) => x, = note: `-D clippy::needless-borrow` implied by `-D warnings` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:65:14 + --> $DIR/needless_borrow_pat.rs:67:14 | LL | Some(ref x) => *x, | ^^^^^ @@ -18,7 +18,7 @@ LL | Some(x) => x, | ~ ~ error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:71:14 + --> $DIR/needless_borrow_pat.rs:74:14 | LL | Some(ref x) => { | ^^^^^ @@ -26,24 +26,25 @@ LL | Some(ref x) => { help: try | LL ~ Some(x) => { +LL | LL | f1(x); LL ~ f1(x); | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:81:14 + --> $DIR/needless_borrow_pat.rs:85:14 | LL | Some(ref x) => m1!(x), | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:86:15 + --> $DIR/needless_borrow_pat.rs:91:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:91:10 + --> $DIR/needless_borrow_pat.rs:97:10 | LL | let (ref y,) = (&x,); | ^^^^^ @@ -51,17 +52,18 @@ LL | let (ref y,) = (&x,); help: try | LL ~ let (y,) = (&x,); +LL | LL ~ let _: &String = y; | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:101:14 + --> $DIR/needless_borrow_pat.rs:108:14 | LL | Some(ref x) => x.0, | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:111:14 + --> $DIR/needless_borrow_pat.rs:119:14 | LL | E::A(ref x) | E::B(ref x) => *x, | ^^^^^ ^^^^^ @@ -72,13 +74,13 @@ LL | E::A(x) | E::B(x) => x, | ~ ~ ~ error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:117:21 + --> $DIR/needless_borrow_pat.rs:126:21 | LL | if let Some(ref x) = Some(&String::new()); | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:125:12 + --> $DIR/needless_borrow_pat.rs:135:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -86,18 +88,19 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL | LL | let _: &String = x; LL ~ x | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:132:11 + --> $DIR/needless_borrow_pat.rs:143:11 | LL | fn f(&ref x: &&String) { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:140:11 + --> $DIR/needless_borrow_pat.rs:152:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -105,6 +108,7 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &String = x; | diff --git a/tests/ui/needless_collect_indirect.rs b/tests/ui/needless_collect_indirect.rs index 1c236a601b967..9d66c5f255fe5 100644 --- a/tests/ui/needless_collect_indirect.rs +++ b/tests/ui/needless_collect_indirect.rs @@ -7,12 +7,17 @@ use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; fn main() { let sample = [1; 5]; let indirect_iter = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); let indirect_len = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len(); let indirect_empty = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_empty.is_empty(); let indirect_contains = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_contains.contains(&&5); let indirect_negative = sample.iter().collect::>(); indirect_negative.len(); @@ -25,6 +30,7 @@ fn main() { let a = "a".to_string(); let sample = vec![a.clone(), "b".to_string(), "c".to_string()]; let non_copy_contains = sample.into_iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed non_copy_contains.contains(&a); // Fix #5991 @@ -54,21 +60,25 @@ mod issue7110 { fn lint_vec(string: &str) -> usize { let buffer: Vec<&str> = string.split('/').collect(); + //~^ ERROR: avoid using `collect()` when not needed buffer.len() } fn lint_vec_deque() -> usize { let sample = [1; 5]; let indirect_len: VecDeque<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn lint_linked_list() -> usize { let sample = [1; 5]; let indirect_len: LinkedList<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn lint_binary_heap() -> usize { let sample = [1; 5]; let indirect_len: BinaryHeap<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn dont_lint(string: &str) -> usize { @@ -129,6 +139,7 @@ mod issue_8553 { for i in 0..2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&i); @@ -154,6 +165,7 @@ mod issue_8553 { while n > 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -183,6 +195,7 @@ mod issue_8553 { loop { if n < 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -219,6 +232,7 @@ mod issue_8553 { while let Some(value) = optional { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); if n < 2 { // Do lint @@ -244,6 +258,7 @@ mod issue_8553 { let vec = vec![1, 2]; let v: Vec = vec.iter().map(|i| i * i).collect(); let w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint for _ in 0..w.len() { todo!(); @@ -266,6 +281,7 @@ mod issue_8553 { let mut vec = vec![1, 2]; let mut v: Vec = vec.iter().map(|i| i * i).collect(); let mut w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint while 1 == w.len() { todo!(); @@ -288,6 +304,7 @@ mod issue_8553 { let mut vec = vec![1, 2]; let mut v: Vec = vec.iter().map(|i| i * i).collect(); let mut w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint while let Some(i) = Some(w.len()) { todo!(); diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index 8f84c5596889c..9337a7412425a 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -3,6 +3,7 @@ error: avoid using `collect()` when not needed | LL | let indirect_iter = sample.iter().collect::>(); | ^^^^^^^ +... LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); | ------------------------- the iterator could be used here instead | @@ -10,123 +11,141 @@ LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>( help: use the original Iterator instead of collecting it and then producing a new one | LL ~ +LL | +LL | LL ~ sample.iter().map(|x| (x, x + 1)).collect::>(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:11:38 + --> $DIR/needless_collect_indirect.rs:13:38 | LL | let indirect_len = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_len.len(); | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:13:40 + --> $DIR/needless_collect_indirect.rs:16:40 | LL | let indirect_empty = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_empty.is_empty(); | ------------------------- the iterator could be used here instead | help: check if the original Iterator has anything instead of collecting it and seeing if it's empty | LL ~ +LL | LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:15:43 + --> $DIR/needless_collect_indirect.rs:19:43 | LL | let indirect_contains = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_contains.contains(&&5); | ------------------------------- the iterator could be used here instead | help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:27:48 + --> $DIR/needless_collect_indirect.rs:32:48 | LL | let non_copy_contains = sample.into_iter().collect::>(); | ^^^^^^^ +LL | LL | non_copy_contains.contains(&a); | ------------------------------ the iterator could be used here instead | help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:56:51 + --> $DIR/needless_collect_indirect.rs:62:51 | LL | let buffer: Vec<&str> = string.split('/').collect(); | ^^^^^^^ +LL | LL | buffer.len() | ------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ string.split('/').count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:61:55 + --> $DIR/needless_collect_indirect.rs:68:55 | LL | let indirect_len: VecDeque<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:66:57 + --> $DIR/needless_collect_indirect.rs:74:57 | LL | let indirect_len: LinkedList<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:71:57 + --> $DIR/needless_collect_indirect.rs:80:57 | LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:131:59 + --> $DIR/needless_collect_indirect.rs:141:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -137,13 +156,14 @@ LL | y.contains(&i); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == i); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:156:59 + --> $DIR/needless_collect_indirect.rs:167:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -154,13 +174,14 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:185:63 + --> $DIR/needless_collect_indirect.rs:197:63 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -171,13 +192,14 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:221:59 + --> $DIR/needless_collect_indirect.rs:234:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -188,56 +210,59 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ -LL | let z: Vec = vec.iter().map(|k| k * k).collect(); -LL | if n < 2 { +LL | + ... LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:246:26 + --> $DIR/needless_collect_indirect.rs:260:26 | LL | let w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | for _ in 0..w.len() { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ for _ in 0..v.iter().count() { | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:268:30 + --> $DIR/needless_collect_indirect.rs:283:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | while 1 == w.len() { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ while 1 == v.iter().count() { | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:290:30 + --> $DIR/needless_collect_indirect.rs:306:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | while let Some(i) = Some(w.len()) { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ while let Some(i) = Some(v.iter().count()) { | diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 12e6c7deb9c20..c26a292c8cb57 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -28,6 +28,7 @@ fn main() { let i = 0; println!("bar {} ", i); } else { + //~^ ERROR: this `else` block is redundant continue; } @@ -43,6 +44,7 @@ fn main() { } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + //~^ ERROR: there is no need for an explicit `else` block for this `if` expression continue; } else { println!("Blabber"); @@ -56,6 +58,7 @@ fn main() { fn simple_loop() { loop { continue; + //~^ ERROR: this `continue` expression is redundant } } @@ -63,6 +66,7 @@ fn simple_loop2() { loop { println!("bleh"); continue; + //~^ ERROR: this `continue` expression is redundant } } @@ -70,6 +74,7 @@ fn simple_loop2() { fn simple_loop3() { loop { continue + //~^ ERROR: this `continue` expression is redundant } } @@ -78,6 +83,7 @@ fn simple_loop4() { loop { println!("bleh"); continue + //~^ ERROR: this `continue` expression is redundant } } @@ -128,12 +134,14 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { + //~^ ERROR: this `else` block is redundant continue 'inner; } println!("bar-4"); update_condition(); if condition() { + //~^ ERROR: there is no need for an explicit `else` block for this `if` ex continue; } else { println!("bar-5"); diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 7f9f644643f97..9a65248c9913f 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -3,6 +3,7 @@ error: this `else` block is redundant | LL | } else { | ________________^ +LL | | LL | | continue; LL | | } | |_________^ @@ -25,6 +26,7 @@ LL | | } println!("lama"); } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } else { println!("Blabber"); @@ -35,9 +37,10 @@ LL | | } = note: `-D clippy::needless-continue` implied by `-D warnings` error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:45:9 + --> $DIR/needless_continue.rs:46:9 | LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { +LL | | LL | | continue; LL | | } else { LL | | println!("Blabber"); @@ -47,6 +50,7 @@ LL | | } | = help: consider dropping the `else` clause if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } { @@ -55,7 +59,7 @@ LL | | } } error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:58:9 + --> $DIR/needless_continue.rs:60:9 | LL | continue; | ^^^^^^^^^ @@ -63,7 +67,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:65:9 + --> $DIR/needless_continue.rs:68:9 | LL | continue; | ^^^^^^^^^ @@ -71,7 +75,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:72:9 + --> $DIR/needless_continue.rs:76:9 | LL | continue | ^^^^^^^^ @@ -79,7 +83,7 @@ LL | continue = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:80:9 + --> $DIR/needless_continue.rs:85:9 | LL | continue | ^^^^^^^^ @@ -87,10 +91,11 @@ LL | continue = help: consider dropping the `continue` expression error: this `else` block is redundant - --> $DIR/needless_continue.rs:130:24 + --> $DIR/needless_continue.rs:136:24 | LL | } else { | ________________________^ +LL | | LL | | continue 'inner; LL | | } | |_________________^ @@ -102,6 +107,7 @@ LL | | } println!("bar-4"); update_condition(); if condition() { + continue; } else { println!("bar-5"); @@ -110,9 +116,10 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:136:17 + --> $DIR/needless_continue.rs:143:17 | LL | / if condition() { +LL | | LL | | continue; LL | | } else { LL | | println!("bar-5"); @@ -121,6 +128,7 @@ LL | | } | = help: consider dropping the `else` clause if condition() { + continue; } { diff --git a/tests/ui/needless_doc_main.rs b/tests/ui/needless_doc_main.rs index 83e9bbaa3af43..d31b9047eaaeb 100644 --- a/tests/ui/needless_doc_main.rs +++ b/tests/ui/needless_doc_main.rs @@ -5,27 +5,32 @@ /// This should lint /// ``` /// fn main() { +//~^ ERROR: needless `fn main` in doctest +//~| NOTE: `-D clippy::needless-doctest-main` implied by `-D warnings` /// unimplemented!(); /// } /// ``` -/// +/// /// With an explicit return type it should lint too /// ```edition2015 /// fn main() -> () { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` -/// +/// /// This should, too. /// ```rust /// fn main() { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` -/// +/// /// This one too. /// ```no_run /// fn main() { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` diff --git a/tests/ui/needless_doc_main.stderr b/tests/ui/needless_doc_main.stderr index 05c7f9d33a792..be6675e6482e0 100644 --- a/tests/ui/needless_doc_main.stderr +++ b/tests/ui/needless_doc_main.stderr @@ -7,19 +7,19 @@ LL | /// fn main() { = note: `-D clippy::needless-doctest-main` implied by `-D warnings` error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:14:4 + --> $DIR/needless_doc_main.rs:16:4 | LL | /// fn main() -> () { | ^^^^^^^^^^^^^^^^^^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:21:4 + --> $DIR/needless_doc_main.rs:24:4 | LL | /// fn main() { | ^^^^^^^^^^^^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:28:4 + --> $DIR/needless_doc_main.rs:32:4 | LL | /// fn main() { | ^^^^^^^^^^^^ diff --git a/tests/ui/needless_for_each_unfixable.rs b/tests/ui/needless_for_each_unfixable.rs index 588d7cb070c70..2220cf9e11eef 100644 --- a/tests/ui/needless_for_each_unfixable.rs +++ b/tests/ui/needless_for_each_unfixable.rs @@ -6,6 +6,8 @@ fn main() { let v: Vec = Vec::new(); // This is unfixable because the closure includes `return`. v.iter().for_each(|v| { + //~^ ERROR: needless use of `for_each` + //~| NOTE: `-D clippy::needless-for-each` implied by `-D warnings` if *v == 10 { return; } else { diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 9c7f3d47121d0..dad0053f5591b 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -2,10 +2,10 @@ error: needless use of `for_each` --> $DIR/needless_for_each_unfixable.rs:8:5 | LL | / v.iter().for_each(|v| { +LL | | +LL | | LL | | if *v == 10 { -LL | | return; -LL | | } else { -LL | | println!("{}", v); +... | LL | | } LL | | }); | |_______^ @@ -14,6 +14,8 @@ LL | | }); help: try | LL ~ for v in v.iter() { +LL + +LL + LL + if *v == 10 { LL + return; LL + } else { diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index ce4bc9286bef0..14cba5a7eb520 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -16,6 +16,8 @@ use std::mem::MaybeUninit; // `v` should be warned // `w`, `x` and `y` are allowed (moved or mutated) fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| NOTE: `-D clippy::needless-pass-by-value` implied by `-D warnings` assert_eq!(v.len(), 42); consume(w); @@ -30,12 +32,15 @@ fn consume(_: T) {} struct Wrapper(String); fn bar(x: String, y: Wrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body assert_eq!(x.len(), 42); assert_eq!(y.0.len(), 42); } // V implements `Borrow`, but should be warned correctly fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body println!("{}", t.borrow()); println!("{}", u.as_ref()); consume(&v); @@ -48,6 +53,7 @@ fn test_fn i32>(f: F) { // x should be warned, but y is ok fn test_match(x: Option>, y: Option>) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body match x { Some(Some(_)) => 1, // not moved _ => 0, @@ -61,6 +67,8 @@ fn test_match(x: Option>, y: Option>) { // x and y should be warned, but z is ok fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body let Wrapper(s) = z; // moved let Wrapper(ref t) = y; // not moved let Wrapper(_) = y; // still not moved @@ -77,8 +85,13 @@ impl<'a, T> Serialize for &'a T where T: Serialize {} impl Serialize for i32 {} fn test_blanket_ref(_foo: T, _serializable: S) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn issue_2114(s: String, t: String, u: Vec, v: Vec) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body s.capacity(); let _ = t.clone(); u.capacity(); @@ -92,7 +105,9 @@ impl S { self, // taking `self` by value is always allowed s: String, + //~^ ERROR: this argument is passed by value, but not consumed in the function bod t: String, + //~^ ERROR: this argument is passed by value, but not consumed in the function bod ) -> usize { s.len() + t.capacity() } @@ -102,6 +117,8 @@ impl S { } fn baz(&self, _u: U, _s: Self) {} + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body } trait FalsePositive { @@ -124,12 +141,16 @@ fn range>(range: T) { struct CopyWrapper(u32); fn bar_copy(x: u32, y: CopyWrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body assert_eq!(x, 42); assert_eq!(y.0, 42); } // x and y should be warned, but z is ok fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body let CopyWrapper(s) = z; // moved let CopyWrapper(ref t) = y; // not moved let CopyWrapper(_) = y; // still not moved @@ -142,11 +163,13 @@ fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { trait Bar<'a, A> {} impl<'b, T> Bar<'b, T> for T {} fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body // Also this should not cause an ICE. See #2831 trait Club<'a, A> {} impl Club<'static, T> for T {} fn more_fun(_item: impl Club<'static, i32>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn is_sync(_: T) where diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 0e660a77dc0cc..a6bf30b1cdfb4 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -7,55 +7,55 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec $DIR/needless_pass_by_value.rs:32:11 + --> $DIR/needless_pass_by_value.rs:34:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:32:22 + --> $DIR/needless_pass_by_value.rs:34:22 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:38:71 + --> $DIR/needless_pass_by_value.rs:42:71 | LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { | ^ help: consider taking a reference instead: `&V` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:50:18 + --> $DIR/needless_pass_by_value.rs:55:18 | LL | fn test_match(x: Option>, y: Option>) { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option>` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:24 + --> $DIR/needless_pass_by_value.rs:69:24 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:36 + --> $DIR/needless_pass_by_value.rs:69:36 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:79:49 + --> $DIR/needless_pass_by_value.rs:87:49 | LL | fn test_blanket_ref(_foo: T, _serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:18 + --> $DIR/needless_pass_by_value.rs:90:18 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:29 + --> $DIR/needless_pass_by_value.rs:90:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -70,13 +70,13 @@ LL | let _ = t.to_string(); | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:40 + --> $DIR/needless_pass_by_value.rs:90:40 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ help: consider taking a reference instead: `&Vec` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:53 + --> $DIR/needless_pass_by_value.rs:90:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -91,85 +91,85 @@ LL | let _ = v.to_owned(); | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:94:12 + --> $DIR/needless_pass_by_value.rs:107:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:95:12 + --> $DIR/needless_pass_by_value.rs:109:12 | LL | t: String, | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:23 + --> $DIR/needless_pass_by_value.rs:119:23 | LL | fn baz(&self, _u: U, _s: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:30 + --> $DIR/needless_pass_by_value.rs:119:30 | LL | fn baz(&self, _u: U, _s: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:126:24 + --> $DIR/needless_pass_by_value.rs:143:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:29 + --> $DIR/needless_pass_by_value.rs:150:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:45 + --> $DIR/needless_pass_by_value.rs:150:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:61 + --> $DIR/needless_pass_by_value.rs:150:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:144:40 + --> $DIR/needless_pass_by_value.rs:165:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:149:20 + --> $DIR/needless_pass_by_value.rs:171:20 | LL | fn more_fun(_item: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index 7457a93c5f559..3f2421953301e 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -13,6 +13,8 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let vec2 = vec![1, 2, 3, 4]; for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", vec[i]); } @@ -22,19 +24,23 @@ fn main() { } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` let _ = vec[i]; } // ICE #746 for j in 0..4 { + //~^ ERROR: the loop variable `j` is only used to index `STATIC` println!("{:?}", STATIC[j]); } for j in 0..4 { + //~^ ERROR: the loop variable `j` is only used to index `CONST` println!("{:?}", CONST[j]); } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } for i in 0..vec.len() { @@ -43,39 +49,48 @@ fn main() { } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec2` println!("{}", vec2[i]); } for i in 5..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 0..MAX_LEN { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 0..=MAX_LEN { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..10 { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..=10 { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } for i in 5..10 { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } // #2542 for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` vec[i] = Some(1).unwrap_or_else(|| panic!("error on {}", i)); } diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index 8ca6b880ceae7..0358b2fb0251a 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -11,7 +11,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:24:14 + --> $DIR/needless_range_loop.rs:26:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` - --> $DIR/needless_range_loop.rs:29:14 + --> $DIR/needless_range_loop.rs:32:14 | LL | for j in 0..4 { | ^^^^ @@ -33,7 +33,7 @@ LL | for in &STATIC { | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` - --> $DIR/needless_range_loop.rs:33:14 + --> $DIR/needless_range_loop.rs:37:14 | LL | for j in 0..4 { | ^^^^ @@ -44,7 +44,7 @@ LL | for in &CONST { | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:37:14 + --> $DIR/needless_range_loop.rs:42:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | for (i, ) in vec.iter().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` - --> $DIR/needless_range_loop.rs:45:14 + --> $DIR/needless_range_loop.rs:51:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | for in vec2.iter().take(vec.len()) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:49:14 + --> $DIR/needless_range_loop.rs:56:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | for in vec.iter().skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:53:14 + --> $DIR/needless_range_loop.rs:61:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | for in vec.iter().take(MAX_LEN) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:57:14 + --> $DIR/needless_range_loop.rs:66:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | for in vec.iter().take(MAX_LEN + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:61:14 + --> $DIR/needless_range_loop.rs:71:14 | LL | for i in 5..10 { | ^^^^^ @@ -110,7 +110,7 @@ LL | for in vec.iter().take(10).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:65:14 + --> $DIR/needless_range_loop.rs:76:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -121,7 +121,7 @@ LL | for in vec.iter().take(10 + 1).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:69:14 + --> $DIR/needless_range_loop.rs:81:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | for (i, ) in vec.iter().enumerate().skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:73:14 + --> $DIR/needless_range_loop.rs:86:14 | LL | for i in 5..10 { | ^^^^^ @@ -143,7 +143,7 @@ LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:78:14 + --> $DIR/needless_range_loop.rs:92:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ diff --git a/tests/ui/needless_range_loop2.rs b/tests/ui/needless_range_loop2.rs index 66cd15401f922..787ff18f338d2 100644 --- a/tests/ui/needless_range_loop2.rs +++ b/tests/ui/needless_range_loop2.rs @@ -9,6 +9,8 @@ fn main() { let ns = vec![2, 3, 5, 7]; for i in 3..10 { + //~^ ERROR: the loop variable `i` is only used to index `ns` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", ns[i]); } @@ -30,12 +32,14 @@ fn main() { let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` ms[i] *= 2; } assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]); let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` let x = &mut ms[i]; *x *= 2; } @@ -60,6 +64,7 @@ fn main() { let mut vec = vec![0; 9]; for i in x..x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } @@ -67,20 +72,24 @@ fn main() { let mut vec = vec![0; 10]; for i in x..=x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } let arr = [1, 2, 3]; for i in 0..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 0..2 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 1..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 8c4f5d954a975..6e6ef73c1f6e8 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -11,7 +11,7 @@ LL | for in ns.iter().take(10).skip(3) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> $DIR/needless_range_loop2.rs:32:14 + --> $DIR/needless_range_loop2.rs:34:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> $DIR/needless_range_loop2.rs:38:14 + --> $DIR/needless_range_loop2.rs:41:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop2.rs:62:14 + --> $DIR/needless_range_loop2.rs:66:14 | LL | for i in x..x + 4 { | ^^^^^^^^ @@ -44,7 +44,7 @@ LL | for in vec.iter_mut().skip(x).take(4) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop2.rs:69:14 + --> $DIR/needless_range_loop2.rs:74:14 | LL | for i in x..=x + 4 { | ^^^^^^^^^ @@ -55,7 +55,7 @@ LL | for in vec.iter_mut().skip(x).take(4 + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:75:14 + --> $DIR/needless_range_loop2.rs:81:14 | LL | for i in 0..3 { | ^^^^ @@ -66,7 +66,7 @@ LL | for in &arr { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:79:14 + --> $DIR/needless_range_loop2.rs:86:14 | LL | for i in 0..2 { | ^^^^ @@ -77,7 +77,7 @@ LL | for in arr.iter().take(2) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:83:14 + --> $DIR/needless_range_loop2.rs:91:14 | LL | for i in 1..3 { | ^^^^ diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 4e8517cad1006..7c59abf07aba9 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -17,6 +17,8 @@ fn main() { S { ..base }; // no error S { a: 1, ..base }; // no error S { a: 1, b: 1, ..base }; + //~^ ERROR: struct update has no effect, all the fields in the struct have already bee + //~| NOTE: `-D clippy::needless-update` implied by `-D warnings` let base = T { x: 0, y: 0 }; T { ..base }; // no error diff --git a/tests/ui/neg_cmp_op_on_partial_ord.rs b/tests/ui/neg_cmp_op_on_partial_ord.rs index 2d392c593b3e7..c79fd26652601 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -14,15 +14,20 @@ fn main() { // Not Less but potentially Greater, Equal or Uncomparable. let _not_less = !(a_value < another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce + //~| NOTE: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` // Not Less or Equal but potentially Greater or Uncomparable. let _not_less_or_equal = !(a_value <= another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // Not Greater but potentially Less, Equal or Uncomparable. let _not_greater = !(a_value > another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // Not Greater or Equal but potentially Less or Uncomparable. let _not_greater_or_equal = !(a_value >= another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // --- Good --- diff --git a/tests/ui/neg_cmp_op_on_partial_ord.stderr b/tests/ui/neg_cmp_op_on_partial_ord.stderr index c78560007217d..c2e1f8702ddeb 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ b/tests/ui/neg_cmp_op_on_partial_ord.stderr @@ -7,19 +7,19 @@ LL | let _not_less = !(a_value < another_value); = note: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:19:30 + --> $DIR/neg_cmp_op_on_partial_ord.rs:21:30 | LL | let _not_less_or_equal = !(a_value <= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:22:24 + --> $DIR/neg_cmp_op_on_partial_ord.rs:25:24 | LL | let _not_greater = !(a_value > another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:25:33 + --> $DIR/neg_cmp_op_on_partial_ord.rs:29:33 | LL | let _not_greater_or_equal = !(a_value >= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs index 22ff1c35b30f9..001b94391ca81 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -10,6 +10,8 @@ fn test1() { let mut x = 0; loop { + //~^ ERROR: this loop never actually loops + //~| NOTE: `#[deny(clippy::never_loop)]` on by default // clippy::never_loop x += 1; if x == 1 { @@ -32,6 +34,7 @@ fn test2() { fn test3() { let mut x = 0; loop { + //~^ ERROR: this loop never actually loops // never loops x += 1; break; @@ -52,8 +55,10 @@ fn test4() { fn test5() { let i = 0; loop { + //~^ ERROR: this loop never actually loops // never loops while i == 0 { + //~^ ERROR: this loop never actually loops // never loops break; } @@ -66,6 +71,7 @@ fn test6() { 'outer: loop { x += 1; loop { + //~^ ERROR: this loop never actually loops // never loops if x == 5 { break; @@ -102,6 +108,7 @@ fn test8() { fn test9() { let x = Some(1); while let Some(y) = x { + //~^ ERROR: this loop never actually loops // never loops return; } @@ -109,6 +116,7 @@ fn test9() { fn test10() { for x in 0..10 { + //~^ ERROR: this loop never actually loops // never loops match x { 1 => break, @@ -157,6 +165,7 @@ pub fn test13() { pub fn test14() { let mut a = true; 'outer: while a { + //~^ ERROR: this loop never actually loops // never loops while a { if a { @@ -172,6 +181,7 @@ pub fn test14() { pub fn test15() { 'label: loop { while false { + //~^ ERROR: this loop never actually loops break 'label; } } @@ -223,6 +233,7 @@ pub fn test18() { }; // never loops let _ = loop { + //~^ ERROR: this loop never actually loops let Some(x) = x else { return; }; @@ -244,9 +255,12 @@ pub fn test19() { pub fn test20() { 'a: loop { + //~^ ERROR: this loop never actually loops 'b: { break 'b 'c: { break 'a; + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` }; } } @@ -278,6 +292,7 @@ pub fn test23() { for _ in 0..10 { 'block: { for _ in 0..20 { + //~^ ERROR: this loop never actually loops break 'block; } } @@ -322,6 +337,7 @@ pub fn test26() { pub fn test27() { loop { + //~^ ERROR: this loop never actually loops 'label: { let x = true; // Lints because we cannot prove it's always `true` diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 0446c09cd5bcc..6d6d2c8ac52e0 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -2,9 +2,9 @@ error: this loop never actually loops --> $DIR/never_loop.rs:12:5 | LL | / loop { +LL | | +LL | | LL | | // clippy::never_loop -LL | | x += 1; -LL | | if x == 1 { ... | LL | | break; LL | | } @@ -13,9 +13,10 @@ LL | | } = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops - --> $DIR/never_loop.rs:34:5 + --> $DIR/never_loop.rs:36:5 | LL | / loop { +LL | | LL | | // never loops LL | | x += 1; LL | | break; @@ -23,55 +24,57 @@ LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:54:5 + --> $DIR/never_loop.rs:57:5 | LL | / loop { +LL | | LL | | // never loops LL | | while i == 0 { -LL | | // never loops ... | LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:56:9 + --> $DIR/never_loop.rs:60:9 | LL | / while i == 0 { +LL | | LL | | // never loops LL | | break; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:68:9 + --> $DIR/never_loop.rs:73:9 | LL | / loop { +LL | | LL | | // never loops LL | | if x == 5 { -LL | | break; -LL | | } +... | LL | | continue 'outer; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:104:5 + --> $DIR/never_loop.rs:110:5 | LL | / while let Some(y) = x { +LL | | LL | | // never loops LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:111:5 + --> $DIR/never_loop.rs:118:5 | LL | / for x in 0..10 { +LL | | LL | | // never loops LL | | match x { -LL | | 1 => break, -LL | | _ => return, +... | LL | | } LL | | } | |_____^ @@ -82,52 +85,53 @@ LL | if let Some(x) = (0..10).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> $DIR/never_loop.rs:159:5 + --> $DIR/never_loop.rs:167:5 | LL | / 'outer: while a { +LL | | LL | | // never loops LL | | while a { -LL | | if a { ... | LL | | break 'outer; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:174:9 + --> $DIR/never_loop.rs:183:9 | LL | / while false { +LL | | LL | | break 'label; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:225:13 + --> $DIR/never_loop.rs:235:13 | LL | let _ = loop { | _____________^ +LL | | LL | | let Some(x) = x else { LL | | return; -LL | | }; -LL | | +... | LL | | break x; LL | | }; | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:246:5 + --> $DIR/never_loop.rs:257:5 | LL | / 'a: loop { +LL | | LL | | 'b: { LL | | break 'b 'c: { -LL | | break 'a; -LL | | }; +... | LL | | } LL | | } | |_____^ error: sub-expression diverges - --> $DIR/never_loop.rs:249:17 + --> $DIR/never_loop.rs:261:17 | LL | break 'a; | ^^^^^^^^ @@ -135,9 +139,10 @@ LL | break 'a; = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` error: this loop never actually loops - --> $DIR/never_loop.rs:280:13 + --> $DIR/never_loop.rs:294:13 | LL | / for _ in 0..20 { +LL | | LL | | break 'block; LL | | } | |_____________^ @@ -148,12 +153,12 @@ LL | if let Some(_) = (0..20).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> $DIR/never_loop.rs:324:5 + --> $DIR/never_loop.rs:339:5 | LL | / loop { +LL | | LL | | 'label: { LL | | let x = true; -LL | | // Lints because we cannot prove it's always `true` ... | LL | | } LL | | } diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index 4eff62b85ff68..b944f531ef660 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -48,6 +48,8 @@ impl R for S3 { impl S3 { // should trigger the lint pub fn new(_: String) -> impl R { + //~^ ERROR: methods called `new` usually return `Self` + //~| NOTE: `-D clippy::new-ret-no-self` implied by `-D warnings` S3 } } @@ -80,6 +82,7 @@ struct U; impl U { // should trigger lint pub fn new() -> u32 { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -89,6 +92,7 @@ struct V; impl V { // should trigger lint pub fn new(_: String) -> u32 { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -125,6 +129,7 @@ struct TupleReturnerBad; impl TupleReturnerBad { // should trigger lint pub fn new() -> (u32, u32) { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -152,6 +157,7 @@ struct MutPointerReturnerBad; impl MutPointerReturnerBad { // should trigger lint pub fn new() -> *mut V { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -170,6 +176,7 @@ struct GenericReturnerBad; impl GenericReturnerBad { // should trigger lint pub fn new() -> Option { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -223,6 +230,7 @@ mod issue5435 { pub trait TraitRet { // should trigger lint as we are in trait definition fn new() -> String; + //~^ ERROR: methods called `new` usually return `Self` } pub struct StructRet; impl TraitRet for StructRet { @@ -235,6 +243,7 @@ mod issue5435 { pub trait TraitRet2 { // should trigger lint fn new(_: String) -> String; + //~^ ERROR: methods called `new` usually return `Self` } trait TupleReturnerOk { @@ -270,6 +279,7 @@ mod issue5435 { trait TupleReturnerBad { // should trigger lint fn new() -> (u32, u32) { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -297,6 +307,7 @@ mod issue5435 { trait MutPointerReturnerBad { // should trigger lint fn new() -> *mut V { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -367,6 +378,7 @@ mod issue7344 { impl RetImplTraitNoSelf { // should trigger lint fn new(t: T) -> impl Into { + //~^ ERROR: methods called `new` usually return `Self` 1 } } @@ -388,6 +400,7 @@ mod issue7344 { impl RetImplTraitNoSelf2 { // should trigger lint fn new(t: T) -> impl Trait2<(), i32> { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!() } } diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 2b053b462b164..4c76603f596d8 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -2,6 +2,8 @@ error: methods called `new` usually return `Self` --> $DIR/new_ret_no_self.rs:50:5 | LL | / pub fn new(_: String) -> impl R { +LL | | +LL | | LL | | S3 LL | | } | |_____^ @@ -9,85 +11,94 @@ LL | | } = note: `-D clippy::new-ret-no-self` implied by `-D warnings` error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:82:5 + --> $DIR/new_ret_no_self.rs:84:5 | LL | / pub fn new() -> u32 { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:91:5 + --> $DIR/new_ret_no_self.rs:94:5 | LL | / pub fn new(_: String) -> u32 { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:127:5 + --> $DIR/new_ret_no_self.rs:131:5 | LL | / pub fn new() -> (u32, u32) { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:154:5 + --> $DIR/new_ret_no_self.rs:159:5 | LL | / pub fn new() -> *mut V { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:172:5 + --> $DIR/new_ret_no_self.rs:178:5 | LL | / pub fn new() -> Option { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:225:9 + --> $DIR/new_ret_no_self.rs:232:9 | LL | fn new() -> String; | ^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:237:9 + --> $DIR/new_ret_no_self.rs:245:9 | LL | fn new(_: String) -> String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:272:9 + --> $DIR/new_ret_no_self.rs:281:9 | LL | / fn new() -> (u32, u32) { +LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:299:9 + --> $DIR/new_ret_no_self.rs:309:9 | LL | / fn new() -> *mut V { +LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:369:9 + --> $DIR/new_ret_no_self.rs:380:9 | LL | / fn new(t: T) -> impl Into { +LL | | LL | | 1 LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:390:9 + --> $DIR/new_ret_no_self.rs:402:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { +LL | | LL | | unimplemented!() LL | | } | |_________^ diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 56359a4cbc3cf..1c7ba1a48c90d 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -16,6 +16,8 @@ impl Default for Foo { impl Foo { pub fn new() -> Foo { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~| NOTE: `-D clippy::new-without-default` implied by `-D warnings` Foo } } @@ -30,6 +32,7 @@ impl Default for Bar { impl Bar { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Bar` Bar } } @@ -100,6 +103,7 @@ impl<'c> Default for LtKo<'c> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { + //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` unimplemented!() } } @@ -198,6 +202,7 @@ impl Default for NewNotEqualToDerive { impl NewNotEqualToDerive { // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `NewNotEqualToDe NewNotEqualToDerive { foo: 1 } } } @@ -212,6 +217,7 @@ impl Default for FooGenerics { impl FooGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` Self(Default::default()) } } @@ -225,6 +231,7 @@ impl Default for BarGenerics { impl BarGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` Self(Default::default()) } } @@ -242,6 +249,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` todo!() } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index bbd7a51d6b984..964aa0f63da8e 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -10,6 +10,8 @@ pub struct Foo; impl Foo { pub fn new() -> Foo { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~| NOTE: `-D clippy::new-without-default` implied by `-D warnings` Foo } } @@ -18,6 +20,7 @@ pub struct Bar; impl Bar { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Bar` Bar } } @@ -82,6 +85,7 @@ pub struct LtKo<'a> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { + //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` unimplemented!() } } @@ -174,6 +178,7 @@ pub struct NewNotEqualToDerive { impl NewNotEqualToDerive { // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `NewNotEqualToDe NewNotEqualToDerive { foo: 1 } } } @@ -182,6 +187,7 @@ impl NewNotEqualToDerive { pub struct FooGenerics(std::marker::PhantomData); impl FooGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` Self(Default::default()) } } @@ -189,6 +195,7 @@ impl FooGenerics { pub struct BarGenerics(std::marker::PhantomData); impl BarGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` Self(Default::default()) } } @@ -200,6 +207,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` todo!() } } diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 61973abcde88c..4293cd5972df7 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -2,6 +2,8 @@ error: you should consider adding a `Default` implementation for `Foo` --> $DIR/new_without_default.rs:12:5 | LL | / pub fn new() -> Foo { +LL | | +LL | | LL | | Foo LL | | } | |_____^ @@ -17,9 +19,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> $DIR/new_without_default.rs:20:5 + --> $DIR/new_without_default.rs:22:5 | LL | / pub fn new() -> Self { +LL | | LL | | Bar LL | | } | |_____^ @@ -34,9 +37,10 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> $DIR/new_without_default.rs:84:5 + --> $DIR/new_without_default.rs:87:5 | LL | / pub fn new() -> LtKo<'c> { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -51,9 +55,10 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:176:5 + --> $DIR/new_without_default.rs:180:5 | LL | / pub fn new() -> Self { +LL | | LL | | NewNotEqualToDerive { foo: 1 } LL | | } | |_____^ @@ -68,9 +73,10 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> $DIR/new_without_default.rs:184:5 + --> $DIR/new_without_default.rs:189:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -85,9 +91,10 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> $DIR/new_without_default.rs:191:5 + --> $DIR/new_without_default.rs:197:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -102,9 +109,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:202:9 + --> $DIR/new_without_default.rs:209:9 | LL | / pub fn new() -> Self { +LL | | LL | | todo!() LL | | } | |_________^ @@ -121,7 +129,7 @@ LL ~ impl Foo { | error: you should consider adding a `Default` implementation for `MyStruct` - --> $DIR/new_without_default.rs:247:5 + --> $DIR/new_without_default.rs:255:5 | LL | / pub fn new() -> Self { LL | | Self { _kv: None } diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 6a726941be893..c52f4389192fd 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -96,36 +96,67 @@ fn main() { let s2 = get_struct(); 0; + //~^ ERROR: statement with no effect + //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` s2; + //~^ ERROR: statement with no effect Unit; + //~^ ERROR: statement with no effect Tuple(0); + //~^ ERROR: statement with no effect Struct { field: 0 }; + //~^ ERROR: statement with no effect Struct { ..s }; + //~^ ERROR: statement with no effect Union { a: 0 }; + //~^ ERROR: statement with no effect Enum::Tuple(0); + //~^ ERROR: statement with no effect Enum::Struct { field: 0 }; + //~^ ERROR: statement with no effect 5 + 6; + //~^ ERROR: statement with no effect *&42; + //~^ ERROR: statement with no effect &6; + //~^ ERROR: statement with no effect (5, 6, 7); + //~^ ERROR: statement with no effect ..; + //~^ ERROR: statement with no effect 5..; + //~^ ERROR: statement with no effect ..5; + //~^ ERROR: statement with no effect 5..6; + //~^ ERROR: statement with no effect 5..=6; + //~^ ERROR: statement with no effect [42, 55]; + //~^ ERROR: statement with no effect [42, 55][1]; + //~^ ERROR: statement with no effect (42, 55).1; + //~^ ERROR: statement with no effect [42; 55]; + //~^ ERROR: statement with no effect [42; 55][13]; + //~^ ERROR: statement with no effect let mut x = 0; || x += 5; + //~^ ERROR: statement with no effect let s: String = "foo".into(); FooString { s: s }; + //~^ ERROR: statement with no effect let _unused = 1; + //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~| NOTE: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` let _penguin = || println!("Some helpful closure"); + //~^ ERROR: binding to `_` prefixed variable with no side-effect let _duck = Struct { field: 0 }; + //~^ ERROR: binding to `_` prefixed variable with no side-effect let _cat = [2, 4, 6, 8][2]; + //~^ ERROR: binding to `_` prefixed variable with no side-effect #[allow(clippy::no_effect)] 0; diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 64edfc32504e5..4b8499a23a5de 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -7,151 +7,151 @@ LL | 0; = note: `-D clippy::no-effect` implied by `-D warnings` error: statement with no effect - --> $DIR/no_effect.rs:99:5 + --> $DIR/no_effect.rs:101:5 | LL | s2; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:100:5 + --> $DIR/no_effect.rs:103:5 | LL | Unit; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:101:5 + --> $DIR/no_effect.rs:105:5 | LL | Tuple(0); | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:102:5 + --> $DIR/no_effect.rs:107:5 | LL | Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:103:5 + --> $DIR/no_effect.rs:109:5 | LL | Struct { ..s }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:104:5 + --> $DIR/no_effect.rs:111:5 | LL | Union { a: 0 }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:105:5 + --> $DIR/no_effect.rs:113:5 | LL | Enum::Tuple(0); | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:106:5 + --> $DIR/no_effect.rs:115:5 | LL | Enum::Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:107:5 + --> $DIR/no_effect.rs:117:5 | LL | 5 + 6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:108:5 + --> $DIR/no_effect.rs:119:5 | LL | *&42; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:109:5 + --> $DIR/no_effect.rs:121:5 | LL | &6; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:110:5 + --> $DIR/no_effect.rs:123:5 | LL | (5, 6, 7); | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:111:5 + --> $DIR/no_effect.rs:125:5 | LL | ..; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:112:5 + --> $DIR/no_effect.rs:127:5 | LL | 5..; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:113:5 + --> $DIR/no_effect.rs:129:5 | LL | ..5; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:114:5 + --> $DIR/no_effect.rs:131:5 | LL | 5..6; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:115:5 + --> $DIR/no_effect.rs:133:5 | LL | 5..=6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:116:5 + --> $DIR/no_effect.rs:135:5 | LL | [42, 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:117:5 + --> $DIR/no_effect.rs:137:5 | LL | [42, 55][1]; | ^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:118:5 + --> $DIR/no_effect.rs:139:5 | LL | (42, 55).1; | ^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:119:5 + --> $DIR/no_effect.rs:141:5 | LL | [42; 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:120:5 + --> $DIR/no_effect.rs:143:5 | LL | [42; 55][13]; | ^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:122:5 + --> $DIR/no_effect.rs:146:5 | LL | || x += 5; | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:124:5 + --> $DIR/no_effect.rs:149:5 | LL | FooString { s: s }; | ^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:125:5 + --> $DIR/no_effect.rs:151:5 | LL | let _unused = 1; | ^^^^^^^^^^^^^^^^ @@ -159,19 +159,19 @@ LL | let _unused = 1; = note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:126:5 + --> $DIR/no_effect.rs:154:5 | LL | let _penguin = || println!("Some helpful closure"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:127:5 + --> $DIR/no_effect.rs:156:5 | LL | let _duck = Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:128:5 + --> $DIR/no_effect.rs:158:5 | LL | let _cat = [2, 4, 6, 8][2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_effect_replace.rs b/tests/ui/no_effect_replace.rs index ad17d53f78906..e4fd5caae2a5d 100644 --- a/tests/ui/no_effect_replace.rs +++ b/tests/ui/no_effect_replace.rs @@ -2,21 +2,30 @@ fn main() { let _ = "12345".replace('1', "1"); + //~^ ERROR: replacing text with itself + //~| NOTE: `-D clippy::no-effect-replace` implied by `-D warnings` let _ = "12345".replace("12", "12"); + //~^ ERROR: replacing text with itself let _ = String::new().replace("12", "12"); + //~^ ERROR: replacing text with itself let _ = "12345".replacen('1', "1", 1); + //~^ ERROR: replacing text with itself let _ = "12345".replacen("12", "12", 1); + //~^ ERROR: replacing text with itself let _ = String::new().replacen("12", "12", 1); + //~^ ERROR: replacing text with itself let _ = "12345".replace("12", "22"); let _ = "12345".replacen("12", "22", 1); let mut x = X::default(); let _ = "hello".replace(&x.f(), &x.f()); + //~^ ERROR: replacing text with itself let _ = "hello".replace(&x.f(), &x.ff()); let _ = "hello".replace(&y(), &y()); + //~^ ERROR: replacing text with itself let _ = "hello".replace(&y(), &z()); let _ = Replaceme.replace("a", "a"); diff --git a/tests/ui/no_effect_replace.stderr b/tests/ui/no_effect_replace.stderr index 53a28aa73b707..685b20b75d41d 100644 --- a/tests/ui/no_effect_replace.stderr +++ b/tests/ui/no_effect_replace.stderr @@ -7,43 +7,43 @@ LL | let _ = "12345".replace('1', "1"); = note: `-D clippy::no-effect-replace` implied by `-D warnings` error: replacing text with itself - --> $DIR/no_effect_replace.rs:5:13 + --> $DIR/no_effect_replace.rs:7:13 | LL | let _ = "12345".replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:6:13 + --> $DIR/no_effect_replace.rs:9:13 | LL | let _ = String::new().replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:8:13 + --> $DIR/no_effect_replace.rs:12:13 | LL | let _ = "12345".replacen('1', "1", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:9:13 + --> $DIR/no_effect_replace.rs:14:13 | LL | let _ = "12345".replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:10:13 + --> $DIR/no_effect_replace.rs:16:13 | LL | let _ = String::new().replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:16:13 + --> $DIR/no_effect_replace.rs:23:13 | LL | let _ = "hello".replace(&x.f(), &x.f()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:19:13 + --> $DIR/no_effect_replace.rs:27:13 | LL | let _ = "hello".replace(&y(), &y()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_effect_return.rs b/tests/ui/no_effect_return.rs index 186d42134fd36..f6585aa30a6f0 100644 --- a/tests/ui/no_effect_return.rs +++ b/tests/ui/no_effect_return.rs @@ -7,6 +7,8 @@ use std::ops::ControlFlow; fn a() -> u32 { { 0u32; + //~^ ERROR: statement with no effect + //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` } 0 } @@ -14,6 +16,7 @@ fn a() -> u32 { async fn b() -> u32 { { 0u32; + //~^ ERROR: statement with no effect } 0 } @@ -22,6 +25,7 @@ type C = i32; async fn c() -> C { { 0i32 as C; + //~^ ERROR: statement with no effect } 0 } @@ -30,6 +34,7 @@ fn d() -> u128 { { // not last stmt 0u128; + //~^ ERROR: statement with no effect println!("lol"); } 0 @@ -39,6 +44,7 @@ fn e() -> u32 { { // mismatched types 0u16; + //~^ ERROR: statement with no effect } 0 } @@ -46,6 +52,7 @@ fn e() -> u32 { fn f() -> [u16; 1] { { [1u16]; + //~^ ERROR: statement with no effect } [1] } @@ -53,6 +60,7 @@ fn f() -> [u16; 1] { fn g() -> ControlFlow<()> { { ControlFlow::Break::<()>(()); + //~^ ERROR: statement with no effect } ControlFlow::Continue(()) } @@ -69,6 +77,7 @@ fn h() -> Vec { fn i() -> () { { (); + //~^ ERROR: statement with no effect } () } @@ -77,6 +86,7 @@ fn j() { { // does not suggest on function without explicit return type (); + //~^ ERROR: statement with no effect } () } diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index 2b55bcb881eec..6b146a03abc11 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -9,7 +9,7 @@ LL | 0u32; = note: `-D clippy::no-effect` implied by `-D warnings` error: statement with no effect - --> $DIR/no_effect_return.rs:16:9 + --> $DIR/no_effect_return.rs:18:9 | LL | 0u32; | -^^^^ @@ -17,7 +17,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:24:9 + --> $DIR/no_effect_return.rs:27:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -25,19 +25,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:32:9 + --> $DIR/no_effect_return.rs:36:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:41:9 + --> $DIR/no_effect_return.rs:46:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:48:9 + --> $DIR/no_effect_return.rs:54:9 | LL | [1u16]; | -^^^^^^ @@ -45,7 +45,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:55:9 + --> $DIR/no_effect_return.rs:62:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:71:9 + --> $DIR/no_effect_return.rs:79:9 | LL | (); | -^^ @@ -61,7 +61,7 @@ LL | (); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:79:9 + --> $DIR/no_effect_return.rs:88:9 | LL | (); | ^^^ diff --git a/tests/ui/no_mangle_with_rust_abi.rs b/tests/ui/no_mangle_with_rust_abi.rs index 7ae9468230403..8c1ea81d2ac9a 100644 --- a/tests/ui/no_mangle_with_rust_abi.rs +++ b/tests/ui/no_mangle_with_rust_abi.rs @@ -4,22 +4,28 @@ #[no_mangle] fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI +//~| NOTE: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` #[no_mangle] pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI /// # Safety /// This function shouldn't be called unless the horsemen are ready #[no_mangle] pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI /// # Safety /// This function shouldn't be called unless the horsemen are ready #[no_mangle] unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI #[no_mangle] fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( + //~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI arg_one: u32, arg_two: usize, ) -> u32 { diff --git a/tests/ui/no_mangle_with_rust_abi.stderr b/tests/ui/no_mangle_with_rust_abi.stderr index 9f5fc90dc12ba..721dcf603b1fd 100644 --- a/tests/ui/no_mangle_with_rust_abi.stderr +++ b/tests/ui/no_mangle_with_rust_abi.stderr @@ -15,7 +15,7 @@ LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:9:1 + --> $DIR/no_mangle_with_rust_abi.rs:11:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:14:1 + --> $DIR/no_mangle_with_rust_abi.rs:17:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:19:1 + --> $DIR/no_mangle_with_rust_abi.rs:23:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,9 +60,10 @@ LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:22:1 + --> $DIR/no_mangle_with_rust_abi.rs:27:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( +LL | | LL | | arg_one: u32, LL | | arg_two: usize, LL | | ) -> u32 { diff --git a/tests/ui/non_minimal_cfg2.rs b/tests/ui/non_minimal_cfg2.rs index a4c6abce38764..f9e3ba4dacdad 100644 --- a/tests/ui/non_minimal_cfg2.rs +++ b/tests/ui/non_minimal_cfg2.rs @@ -1,6 +1,8 @@ #![allow(unused)] #[cfg(all())] +//~^ ERROR: unneeded sub `cfg` when there is no condition +//~| NOTE: `-D clippy::non-minimal-cfg` implied by `-D warnings` fn all() {} fn main() {} diff --git a/tests/ui/non_send_fields_in_send_ty.rs b/tests/ui/non_send_fields_in_send_ty.rs index 514fb25c8cfd8..c6855a0969681 100644 --- a/tests/ui/non_send_fields_in_send_ty.rs +++ b/tests/ui/non_send_fields_in_send_ty.rs @@ -15,6 +15,7 @@ pub struct RingBuffer { } unsafe impl Send for RingBuffer {} +//~^ ERROR: some fields in `RingBuffer` are not safe to be sent to another thread // noise_search / RUSTSEC-2020-0141 pub struct MvccRwLock { @@ -23,6 +24,7 @@ pub struct MvccRwLock { } unsafe impl Send for MvccRwLock {} +//~^ ERROR: some fields in `MvccRwLock` are not safe to be sent to another thread // async-coap / RUSTSEC-2020-0124 pub struct ArcGuard { @@ -31,6 +33,7 @@ pub struct ArcGuard { } unsafe impl Send for ArcGuard {} +//~^ ERROR: some fields in `ArcGuard` are not safe to be sent to another thread // rusb / RUSTSEC-2020-0098 extern "C" { @@ -47,6 +50,7 @@ pub struct DeviceHandle { } unsafe impl Send for DeviceHandle {} +//~^ ERROR: some fields in `DeviceHandle` are not safe to be sent to another thread // Other basic tests pub struct NoGeneric { @@ -54,6 +58,7 @@ pub struct NoGeneric { } unsafe impl Send for NoGeneric {} +//~^ ERROR: some fields in `NoGeneric` are not safe to be sent to another thread pub struct MultiField { field1: T, @@ -62,6 +67,7 @@ pub struct MultiField { } unsafe impl Send for MultiField {} +//~^ ERROR: some fields in `MultiField` are not safe to be sent to another thread pub enum MyOption { MySome(T), @@ -69,6 +75,7 @@ pub enum MyOption { } unsafe impl Send for MyOption {} +//~^ ERROR: some fields in `MyOption` are not safe to be sent to another thread // Test types that contain `NonNull` instead of raw pointers (#8045) pub struct WrappedNonNull(UnsafeCell>); @@ -81,6 +88,7 @@ pub struct MultiParam { } unsafe impl Send for MultiParam {} +//~^ ERROR: some fields in `MultiParam` are not safe to be sent to another thread // Tests for raw pointer heuristic extern "C" { @@ -99,6 +107,7 @@ pub struct HeuristicTest { } unsafe impl Send for HeuristicTest {} +//~^ ERROR: some fields in `HeuristicTest` are not safe to be sent to another thread // Test attributes #[allow(clippy::non_send_fields_in_send_ty)] @@ -118,6 +127,7 @@ pub enum AttrTest3 { unsafe impl Send for AttrTest1 {} unsafe impl Send for AttrTest2 {} unsafe impl Send for AttrTest3 {} +//~^ ERROR: some fields in `AttrTest3` are not safe to be sent to another thread // Multiple non-overlapping `Send` for a single type pub struct Complex { @@ -126,8 +136,10 @@ pub struct Complex { } unsafe impl

Send for Complex {} +//~^ ERROR: some fields in `Complex` are not safe to be sent to another thread // `MutexGuard` is non-Send unsafe impl Send for Complex> {} +//~^ ERROR: some fields in `Complex>` are not safe to be sent fn main() {} diff --git a/tests/ui/non_send_fields_in_send_ty.stderr b/tests/ui/non_send_fields_in_send_ty.stderr index e912b59a6e7b0..08a53b3a891cf 100644 --- a/tests/ui/non_send_fields_in_send_ty.stderr +++ b/tests/ui/non_send_fields_in_send_ty.stderr @@ -13,155 +13,155 @@ LL | data: Vec>, = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` error: some fields in `MvccRwLock` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:25:1 + --> $DIR/non_send_fields_in_send_ty.rs:26:1 | LL | unsafe impl Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:22:5 + --> $DIR/non_send_fields_in_send_ty.rs:23:5 | LL | lock: Mutex>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:33:1 + --> $DIR/non_send_fields_in_send_ty.rs:35:1 | LL | unsafe impl Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:30:5 + --> $DIR/non_send_fields_in_send_ty.rs:32:5 | LL | head: Arc, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:49:1 + --> $DIR/non_send_fields_in_send_ty.rs:52:1 | LL | unsafe impl Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:45:5 + --> $DIR/non_send_fields_in_send_ty.rs:48:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:56:1 + --> $DIR/non_send_fields_in_send_ty.rs:60:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:53:5 + --> $DIR/non_send_fields_in_send_ty.rs:57:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:64:1 + --> $DIR/non_send_fields_in_send_ty.rs:69:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:59:5 + --> $DIR/non_send_fields_in_send_ty.rs:64:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:5 + --> $DIR/non_send_fields_in_send_ty.rs:65:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:61:5 + --> $DIR/non_send_fields_in_send_ty.rs:66:5 | LL | field3: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:71:1 + --> $DIR/non_send_fields_in_send_ty.rs:77:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:67:12 + --> $DIR/non_send_fields_in_send_ty.rs:73:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:83:1 + --> $DIR/non_send_fields_in_send_ty.rs:90:1 | LL | unsafe impl Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:80:5 + --> $DIR/non_send_fields_in_send_ty.rs:87:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:101:1 + --> $DIR/non_send_fields_in_send_ty.rs:109:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:96:5 + --> $DIR/non_send_fields_in_send_ty.rs:104:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:120:1 + --> $DIR/non_send_fields_in_send_ty.rs:129:1 | LL | unsafe impl Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:115:11 + --> $DIR/non_send_fields_in_send_ty.rs:124:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:128:1 + --> $DIR/non_send_fields_in_send_ty.rs:138:1 | LL | unsafe impl

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:5 + --> $DIR/non_send_fields_in_send_ty.rs:134:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:131:1 + --> $DIR/non_send_fields_in_send_ty.rs:142:1 | LL | unsafe impl Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:125:5 + --> $DIR/non_send_fields_in_send_ty.rs:135:5 | LL | field2: B, | ^^^^^^^^^ diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 9bb97bd50286b..da7876e772ee9 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -11,15 +11,23 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = !true; + //~^ ERROR: this boolean expression can be simplified + //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings` let _ = !false; + //~^ ERROR: this boolean expression can be simplified let _ = !!a; + //~^ ERROR: this boolean expression can be simplified let _ = false || a; + //~^ ERROR: this boolean expression can be simplified // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; let _ = !(!a && b); + //~^ ERROR: this boolean expression can be simplified let _ = !(!a || b); + //~^ ERROR: this boolean expression can be simplified let _ = !a && !(b && c); + //~^ ERROR: this boolean expression can be simplified } fn equality_stuff() { @@ -28,10 +36,15 @@ fn equality_stuff() { let c: i32 = unimplemented!(); let d: i32 = unimplemented!(); let _ = a == b && c == 5 && a == b; + //~^ ERROR: this boolean expression can be simplified let _ = a == b || c == 5 || a == b; + //~^ ERROR: this boolean expression can be simplified let _ = a == b && c == 5 && b == a; + //~^ ERROR: this boolean expression can be simplified let _ = a != b || !(a != b || c == d); + //~^ ERROR: this boolean expression can be simplified let _ = a != b && !(a != b && c == d); + //~^ ERROR: this boolean expression can be simplified } fn issue3847(a: u32, b: u32) -> bool { @@ -62,6 +75,7 @@ fn check_expect() { fn issue9428() { if matches!(true, true) && true { + //~^ ERROR: this boolean expression can be simplified println!("foo"); } } diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 087e57867e6d1..2eba55555f438 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -7,43 +7,43 @@ LL | let _ = !true; = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:14:13 + --> $DIR/nonminimal_bool.rs:16:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:15:13 + --> $DIR/nonminimal_bool.rs:18:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:16:13 + --> $DIR/nonminimal_bool.rs:20:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:20:13 + --> $DIR/nonminimal_bool.rs:25:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:21:13 + --> $DIR/nonminimal_bool.rs:27:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:22:13 + --> $DIR/nonminimal_bool.rs:29:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:30:13 + --> $DIR/nonminimal_bool.rs:38:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:31:13 + --> $DIR/nonminimal_bool.rs:40:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:32:13 + --> $DIR/nonminimal_bool.rs:42:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:33:13 + --> $DIR/nonminimal_bool.rs:44:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:34:13 + --> $DIR/nonminimal_bool.rs:46:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:64:8 + --> $DIR/nonminimal_bool.rs:77:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` diff --git a/tests/ui/octal_escapes.rs b/tests/ui/octal_escapes.rs index 68fd3f2180d4e..3915dfdb8418b 100644 --- a/tests/ui/octal_escapes.rs +++ b/tests/ui/octal_escapes.rs @@ -3,15 +3,24 @@ fn main() { let _bad1 = "\033[0m"; + //~^ ERROR: octal-looking escape in string literal let _bad2 = b"\033[0m"; + //~^ ERROR: octal-looking escape in byte string literal let _bad3 = "\\\033[0m"; + //~^ ERROR: octal-looking escape in string literal // maximum 3 digits (\012 is the escape) let _bad4 = "\01234567"; + //~^ ERROR: octal-looking escape in string literal let _bad5 = "\0\03"; + //~^ ERROR: octal-looking escape in string literal let _bad6 = "Text-\055\077-MoreText"; + //~^ ERROR: octal-looking escape in string literal let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; + //~^ ERROR: octal-looking escape in string literal let _bad8 = "锈\01锈"; + //~^ ERROR: octal-looking escape in string literal let _bad9 = "锈\011锈"; + //~^ ERROR: octal-looking escape in string literal let _good1 = "\\033[0m"; let _good2 = "\0\\0"; diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 078118eb7f204..98f7d21261f5b 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -16,7 +16,7 @@ LL | let _bad1 = "\x0033[0m"; | ~~~~~~~~~~~ error: octal-looking escape in byte string literal - --> $DIR/octal_escapes.rs:6:17 + --> $DIR/octal_escapes.rs:7:17 | LL | let _bad2 = b"\033[0m"; | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _bad2 = b"\x0033[0m"; | ~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:7:17 + --> $DIR/octal_escapes.rs:9:17 | LL | let _bad3 = "\\\033[0m"; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _bad3 = "\\\x0033[0m"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:9:17 + --> $DIR/octal_escapes.rs:12:17 | LL | let _bad4 = "\01234567"; | ^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _bad4 = "\x001234567"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:10:17 + --> $DIR/octal_escapes.rs:14:17 | LL | let _bad5 = "\0\03"; | ^^^^^^^ @@ -80,7 +80,7 @@ LL | let _bad5 = "\0\x003"; | ~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:11:17 + --> $DIR/octal_escapes.rs:16:17 | LL | let _bad6 = "Text-\055\077-MoreText"; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _bad6 = "Text-\x0055\x0077-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:12:17 + --> $DIR/octal_escapes.rs:18:17 | LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let _bad7 = "EvenMoreText-\x001\x002-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:13:17 + --> $DIR/octal_escapes.rs:20:17 | LL | let _bad8 = "锈\01锈"; | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | let _bad8 = "锈\x001锈"; | ~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:14:17 + --> $DIR/octal_escapes.rs:22:17 | LL | let _bad9 = "锈\011锈"; | ^^^^^^^^^^ diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs index 2047ee689d95c..c2ad21e22ff8c 100644 --- a/tests/ui/ok_expect.rs +++ b/tests/ui/ok_expect.rs @@ -14,16 +14,21 @@ fn main() { let _ = res.unwrap(); res.ok().expect("disaster!"); + //~^ ERROR: called `ok().expect()` on a `Result` value // the following should not warn, since `expect` isn't implemented unless // the error type implements `Debug` let res2: Result = Ok(0); res2.ok().expect("oh noes!"); let res3: Result> = Ok(0); res3.ok().expect("whoof"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res4: Result = Ok(0); res4.ok().expect("argh"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res5: io::Result = Ok(0); res5.ok().expect("oops"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res6: Result = Ok(0); res6.ok().expect("meh"); + //~^ ERROR: called `ok().expect()` on a `Result` value } diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index ab9df26ebc37e..4c295d7a4c257 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -8,7 +8,7 @@ LL | res.ok().expect("disaster!"); = note: `-D clippy::ok-expect` implied by `-D warnings` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:22:5 + --> $DIR/ok_expect.rs:23:5 | LL | res3.ok().expect("whoof"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | res3.ok().expect("whoof"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:24:5 + --> $DIR/ok_expect.rs:26:5 | LL | res4.ok().expect("argh"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | res4.ok().expect("argh"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:26:5 + --> $DIR/ok_expect.rs:29:5 | LL | res5.ok().expect("oops"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | res5.ok().expect("oops"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:28:5 + --> $DIR/ok_expect.rs:32:5 | LL | res6.ok().expect("meh"); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/only_used_in_recursion.rs b/tests/ui/only_used_in_recursion.rs index 871b3a79f3f6b..169fb790f8c5c 100644 --- a/tests/ui/only_used_in_recursion.rs +++ b/tests/ui/only_used_in_recursion.rs @@ -9,14 +9,18 @@ fn _simple2(x: u32) -> u32 { } fn _one_unused(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _one_unused(flag - 1, a) } } fn _two_unused(flag: u32, a: u32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } } fn _with_calc(flag: u32, a: i64) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -30,6 +34,8 @@ fn _used_with_flag(flag: u32, a: u32) -> usize { } fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -38,6 +44,8 @@ fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { } fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -46,6 +54,7 @@ fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { } fn _not_primitive(flag: u32, b: String) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } } @@ -53,10 +62,13 @@ struct A; impl A { fn _method(flag: usize, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::_method(flag - 1, a) } } fn _method_self(&self, flag: usize, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self._method_self(flag - 1, a) } } } @@ -68,10 +80,12 @@ trait B { impl B for A { fn method(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } @@ -98,10 +112,12 @@ impl B for u32 { trait C { fn method(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } diff --git a/tests/ui/only_used_in_recursion.stderr b/tests/ui/only_used_in_recursion.stderr index 571e5c4b5faa9..b731d37c62c44 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -5,188 +5,188 @@ LL | fn _one_unused(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:12:53 + --> $DIR/only_used_in_recursion.rs:13:53 | LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:15:27 + --> $DIR/only_used_in_recursion.rs:16:27 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:16:53 + --> $DIR/only_used_in_recursion.rs:19:53 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:15:35 + --> $DIR/only_used_in_recursion.rs:16:35 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:16:56 + --> $DIR/only_used_in_recursion.rs:19:56 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:19:26 + --> $DIR/only_used_in_recursion.rs:22:26 | LL | fn _with_calc(flag: u32, a: i64) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:23:32 + --> $DIR/only_used_in_recursion.rs:27:32 | LL | _with_calc(flag - 1, (-a + 10) * 5) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:32:33 + --> $DIR/only_used_in_recursion.rs:36:33 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:36:38 + --> $DIR/only_used_in_recursion.rs:42:38 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:32:41 + --> $DIR/only_used_in_recursion.rs:36:41 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:36:45 + --> $DIR/only_used_in_recursion.rs:42:45 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:40:35 + --> $DIR/only_used_in_recursion.rs:46:35 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:44:39 + --> $DIR/only_used_in_recursion.rs:52:39 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:40:43 + --> $DIR/only_used_in_recursion.rs:46:43 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:44:43 + --> $DIR/only_used_in_recursion.rs:52:43 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:48:30 + --> $DIR/only_used_in_recursion.rs:56:30 | LL | fn _not_primitive(flag: u32, b: String) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:49:56 + --> $DIR/only_used_in_recursion.rs:58:56 | LL | if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:55:29 + --> $DIR/only_used_in_recursion.rs:64:29 | LL | fn _method(flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:56:59 + --> $DIR/only_used_in_recursion.rs:66:59 | LL | if flag == 0 { 0 } else { Self::_method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:59:22 + --> $DIR/only_used_in_recursion.rs:69:22 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^^^^ | note: parameter used here - --> $DIR/only_used_in_recursion.rs:60:35 + --> $DIR/only_used_in_recursion.rs:72:35 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^^^^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:59:41 + --> $DIR/only_used_in_recursion.rs:69:41 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:60:63 + --> $DIR/only_used_in_recursion.rs:72:63 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:70:26 + --> $DIR/only_used_in_recursion.rs:82:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:71:58 + --> $DIR/only_used_in_recursion.rs:84:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:74:38 + --> $DIR/only_used_in_recursion.rs:87:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:75:62 + --> $DIR/only_used_in_recursion.rs:89:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:100:26 + --> $DIR/only_used_in_recursion.rs:114:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:101:58 + --> $DIR/only_used_in_recursion.rs:116:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:104:38 + --> $DIR/only_used_in_recursion.rs:119:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:105:62 + --> $DIR/only_used_in_recursion.rs:121:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ diff --git a/tests/ui/only_used_in_recursion2.rs b/tests/ui/only_used_in_recursion2.rs index 587114b7cb8d9..1353ff8816ad1 100644 --- a/tests/ui/only_used_in_recursion2.rs +++ b/tests/ui/only_used_in_recursion2.rs @@ -1,7 +1,9 @@ #![warn(clippy::only_used_in_recursion)] //@no-rustfix fn _with_inner(flag: u32, a: u32, b: u32) -> usize { + //~^ ERROR: parameter is only used in recursion fn inner(flag: u32, a: u32) -> u32 { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { inner(flag, a) } } @@ -10,6 +12,7 @@ fn _with_inner(flag: u32, a: u32, b: u32) -> usize { } fn _with_closure(a: Option, b: u32, f: impl Fn(u32, u32) -> Option) -> u32 { + //~^ ERROR: parameter is only used in recursion if let Some(x) = a.and_then(|x| f(x, x)) { _with_closure(Some(x), b, f) } else { @@ -60,6 +63,7 @@ impl E<()> for () { } fn overwritten_param(flag: u32, mut a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { return 0; } else if flag > 5 { @@ -71,6 +75,7 @@ fn overwritten_param(flag: u32, mut a: usize) -> usize { } fn field_direct(flag: u32, mut a: (usize,)) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { diff --git a/tests/ui/only_used_in_recursion2.stderr b/tests/ui/only_used_in_recursion2.stderr index 8dcbfdd612ef2..ae349fd29e957 100644 --- a/tests/ui/only_used_in_recursion2.stderr +++ b/tests/ui/only_used_in_recursion2.stderr @@ -5,56 +5,56 @@ LL | fn _with_inner(flag: u32, a: u32, b: u32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:9:52 + --> $DIR/only_used_in_recursion2.rs:11:52 | LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:4:25 + --> $DIR/only_used_in_recursion2.rs:5:25 | LL | fn inner(flag: u32, a: u32) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:5:47 + --> $DIR/only_used_in_recursion2.rs:7:47 | LL | if flag == 0 { 0 } else { inner(flag, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:12:34 + --> $DIR/only_used_in_recursion2.rs:14:34 | LL | fn _with_closure(a: Option, b: u32, f: impl Fn(u32, u32) -> Option) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:14:32 + --> $DIR/only_used_in_recursion2.rs:17:32 | LL | _with_closure(Some(x), b, f) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:62:37 + --> $DIR/only_used_in_recursion2.rs:65:37 | LL | fn overwritten_param(flag: u32, mut a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:70:29 + --> $DIR/only_used_in_recursion2.rs:74:29 | LL | overwritten_param(flag, a) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:73:32 + --> $DIR/only_used_in_recursion2.rs:77:32 | LL | fn field_direct(flag: u32, mut a: (usize,)) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:78:32 + --> $DIR/only_used_in_recursion2.rs:83:32 | LL | field_direct(flag - 1, a) | ^ diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed index ea7898e2b355d..183dcf4f08635 100644 --- a/tests/ui/op_ref.fixed +++ b/tests/ui/op_ref.fixed @@ -9,6 +9,8 @@ fn main() { let unwanted = &tracked_fds - &new_fds; let foo = 5 - 6; + //~^ ERROR: needlessly taken reference of both operands + //~| NOTE: `-D clippy::op-ref` implied by `-D warnings` let bar = String::new(); let bar = "foo" == &bar; @@ -54,6 +56,7 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & y; + //~^ ERROR: taken reference of right operand } #[derive(Clone, Copy)] @@ -87,7 +90,9 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * self; + //~^ ERROR: taken reference of right operand let _ = two + three; + //~^ ERROR: taken reference of right operand // Removing the reference would lead to unconditional recursion self * &rhs } diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index 07226b0a1a83b..6ed4f23d2bd7b 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -9,6 +9,8 @@ fn main() { let unwanted = &tracked_fds - &new_fds; let foo = &5 - &6; + //~^ ERROR: needlessly taken reference of both operands + //~| NOTE: `-D clippy::op-ref` implied by `-D warnings` let bar = String::new(); let bar = "foo" == &bar; @@ -54,6 +56,7 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & &y; + //~^ ERROR: taken reference of right operand } #[derive(Clone, Copy)] @@ -87,7 +90,9 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * &self; + //~^ ERROR: taken reference of right operand let _ = two + &three; + //~^ ERROR: taken reference of right operand // Removing the reference would lead to unconditional recursion self * &rhs } diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index fe36c01166ff7..5f3769ddfab4b 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -11,7 +11,7 @@ LL | let foo = 5 - 6; | ~ ~ error: taken reference of right operand - --> $DIR/op_ref.rs:56:13 + --> $DIR/op_ref.rs:58:13 | LL | let z = x & &y; | ^^^^-- @@ -19,7 +19,7 @@ LL | let z = x & &y; | help: use the right value directly: `y` error: taken reference of right operand - --> $DIR/op_ref.rs:89:17 + --> $DIR/op_ref.rs:92:17 | LL | let _ = one * &self; | ^^^^^^----- @@ -27,7 +27,7 @@ LL | let _ = one * &self; | help: use the right value directly: `self` error: taken reference of right operand - --> $DIR/op_ref.rs:90:17 + --> $DIR/op_ref.rs:94:17 | LL | let _ = two + &three; | ^^^^^^------ diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index 9063fafbcd040..0cdc5bf2bb592 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -4,11 +4,19 @@ use std::fs::OpenOptions; #[warn(clippy::nonsensical_open_options)] fn main() { OpenOptions::new().read(true).truncate(true).open("foo.txt"); + //~^ ERROR: file opened with `truncate` and `read` + //~| NOTE: `-D clippy::nonsensical-open-options` implied by `-D warnings` OpenOptions::new().append(true).truncate(true).open("foo.txt"); + //~^ ERROR: file opened with `append` and `truncate` OpenOptions::new().read(true).read(false).open("foo.txt"); + //~^ ERROR: the method `read` is called more than once OpenOptions::new().create(true).create(false).open("foo.txt"); + //~^ ERROR: the method `create` is called more than once OpenOptions::new().write(true).write(false).open("foo.txt"); + //~^ ERROR: the method `write` is called more than once OpenOptions::new().append(true).append(false).open("foo.txt"); + //~^ ERROR: the method `append` is called more than once OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); + //~^ ERROR: the method `truncate` is called more than once } diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index 26fe9f6fb206f..c136cf2dbf405 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -7,37 +7,37 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); = note: `-D clippy::nonsensical-open-options` implied by `-D warnings` error: file opened with `append` and `truncate` - --> $DIR/open_options.rs:7:5 + --> $DIR/open_options.rs:9:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> $DIR/open_options.rs:9:5 + --> $DIR/open_options.rs:12:5 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `create` is called more than once - --> $DIR/open_options.rs:10:5 + --> $DIR/open_options.rs:14:5 | LL | OpenOptions::new().create(true).create(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `write` is called more than once - --> $DIR/open_options.rs:11:5 + --> $DIR/open_options.rs:16:5 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `append` is called more than once - --> $DIR/open_options.rs:12:5 + --> $DIR/open_options.rs:18:5 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `truncate` is called more than once - --> $DIR/open_options.rs:13:5 + --> $DIR/open_options.rs:20:5 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_option.rs b/tests/ui/option_option.rs index 2faab9e035d99..9bbdd3aaacce5 100644 --- a/tests/ui/option_option.rs +++ b/tests/ui/option_option.rs @@ -2,40 +2,51 @@ #![allow(clippy::unnecessary_wraps)] const C: Option> = None; +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if static S: Option> = None; +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn input(_: Option>) {} +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn output() -> Option> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } fn output_nested() -> Vec>> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if vec![None] } // The lint only generates one warning for this fn output_nested_nested() -> Option>> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } struct Struct { x: Option>, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } impl Struct { fn struct_fn() -> Option> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum None } } trait Trait { fn trait_fn() -> Option>; + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } enum Enum { Tuple(Option>), + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum Struct { x: Option> }, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } // The lint allows this @@ -77,6 +88,7 @@ mod issue_4298 { #[serde(default)] #[serde(borrow)] foo: Option>>, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom } #[allow(clippy::option_option)] diff --git a/tests/ui/option_option.stderr b/tests/ui/option_option.stderr index a925bb35b04d8..fcae9655dbf7f 100644 --- a/tests/ui/option_option.stderr +++ b/tests/ui/option_option.stderr @@ -11,67 +11,67 @@ LL | #![deny(clippy::option_option)] | ^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:5:11 + --> $DIR/option_option.rs:6:11 | LL | static S: Option> = None; | ^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:7:13 + --> $DIR/option_option.rs:9:13 | LL | fn input(_: Option>) {} | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:9:16 + --> $DIR/option_option.rs:12:16 | LL | fn output() -> Option> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:13:27 + --> $DIR/option_option.rs:17:27 | LL | fn output_nested() -> Vec>> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:18:30 + --> $DIR/option_option.rs:23:30 | LL | fn output_nested_nested() -> Option>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:23:8 + --> $DIR/option_option.rs:29:8 | LL | x: Option>, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:27:23 + --> $DIR/option_option.rs:34:23 | LL | fn struct_fn() -> Option> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:33:22 + --> $DIR/option_option.rs:41:22 | LL | fn trait_fn() -> Option>; | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:37:11 + --> $DIR/option_option.rs:46:11 | LL | Tuple(Option>), | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:38:17 + --> $DIR/option_option.rs:48:17 | LL | Struct { x: Option> }, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:79:14 + --> $DIR/option_option.rs:90:14 | LL | foo: Option>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index a5605cc14d484..81674653bdd3b 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -7,5 +7,8 @@ fn main() { // issue 3102 let num = 1; &x[num..10]; + //~^ ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[10..num]; + //~^ ERROR: range is out of bounds } diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 8a09688a90ceb..b50b76bd9b2e8 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -7,7 +7,7 @@ LL | &x[num..10]; = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: range is out of bounds - --> $DIR/issue-3102.rs:10:8 + --> $DIR/issue-3102.rs:12:8 | LL | &x[10..num]; | ^^ diff --git a/tests/ui/out_of_bounds_indexing/simple.rs b/tests/ui/out_of_bounds_indexing/simple.rs index 4c541c23f5f47..c38ca51238165 100644 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -5,11 +5,18 @@ fn main() { let x = [1, 2, 3, 4]; &x[..=4]; + //~^ ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[1..5]; + //~^ ERROR: range is out of bounds &x[5..]; + //~^ ERROR: range is out of bounds &x[..5]; + //~^ ERROR: range is out of bounds &x[5..].iter().map(|x| 2 * x).collect::>(); + //~^ ERROR: range is out of bounds &x[0..=4]; + //~^ ERROR: range is out of bounds &x[4..]; // Ok, should not produce stderr. &x[..4]; // Ok, should not produce stderr. diff --git a/tests/ui/out_of_bounds_indexing/simple.stderr b/tests/ui/out_of_bounds_indexing/simple.stderr index 3d95afcdab233..ea5e83e87e089 100644 --- a/tests/ui/out_of_bounds_indexing/simple.stderr +++ b/tests/ui/out_of_bounds_indexing/simple.stderr @@ -7,31 +7,31 @@ LL | &x[..=4]; = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: range is out of bounds - --> $DIR/simple.rs:8:11 + --> $DIR/simple.rs:10:11 | LL | &x[1..5]; | ^ error: range is out of bounds - --> $DIR/simple.rs:9:8 + --> $DIR/simple.rs:12:8 | LL | &x[5..]; | ^ error: range is out of bounds - --> $DIR/simple.rs:10:10 + --> $DIR/simple.rs:14:10 | LL | &x[..5]; | ^ error: range is out of bounds - --> $DIR/simple.rs:11:8 + --> $DIR/simple.rs:16:8 | LL | &x[5..].iter().map(|x| 2 * x).collect::>(); | ^ error: range is out of bounds - --> $DIR/simple.rs:12:12 + --> $DIR/simple.rs:18:12 | LL | &x[0..=4]; | ^ diff --git a/tests/ui/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs index 14a6b98d07d14..a70bb3bc47bfb 100644 --- a/tests/ui/overflow_check_conditional.rs +++ b/tests/ui/overflow_check_conditional.rs @@ -3,13 +3,22 @@ fn test(a: u32, b: u32, c: u32) { if a + b < a {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust + //~| NOTE: `-D clippy::overflow-check-conditional` implied by `-D warnings` if a > a + b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if a + b < b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if b > a + b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if a - b > b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if b < a - b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a - b > a {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a < a - b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a + b < c {} if c > a + b {} if a - b < c {} diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr index 3ec2298f828ae..b1e9f1eee54f3 100644 --- a/tests/ui/overflow_check_conditional.stderr +++ b/tests/ui/overflow_check_conditional.stderr @@ -7,43 +7,43 @@ LL | if a + b < a {} = note: `-D clippy::overflow-check-conditional` implied by `-D warnings` error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:6:8 + --> $DIR/overflow_check_conditional.rs:8:8 | LL | if a > a + b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:7:8 + --> $DIR/overflow_check_conditional.rs:10:8 | LL | if a + b < b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:8:8 + --> $DIR/overflow_check_conditional.rs:12:8 | LL | if b > a + b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:9:8 + --> $DIR/overflow_check_conditional.rs:14:8 | LL | if a - b > b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:10:8 + --> $DIR/overflow_check_conditional.rs:16:8 | LL | if b < a - b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:11:8 + --> $DIR/overflow_check_conditional.rs:18:8 | LL | if a - b > a {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:12:8 + --> $DIR/overflow_check_conditional.rs:20:8 | LL | if a < a - b {} | ^^^^^^^^^ diff --git a/tests/ui/overly_complex_bool_expr.fixed b/tests/ui/overly_complex_bool_expr.fixed index f143cf70fcfad..e44f6063156a7 100644 --- a/tests/ui/overly_complex_bool_expr.fixed +++ b/tests/ui/overly_complex_bool_expr.fixed @@ -9,8 +9,10 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a; + //~^ ERROR: this boolean expression contains a logic bug let _ = !(a && b); let _ = false; + //~^ ERROR: this boolean expression contains a logic bug // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -21,8 +23,11 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = false; + //~^ ERROR: this boolean expression contains a logic bug let _ = false; + //~^ ERROR: this boolean expression contains a logic bug let _ = false; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a == b; } diff --git a/tests/ui/overly_complex_bool_expr.rs b/tests/ui/overly_complex_bool_expr.rs index 04a30a83250e1..f010a8537e7f7 100644 --- a/tests/ui/overly_complex_bool_expr.rs +++ b/tests/ui/overly_complex_bool_expr.rs @@ -9,8 +9,10 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a && b || a; + //~^ ERROR: this boolean expression contains a logic bug let _ = !(a && b); let _ = false && a; + //~^ ERROR: this boolean expression contains a logic bug // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -21,8 +23,11 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = a == b && a != b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a < b && a >= b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a <= b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a == b; } diff --git a/tests/ui/overly_complex_bool_expr.stderr b/tests/ui/overly_complex_bool_expr.stderr index e989f2ece3080..d296b88224d8c 100644 --- a/tests/ui/overly_complex_bool_expr.stderr +++ b/tests/ui/overly_complex_bool_expr.stderr @@ -12,49 +12,49 @@ LL | let _ = a && b || a; = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings` error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:13:13 + --> $DIR/overly_complex_bool_expr.rs:14:13 | LL | let _ = false && a; | ^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:13:22 + --> $DIR/overly_complex_bool_expr.rs:14:22 | LL | let _ = false && a; | ^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:23:13 + --> $DIR/overly_complex_bool_expr.rs:25:13 | LL | let _ = a == b && a != b; | ^^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:23:13 + --> $DIR/overly_complex_bool_expr.rs:25:13 | LL | let _ = a == b && a != b; | ^^^^^^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:24:13 + --> $DIR/overly_complex_bool_expr.rs:27:13 | LL | let _ = a < b && a >= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:24:13 + --> $DIR/overly_complex_bool_expr.rs:27:13 | LL | let _ = a < b && a >= b; | ^^^^^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:25:13 + --> $DIR/overly_complex_bool_expr.rs:29:13 | LL | let _ = a > b && a <= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:25:13 + --> $DIR/overly_complex_bool_expr.rs:29:13 | LL | let _ = a > b && a <= b; | ^^^^^ diff --git a/tests/ui/panic_in_result_fn.rs b/tests/ui/panic_in_result_fn.rs index e75eb1b6eadd8..41e2f5226899d 100644 --- a/tests/ui/panic_in_result_fn.rs +++ b/tests/ui/panic_in_result_fn.rs @@ -4,6 +4,7 @@ struct A; impl A { fn result_with_panic() -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { panic!("error"); } @@ -50,6 +51,7 @@ impl A { } fn function_result_with_panic() -> Result // should emit lint +//~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { panic!("error"); } diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index b758fc2381248..9040018f1d4c9 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -2,6 +2,7 @@ error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:6:5 | LL | / fn result_with_panic() -> Result // should emit lint +LL | | LL | | { LL | | panic!("error"); LL | | } @@ -9,16 +10,17 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:8:9 + --> $DIR/panic_in_result_fn.rs:9:9 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:52:1 + --> $DIR/panic_in_result_fn.rs:53:1 | LL | / fn function_result_with_panic() -> Result // should emit lint +LL | | LL | | { LL | | panic!("error"); LL | | } @@ -26,7 +28,7 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:54:5 + --> $DIR/panic_in_result_fn.rs:56:5 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/panic_in_result_fn_assertions.rs b/tests/ui/panic_in_result_fn_assertions.rs index 08ab4d8681edd..672c4c7383392 100644 --- a/tests/ui/panic_in_result_fn_assertions.rs +++ b/tests/ui/panic_in_result_fn_assertions.rs @@ -5,18 +5,21 @@ struct A; impl A { fn result_with_assert_with_message(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert!(x == 5, "wrong argument"); Ok(true) } fn result_with_assert_eq(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert_eq!(x, 5); Ok(true) } fn result_with_assert_ne(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert_ne!(x, 1); Ok(true) diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index 0dd213a7eede9..368a9970af850 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -2,6 +2,7 @@ error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:7:5 | LL | / fn result_with_assert_with_message(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert!(x == 5, "wrong argument"); LL | | Ok(true) @@ -10,16 +11,17 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:9:9 + --> $DIR/panic_in_result_fn_assertions.rs:10:9 | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:13:5 + --> $DIR/panic_in_result_fn_assertions.rs:14:5 | LL | / fn result_with_assert_eq(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert_eq!(x, 5); LL | | Ok(true) @@ -28,15 +30,16 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:15:9 + --> $DIR/panic_in_result_fn_assertions.rs:17:9 | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:19:5 + --> $DIR/panic_in_result_fn_assertions.rs:21:5 | LL | / fn result_with_assert_ne(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert_ne!(x, 1); LL | | Ok(true) @@ -45,7 +48,7 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:21:9 + --> $DIR/panic_in_result_fn_assertions.rs:24:9 | LL | assert_ne!(x, 1); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs index 041ef17fa6834..dccfbd409e503 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -21,41 +21,61 @@ fn inline_const() { fn panic() { let a = 2; panic!(); + //~^ ERROR: `panic` should not be present in production code + //~| NOTE: `-D clippy::panic` implied by `-D warnings` panic!("message"); + //~^ ERROR: `panic` should not be present in production code panic!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `panic` should not be present in production code let b = a + 2; } fn todo() { let a = 2; todo!(); + //~^ ERROR: `todo` should not be present in production code + //~| NOTE: `-D clippy::todo` implied by `-D warnings` todo!("message"); + //~^ ERROR: `todo` should not be present in production code todo!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `todo` should not be present in production code let b = a + 2; } fn unimplemented() { let a = 2; unimplemented!(); + //~^ ERROR: `unimplemented` should not be present in production code + //~| NOTE: `-D clippy::unimplemented` implied by `-D warnings` unimplemented!("message"); + //~^ ERROR: `unimplemented` should not be present in production code unimplemented!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `unimplemented` should not be present in production code let b = a + 2; } fn unreachable() { let a = 2; unreachable!(); + //~^ ERROR: usage of the `unreachable!` macro + //~| NOTE: `-D clippy::unreachable` implied by `-D warnings` unreachable!("message"); + //~^ ERROR: usage of the `unreachable!` macro unreachable!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: usage of the `unreachable!` macro let b = a + 2; } fn core_versions() { use core::{panic, todo, unimplemented, unreachable}; panic!(); + //~^ ERROR: `panic` should not be present in production code todo!(); + //~^ ERROR: `todo` should not be present in production code unimplemented!(); + //~^ ERROR: `unimplemented` should not be present in production code unreachable!(); + //~^ ERROR: usage of the `unreachable!` macro } fn assert() { diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 4ceb6d1440f61..b47220d2cdc35 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -7,19 +7,19 @@ LL | panic!(); = note: `-D clippy::panic` implied by `-D warnings` error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:24:5 + --> $DIR/panicking_macros.rs:26:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:25:5 + --> $DIR/panicking_macros.rs:28:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:31:5 + --> $DIR/panicking_macros.rs:35:5 | LL | todo!(); | ^^^^^^^ @@ -27,19 +27,19 @@ LL | todo!(); = note: `-D clippy::todo` implied by `-D warnings` error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:32:5 + --> $DIR/panicking_macros.rs:38:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:33:5 + --> $DIR/panicking_macros.rs:40:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:39:5 + --> $DIR/panicking_macros.rs:47:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ @@ -47,19 +47,19 @@ LL | unimplemented!(); = note: `-D clippy::unimplemented` implied by `-D warnings` error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:40:5 + --> $DIR/panicking_macros.rs:50:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:41:5 + --> $DIR/panicking_macros.rs:52:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:47:5 + --> $DIR/panicking_macros.rs:59:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ @@ -67,37 +67,37 @@ LL | unreachable!(); = note: `-D clippy::unreachable` implied by `-D warnings` error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:48:5 + --> $DIR/panicking_macros.rs:62:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:49:5 + --> $DIR/panicking_macros.rs:64:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:55:5 + --> $DIR/panicking_macros.rs:71:5 | LL | panic!(); | ^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:56:5 + --> $DIR/panicking_macros.rs:73:5 | LL | todo!(); | ^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:57:5 + --> $DIR/panicking_macros.rs:75:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:58:5 + --> $DIR/panicking_macros.rs:77:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/partial_pub_fields.rs b/tests/ui/partial_pub_fields.rs index 668545da84419..316b36c25eacd 100644 --- a/tests/ui/partial_pub_fields.rs +++ b/tests/ui/partial_pub_fields.rs @@ -8,19 +8,23 @@ fn main() { pub struct FileSet { files: HashMap, pub paths: HashMap, + //~^ ERROR: mixed usage of pub and non-pub fields } pub struct Color { pub r: u8, pub g: u8, b: u8, + //~^ ERROR: mixed usage of pub and non-pub fields } pub struct Point(i32, pub i32); + //~^ ERROR: mixed usage of pub and non-pub fields pub struct Visibility { r#pub: bool, pub pos: u32, + //~^ ERROR: mixed usage of pub and non-pub fields } // Don't lint on empty structs; diff --git a/tests/ui/partial_pub_fields.stderr b/tests/ui/partial_pub_fields.stderr index 84cfc1a91940d..95960201769e2 100644 --- a/tests/ui/partial_pub_fields.stderr +++ b/tests/ui/partial_pub_fields.stderr @@ -8,7 +8,7 @@ LL | pub paths: HashMap, = note: `-D clippy::partial-pub-fields` implied by `-D warnings` error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:16:9 + --> $DIR/partial_pub_fields.rs:17:9 | LL | b: u8, | ^ @@ -16,7 +16,7 @@ LL | b: u8, = help: consider using public field here error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:19:27 + --> $DIR/partial_pub_fields.rs:21:27 | LL | pub struct Point(i32, pub i32); | ^^^ @@ -24,7 +24,7 @@ LL | pub struct Point(i32, pub i32); = help: consider using private field here error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:23:9 + --> $DIR/partial_pub_fields.rs:26:9 | LL | pub pos: u32, | ^^^ diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index 1338d3c74d554..555eeebe1c78a 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -7,6 +7,8 @@ impl PartialEq for Foo { true } fn ne(&self, _: &Foo) -> bool { + //~^ ERROR: re-implementing `PartialEq::ne` is unnecessary + //~| NOTE: `-D clippy::partialeq-ne-impl` implied by `-D warnings` false } } diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index b92da4511b48d..04b29dd8764aa 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -2,6 +2,8 @@ error: re-implementing `PartialEq::ne` is unnecessary --> $DIR/partialeq_ne_impl.rs:9:5 | LL | / fn ne(&self, _: &Foo) -> bool { +LL | | +LL | | LL | | false LL | | } | |_____^ diff --git a/tests/ui/pattern_type_mismatch/mutability.rs b/tests/ui/pattern_type_mismatch/mutability.rs index 55a8c26215e9e..61dee47cb1927 100644 --- a/tests/ui/pattern_type_mismatch/mutability.rs +++ b/tests/ui/pattern_type_mismatch/mutability.rs @@ -7,12 +7,14 @@ fn should_lint() { let value = &Some(23); match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), } let value = &mut Some(23); match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), } } diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr index 87fb243b65efd..b512f5e1ee256 100644 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/tests/ui/pattern_type_mismatch/mutability.stderr @@ -8,7 +8,7 @@ LL | Some(_) => (), = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/mutability.rs:15:9 + --> $DIR/mutability.rs:16:9 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs index 065ea9fb9b5a4..558d496ae2c0f 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs @@ -13,8 +13,11 @@ fn alternatives() { // not ok if let Value::B | Value::A(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &Value::B | &Value::A(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let Value::B | Value::A(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &Value::B | &Value::A(_) = ref_value {} diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr index a91b5ac6cf742..8e0d13bc8bdb8 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr @@ -8,7 +8,7 @@ LL | if let Value::B | Value::A(_) = ref_value {} = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:16:34 + --> $DIR/pattern_alternatives.rs:17:34 | LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:17:32 + --> $DIR/pattern_alternatives.rs:19:32 | LL | if let Value::B | Value::A(Some(_)) = *ref_value {} | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.rs b/tests/ui/pattern_type_mismatch/pattern_structs.rs index 417b1c107c55b..d9b22693f297f 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.rs +++ b/tests/ui/pattern_type_mismatch/pattern_structs.rs @@ -11,8 +11,11 @@ fn struct_types() { // not ok let Struct { .. } = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &Struct { ref_inner: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let Struct { ref_inner: Some(_) } = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &Struct { .. } = ref_value; @@ -30,10 +33,15 @@ fn struct_enum_variants() { // not ok if let StructEnum::Var { .. } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Empty = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &StructEnum::Var { .. } = ref_value {} diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/tests/ui/pattern_type_mismatch/pattern_structs.stderr index 8bc5c63baab5b..a0c7a67b521e2 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -8,7 +8,7 @@ LL | let Struct { .. } = ref_value; = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:14:33 + --> $DIR/pattern_structs.rs:15:33 | LL | if let &Struct { ref_inner: Some(_) } = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let &Struct { ref_inner: Some(_) } = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:15:32 + --> $DIR/pattern_structs.rs:17:32 | LL | if let Struct { ref_inner: Some(_) } = *ref_value {} | ^^^^^^^ @@ -24,7 +24,7 @@ LL | if let Struct { ref_inner: Some(_) } = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:32:12 + --> $DIR/pattern_structs.rs:35:12 | LL | if let StructEnum::Var { .. } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | if let StructEnum::Var { .. } = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:33:12 + --> $DIR/pattern_structs.rs:37:12 | LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:34:42 + --> $DIR/pattern_structs.rs:39:42 | LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^ @@ -48,7 +48,7 @@ LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:35:41 + --> $DIR/pattern_structs.rs:41:41 | LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} | ^^^^^^^ @@ -56,7 +56,7 @@ LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:36:12 + --> $DIR/pattern_structs.rs:43:12 | LL | if let StructEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.rs b/tests/ui/pattern_type_mismatch/pattern_tuples.rs index 19504a051d8b1..f44e3543c96ad 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.rs +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.rs @@ -9,8 +9,11 @@ fn tuple_types() { // not ok let TupleStruct(_) = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &TupleStruct(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleStruct(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &TupleStruct(_) = ref_value; @@ -28,9 +31,13 @@ fn tuple_enum_variants() { // not ok if let TupleEnum::Var(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &TupleEnum::Var(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleEnum::Var(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleEnum::Empty = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &TupleEnum::Var(_) = ref_value {} @@ -46,8 +53,11 @@ fn plain_tuples() { // not ok let (_a, _b) = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &(_a, Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let (_a, Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &(_a, _b) = ref_value; diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr index a1ef540d28313..1001f4f63c686 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -8,7 +8,7 @@ LL | let TupleStruct(_) = ref_value; = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:12:25 + --> $DIR/pattern_tuples.rs:13:25 | LL | if let &TupleStruct(Some(_)) = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let &TupleStruct(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:13:24 + --> $DIR/pattern_tuples.rs:15:24 | LL | if let TupleStruct(Some(_)) = *ref_value {} | ^^^^^^^ @@ -24,7 +24,7 @@ LL | if let TupleStruct(Some(_)) = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:30:12 + --> $DIR/pattern_tuples.rs:33:12 | LL | if let TupleEnum::Var(_) = ref_value {} | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | if let TupleEnum::Var(_) = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:31:28 + --> $DIR/pattern_tuples.rs:35:28 | LL | if let &TupleEnum::Var(Some(_)) = ref_value {} | ^^^^^^^ @@ -40,7 +40,7 @@ LL | if let &TupleEnum::Var(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:32:27 + --> $DIR/pattern_tuples.rs:37:27 | LL | if let TupleEnum::Var(Some(_)) = *ref_value {} | ^^^^^^^ @@ -48,7 +48,7 @@ LL | if let TupleEnum::Var(Some(_)) = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:33:12 + --> $DIR/pattern_tuples.rs:39:12 | LL | if let TupleEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let TupleEnum::Empty = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:48:9 + --> $DIR/pattern_tuples.rs:55:9 | LL | let (_a, _b) = ref_value; | ^^^^^^^^ @@ -64,7 +64,7 @@ LL | let (_a, _b) = ref_value; = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:49:18 + --> $DIR/pattern_tuples.rs:57:18 | LL | if let &(_a, Some(_)) = ref_value {} | ^^^^^^^ @@ -72,7 +72,7 @@ LL | if let &(_a, Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:50:17 + --> $DIR/pattern_tuples.rs:59:17 | LL | if let (_a, Some(_)) = *ref_value {} | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/syntax.rs b/tests/ui/pattern_type_mismatch/syntax.rs index e89917c41e8c1..dbc7c3f31061c 100644 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ b/tests/ui/pattern_type_mismatch/syntax.rs @@ -9,6 +9,7 @@ fn syntax_match() { // not ok match ref_value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type None => (), } @@ -28,6 +29,7 @@ fn syntax_if_let() { // not ok if let Some(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &Some(_) = ref_value {} @@ -39,6 +41,7 @@ fn syntax_while_let() { // not ok while let Some(_) = ref_value { + //~^ ERROR: type of pattern does not match the expression type break; } @@ -57,6 +60,7 @@ fn syntax_for() { // not ok for (_a, _b) in slice.iter() {} + //~^ ERROR: type of pattern does not match the expression type // ok for &(_a, _b) in slice.iter() {} @@ -67,6 +71,7 @@ fn syntax_let() { // not ok let (_n, _m) = ref_value; + //~^ ERROR: type of pattern does not match the expression type // ok let &(_n, _m) = ref_value; @@ -76,6 +81,7 @@ fn syntax_let() { fn syntax_fn() { // not ok fn foo((_a, _b): &(i32, i32)) {} + //~^ ERROR: type of pattern does not match the expression type // ok fn foo_ok_1(&(_a, _b): &(i32, i32)) {} @@ -90,6 +96,7 @@ fn syntax_closure() { // not ok foo(|(_a, _b)| ()); + //~^ ERROR: type of pattern does not match the expression type // ok foo(|&(_a, _b)| ()); @@ -106,6 +113,7 @@ fn macro_with_expression() { // not ok matching_macro!(match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), }); diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index f56a3a893801b..36869598815d7 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -8,7 +8,7 @@ LL | Some(_) => (), = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/syntax.rs:30:12 + --> $DIR/syntax.rs:31:12 | LL | if let Some(_) = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let Some(_) = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:41:15 + --> $DIR/syntax.rs:43:15 | LL | while let Some(_) = ref_value { | ^^^^^^^ @@ -24,7 +24,7 @@ LL | while let Some(_) = ref_value { = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:59:9 + --> $DIR/syntax.rs:62:9 | LL | for (_a, _b) in slice.iter() {} | ^^^^^^^^ @@ -32,7 +32,7 @@ LL | for (_a, _b) in slice.iter() {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:69:9 + --> $DIR/syntax.rs:73:9 | LL | let (_n, _m) = ref_value; | ^^^^^^^^ @@ -40,7 +40,7 @@ LL | let (_n, _m) = ref_value; = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:78:12 + --> $DIR/syntax.rs:83:12 | LL | fn foo((_a, _b): &(i32, i32)) {} | ^^^^^^^^ @@ -48,7 +48,7 @@ LL | fn foo((_a, _b): &(i32, i32)) {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:92:10 + --> $DIR/syntax.rs:98:10 | LL | foo(|(_a, _b)| ()); | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | foo(|(_a, _b)| ()); = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:108:9 + --> $DIR/syntax.rs:115:9 | LL | Some(_) => (), | ^^^^^^^ @@ -64,7 +64,7 @@ LL | Some(_) => (), = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:128:17 + --> $DIR/syntax.rs:136:17 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/permissions_set_readonly_false.rs b/tests/ui/permissions_set_readonly_false.rs index 28c00d100942c..5a84a64fd2d10 100644 --- a/tests/ui/permissions_set_readonly_false.rs +++ b/tests/ui/permissions_set_readonly_false.rs @@ -17,6 +17,8 @@ fn main() { let mut permissions = metadata.permissions(); // lint here permissions.set_readonly(false); + //~^ ERROR: call to `set_readonly` with argument `false` + //~| NOTE: on Unix platforms this results in the file being world writable // no lint permissions.set_readonly(true); diff --git a/tests/ui/print.rs b/tests/ui/print.rs index 366ccc2b3bd58..9ac4b51e1afd9 100644 --- a/tests/ui/print.rs +++ b/tests/ui/print.rs @@ -9,6 +9,8 @@ struct Foo; impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{:?}", 43.1415) + //~^ ERROR: use of `Debug`-based formatting + //~| NOTE: `-D clippy::use-debug` implied by `-D warnings` } } @@ -21,13 +23,21 @@ impl Debug for Foo { fn main() { println!("Hello"); + //~^ ERROR: use of `println!` + //~| NOTE: `-D clippy::print-stdout` implied by `-D warnings` print!("Hello"); + //~^ ERROR: use of `print!` print!("Hello {}", "World"); + //~^ ERROR: use of `print!` print!("Hello {:?}", "World"); + //~^ ERROR: use of `print!` + //~| ERROR: use of `Debug`-based formatting print!("Hello {:#?}", "#orld"); + //~^ ERROR: use of `print!` + //~| ERROR: use of `Debug`-based formatting assert_eq!(42, 1337); diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr index 1754c418381a1..e9d88df33f597 100644 --- a/tests/ui/print.stderr +++ b/tests/ui/print.stderr @@ -7,7 +7,7 @@ LL | write!(f, "{:?}", 43.1415) = note: `-D clippy::use-debug` implied by `-D warnings` error: use of `println!` - --> $DIR/print.rs:23:5 + --> $DIR/print.rs:25:5 | LL | println!("Hello"); | ^^^^^^^^^^^^^^^^^ @@ -15,37 +15,37 @@ LL | println!("Hello"); = note: `-D clippy::print-stdout` implied by `-D warnings` error: use of `print!` - --> $DIR/print.rs:24:5 + --> $DIR/print.rs:28:5 | LL | print!("Hello"); | ^^^^^^^^^^^^^^^ error: use of `print!` - --> $DIR/print.rs:26:5 + --> $DIR/print.rs:31:5 | LL | print!("Hello {}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `print!` - --> $DIR/print.rs:28:5 + --> $DIR/print.rs:34:5 | LL | print!("Hello {:?}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> $DIR/print.rs:28:19 + --> $DIR/print.rs:34:19 | LL | print!("Hello {:?}", "World"); | ^^^^ error: use of `print!` - --> $DIR/print.rs:30:5 + --> $DIR/print.rs:38:5 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> $DIR/print.rs:30:19 + --> $DIR/print.rs:38:19 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^ diff --git a/tests/ui/print_in_format_impl.rs b/tests/ui/print_in_format_impl.rs index deafcbfb8c366..261f50832199c 100644 --- a/tests/ui/print_in_format_impl.rs +++ b/tests/ui/print_in_format_impl.rs @@ -18,11 +18,17 @@ impl Debug for Foo { static WORKS_WITH_NESTED_ITEMS: bool = true; print!("{}", 1); + //~^ ERROR: use of `print!` in `Debug` impl + //~| NOTE: `-D clippy::print-in-format-impl` implied by `-D warnings` println!("{}", 2); + //~^ ERROR: use of `println!` in `Debug` impl eprint!("{}", 3); + //~^ ERROR: use of `eprint!` in `Debug` impl eprintln!("{}", 4); + //~^ ERROR: use of `eprintln!` in `Debug` impl nested! { println!("nested"); + //~^ ERROR: use of `println!` in `Debug` impl }; write!(f, "{}", 5); @@ -36,6 +42,7 @@ impl Debug for Foo { impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { print!("Display"); + //~^ ERROR: use of `print!` in `Display` impl write!(f, "Display"); Ok(()) @@ -46,6 +53,7 @@ struct UnnamedFormatter; impl Debug for UnnamedFormatter { fn fmt(&self, _: &mut Formatter) -> Result<(), Error> { println!("UnnamedFormatter"); + //~^ ERROR: use of `println!` in `Debug` impl Ok(()) } } diff --git a/tests/ui/print_in_format_impl.stderr b/tests/ui/print_in_format_impl.stderr index 63b7179bca7dc..7a7a2dc1c2a7f 100644 --- a/tests/ui/print_in_format_impl.stderr +++ b/tests/ui/print_in_format_impl.stderr @@ -7,37 +7,37 @@ LL | print!("{}", 1); = note: `-D clippy::print-in-format-impl` implied by `-D warnings` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:21:9 + --> $DIR/print_in_format_impl.rs:23:9 | LL | println!("{}", 2); | ^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `eprint!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:22:9 + --> $DIR/print_in_format_impl.rs:25:9 | LL | eprint!("{}", 3); | ^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `eprintln!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:23:9 + --> $DIR/print_in_format_impl.rs:27:9 | LL | eprintln!("{}", 4); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:25:13 + --> $DIR/print_in_format_impl.rs:30:13 | LL | println!("nested"); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `print!` in `Display` impl - --> $DIR/print_in_format_impl.rs:38:9 + --> $DIR/print_in_format_impl.rs:44:9 | LL | print!("Display"); | ^^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:48:9 + --> $DIR/print_in_format_impl.rs:55:9 | LL | println!("UnnamedFormatter"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(..)` diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index 48fe024ef63f7..88cd3a54b4100 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -25,19 +25,32 @@ fn main() { // these should throw warnings print!("Hello world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` println!("Hello {} world", world); + //~^ ERROR: literal with an empty format string println!("Hello world"); + //~^ ERROR: literal with an empty format string println!("a literal {:.4}", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning println!("hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either println!("hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index 538513e9156f8..bd7444c9606ab 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -25,19 +25,32 @@ fn main() { // these should throw warnings print!("Hello {}", "world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` println!("Hello {} {}", world, "world"); + //~^ ERROR: literal with an empty format string println!("Hello {}", "world"); + //~^ ERROR: literal with an empty format string println!("{} {:.4}", "a literal", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning println!("{0} {1}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("{1} {0}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either println!("{foo} {bar}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("{bar} {foo}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index 71c8d188f1678..d7a2fa7f4bb47 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -12,7 +12,7 @@ LL + print!("Hello world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:28:36 + --> $DIR/print_literal.rs:30:36 | LL | println!("Hello {} {}", world, "world"); | ^^^^^^^ @@ -24,7 +24,7 @@ LL + println!("Hello {} world", world); | error: literal with an empty format string - --> $DIR/print_literal.rs:29:26 + --> $DIR/print_literal.rs:32:26 | LL | println!("Hello {}", "world"); | ^^^^^^^ @@ -36,7 +36,7 @@ LL + println!("Hello world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:30:26 + --> $DIR/print_literal.rs:34:26 | LL | println!("{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + println!("a literal {:.4}", 5); | error: literal with an empty format string - --> $DIR/print_literal.rs:35:25 + --> $DIR/print_literal.rs:40:25 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^ @@ -60,7 +60,7 @@ LL + println!("hello {1}", "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:35:34 + --> $DIR/print_literal.rs:40:34 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^ @@ -72,7 +72,7 @@ LL + println!("{0} world", "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:36:34 + --> $DIR/print_literal.rs:43:34 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^ @@ -84,7 +84,7 @@ LL + println!("world {0}", "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:36:25 + --> $DIR/print_literal.rs:43:25 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^ @@ -96,7 +96,7 @@ LL + println!("{1} hello", "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:39:35 + --> $DIR/print_literal.rs:48:35 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -108,7 +108,7 @@ LL + println!("hello {bar}", bar = "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:39:50 + --> $DIR/print_literal.rs:48:50 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -120,7 +120,7 @@ LL + println!("{foo} world", foo = "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:40:50 + --> $DIR/print_literal.rs:51:50 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -132,7 +132,7 @@ LL + println!("world {foo}", foo = "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:40:35 + --> $DIR/print_literal.rs:51:35 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ diff --git a/tests/ui/print_stderr.rs b/tests/ui/print_stderr.rs index fa07e74a7be47..109f43ffe25d1 100644 --- a/tests/ui/print_stderr.rs +++ b/tests/ui/print_stderr.rs @@ -2,7 +2,10 @@ fn main() { eprintln!("Hello"); + //~^ ERROR: use of `eprintln!` + //~| NOTE: `-D clippy::print-stderr` implied by `-D warnings` println!("This should not do anything"); eprint!("World"); + //~^ ERROR: use of `eprint!` print!("Nor should this"); } diff --git a/tests/ui/print_stderr.stderr b/tests/ui/print_stderr.stderr index 5af735af65769..0a56fbcec9999 100644 --- a/tests/ui/print_stderr.stderr +++ b/tests/ui/print_stderr.stderr @@ -7,7 +7,7 @@ LL | eprintln!("Hello"); = note: `-D clippy::print-stderr` implied by `-D warnings` error: use of `eprint!` - --> $DIR/print_stderr.rs:6:5 + --> $DIR/print_stderr.rs:8:5 | LL | eprint!("World"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index c9c3b925aa699..7ac6d2870c123 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -5,10 +5,16 @@ fn main() { println!("Hello"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` println!("Hello {}", "world"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!("Hello {} {}", "world", "#2"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!("{}", 1265); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!(); + //~^ ERROR: using `print!()` with a format string that ends in a single newline // these are all fine print!(""); @@ -31,6 +37,7 @@ fn main() { // #3514 print!("\\n"); println!("\\"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\\\\n"); // Raw strings @@ -39,9 +46,11 @@ fn main() { // Literal newlines should also fail println!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline ); println!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline ); @@ -50,6 +59,7 @@ fn main() { print!("foo\r\n"); // should fail println!("\\r"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index aaddbcd4be824..602d1ea3ec0e1 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -5,10 +5,16 @@ fn main() { print!("Hello\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` print!("Hello {}\n", "world"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("{}\n", 1265); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline // these are all fine print!(""); @@ -31,6 +37,7 @@ fn main() { // #3514 print!("\\n"); print!("\\\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\\\\n"); // Raw strings @@ -39,10 +46,12 @@ fn main() { // Literal newlines should also fail print!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline " " ); print!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline r" " ); @@ -52,6 +61,7 @@ fn main() { print!("foo\r\n"); // should fail print!("\\r\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 16cec220f8346..1c5f2548c89b6 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -12,7 +12,7 @@ LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:8:5 + --> $DIR/print_with_newline.rs:10:5 | LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:9:5 + --> $DIR/print_with_newline.rs:12:5 | LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:10:5 + --> $DIR/print_with_newline.rs:14:5 | LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:11:5 + --> $DIR/print_with_newline.rs:16:5 | LL | print!("\n"); | ^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:33:5 + --> $DIR/print_with_newline.rs:39:5 | LL | print!("\\\n"); | ^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:41:5 + --> $DIR/print_with_newline.rs:48:5 | LL | / print!( +LL | | LL | | " LL | | " LL | | ); @@ -83,13 +84,15 @@ LL | | ); help: use `println!` instead | LL ~ println!( +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:45:5 + --> $DIR/print_with_newline.rs:53:5 | LL | / print!( +LL | | LL | | r" LL | | " LL | | ); @@ -98,11 +101,12 @@ LL | | ); help: use `println!` instead | LL ~ println!( +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:54:5 + --> $DIR/print_with_newline.rs:63:5 | LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/proc_macro.rs b/tests/ui/proc_macro.rs index b77874034d0ba..e5b155dd1b8da 100644 --- a/tests/ui/proc_macro.rs +++ b/tests/ui/proc_macro.rs @@ -7,6 +7,7 @@ use proc_macro::TokenStream; #[allow(dead_code)] fn f() { let _x = 3.14; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found } #[proc_macro] diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index be02856b08896..91e2e7fd6427f 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -12,26 +12,33 @@ use std::borrow::Cow; use std::path::{Path, PathBuf}; fn do_vec(x: &Vec) { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do + //~| NOTE: `-D clippy::ptr-arg` implied by `-D warnings` //Nothing here } fn do_vec_mut(x: &mut Vec) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w //Nothing here } fn do_str(x: &String) { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d //Nothing here either } fn do_str_mut(x: &mut String) { + //~^ ERROR: writing `&mut String` instead of `&mut str` involves a new object where a slic //Nothing here either } fn do_path(x: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will //Nothing here either } fn do_path_mut(x: &mut PathBuf) { + //~^ ERROR: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a sl //Nothing here either } @@ -40,6 +47,7 @@ fn main() {} trait Foo { type Item; fn do_vec(x: &Vec); + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will fn do_item(x: &Self::Item); } @@ -53,6 +61,7 @@ impl Foo for Bar { } fn cloned(x: &Vec) -> Vec { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do let e = x.clone(); let f = e.clone(); // OK let g = x; @@ -62,6 +71,7 @@ fn cloned(x: &Vec) -> Vec { } fn str_cloned(x: &String) -> String { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -70,6 +80,7 @@ fn str_cloned(x: &String) -> String { } fn path_cloned(x: &PathBuf) -> PathBuf { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -78,6 +89,7 @@ fn path_cloned(x: &PathBuf) -> PathBuf { } fn false_positive_capacity(x: &Vec, y: &String) { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d let a = x.capacity(); let b = y.clone(); let c = y.as_str(); @@ -92,6 +104,7 @@ fn false_positive_capacity_too(x: &String) -> String { #[allow(dead_code)] fn test_cow_with_ref(c: &Cow<[i32]>) {} +//~^ ERROR: using a reference to `Cow` is not recommended fn test_cow(c: Cow<[i32]>) { let _c = c; @@ -121,6 +134,7 @@ mod issue_5644 { } fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice wi struct S; impl S { @@ -150,22 +164,26 @@ mod issue6509 { use std::path::PathBuf; fn foo_vec(vec: &Vec) { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will let _ = vec.clone().pop(); let _ = vec.clone().clone(); } fn foo_path(path: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice let _ = path.clone().pop(); let _ = path.clone().clone(); } fn foo_str(str: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice let _ = str.clone().pop(); let _ = str.clone().clone(); } } fn mut_vec_slice_methods(v: &mut Vec) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w v.copy_within(1..5, 10); } @@ -228,6 +246,9 @@ fn dyn_trait_ok(a: &mut Vec, b: &mut String, c: &mut PathBuf) { } fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w + //~| ERROR: writing `&mut String` instead of `&mut str` involves a new object where a slic + //~| ERROR: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a sl trait T {} impl T for Vec {} impl T for [U] {} @@ -251,14 +272,17 @@ mod issue_9218 { // This one has an anonymous lifetime so it's not okay fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } // These two's return types don't use use 'a so it's not okay fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 0e9dd760f453a..e5708ce3a7e2e 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -7,43 +7,43 @@ LL | fn do_vec(x: &Vec) { = note: `-D clippy::ptr-arg` implied by `-D warnings` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:18:18 + --> $DIR/ptr_arg.rs:20:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:22:14 + --> $DIR/ptr_arg.rs:25:14 | LL | fn do_str(x: &String) { | ^^^^^^^ help: change this to: `&str` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:26:18 + --> $DIR/ptr_arg.rs:30:18 | LL | fn do_str_mut(x: &mut String) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:30:15 + --> $DIR/ptr_arg.rs:35:15 | LL | fn do_path(x: &PathBuf) { | ^^^^^^^^ help: change this to: `&Path` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:34:19 + --> $DIR/ptr_arg.rs:40:19 | LL | fn do_path_mut(x: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:42:18 + --> $DIR/ptr_arg.rs:49:18 | LL | fn do_vec(x: &Vec); | ^^^^^^^^^ help: change this to: `&[i64]` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:55:14 + --> $DIR/ptr_arg.rs:63:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -51,6 +51,7 @@ LL | fn cloned(x: &Vec) -> Vec { help: change this to | LL ~ fn cloned(x: &[u8]) -> Vec { +LL | LL ~ let e = x.to_owned(); LL | let f = e.clone(); // OK LL | let g = x; @@ -60,7 +61,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:64:18 + --> $DIR/ptr_arg.rs:73:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -68,6 +69,7 @@ LL | fn str_cloned(x: &String) -> String { help: change this to | LL ~ fn str_cloned(x: &str) -> String { +LL | LL ~ let a = x.to_owned(); LL ~ let b = x.to_owned(); LL | let c = b.clone(); @@ -76,7 +78,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:72:19 + --> $DIR/ptr_arg.rs:82:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -84,6 +86,7 @@ LL | fn path_cloned(x: &PathBuf) -> PathBuf { help: change this to | LL ~ fn path_cloned(x: &Path) -> PathBuf { +LL | LL ~ let a = x.to_path_buf(); LL ~ let b = x.to_path_buf(); LL | let c = b.clone(); @@ -92,7 +95,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:80:44 + --> $DIR/ptr_arg.rs:91:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -100,25 +103,26 @@ LL | fn false_positive_capacity(x: &Vec, y: &String) { help: change this to | LL ~ fn false_positive_capacity(x: &Vec, y: &str) { +LL | LL | let a = x.capacity(); LL ~ let b = y.to_owned(); LL ~ let c = y; | error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:94:25 + --> $DIR/ptr_arg.rs:106:25 | LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} | ^^^^^^^^^^^ help: change this to: `&[i32]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:123:66 + --> $DIR/ptr_arg.rs:136:66 | LL | fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} | ^^^^^^^ help: change this to: `&str` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:152:21 + --> $DIR/ptr_arg.rs:166:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -126,12 +130,13 @@ LL | fn foo_vec(vec: &Vec) { help: change this to | LL ~ fn foo_vec(vec: &[u8]) { +LL | LL ~ let _ = vec.to_owned().pop(); LL ~ let _ = vec.to_owned().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:157:23 + --> $DIR/ptr_arg.rs:172:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -139,12 +144,13 @@ LL | fn foo_path(path: &PathBuf) { help: change this to | LL ~ fn foo_path(path: &Path) { +LL | LL ~ let _ = path.to_path_buf().pop(); LL ~ let _ = path.to_path_buf().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:162:21 + --> $DIR/ptr_arg.rs:178:21 | LL | fn foo_str(str: &PathBuf) { | ^^^^^^^^ @@ -152,48 +158,49 @@ LL | fn foo_str(str: &PathBuf) { help: change this to | LL ~ fn foo_str(str: &Path) { +LL | LL ~ let _ = str.to_path_buf().pop(); LL ~ let _ = str.to_path_buf().clone(); | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:168:29 + --> $DIR/ptr_arg.rs:185:29 | LL | fn mut_vec_slice_methods(v: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:17 + --> $DIR/ptr_arg.rs:248:17 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:35 + --> $DIR/ptr_arg.rs:248:35 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:51 + --> $DIR/ptr_arg.rs:248:51 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:253:39 + --> $DIR/ptr_arg.rs:274:39 | LL | fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { | ^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:258:36 + --> $DIR/ptr_arg.rs:280:36 | LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:261:40 + --> $DIR/ptr_arg.rs:284:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` diff --git a/tests/ui/pub_use.rs b/tests/ui/pub_use.rs index 65542bedec7bc..aef947e406a68 100644 --- a/tests/ui/pub_use.rs +++ b/tests/ui/pub_use.rs @@ -8,6 +8,7 @@ pub mod outer { } // should be linted pub use inner::Test; + //~^ ERROR: using `pub use` } // should not be linted diff --git a/tests/ui/question_mark_used.rs b/tests/ui/question_mark_used.rs index 8c3ef789697fc..715d7fab8eed2 100644 --- a/tests/ui/question_mark_used.rs +++ b/tests/ui/question_mark_used.rs @@ -9,6 +9,7 @@ fn other_function() -> Option { fn my_function() -> Option { other_function()?; + //~^ ERROR: question mark operator was used None } diff --git a/tests/ui/range.rs b/tests/ui/range.rs index 46edf0921bf2c..9541812b06911 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -4,6 +4,8 @@ fn main() { let v1 = vec![1, 2, 3]; let v2 = vec![4, 5]; let _x = v1.iter().zip(0..v1.len()); + //~^ ERROR: it is more idiomatic to use `v1.iter().enumerate()` + //~| NOTE: `-D clippy::range-zip-with-len` implied by `-D warnings` let _y = v1.iter().zip(0..v2.len()); // No error } diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs index 9cb7f48e75b54..1c9e9aa7ef47d 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/tests/ui/rc_clone_in_vec_init/arc.rs @@ -7,6 +7,8 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Arc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -15,12 +17,16 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance std::sync::Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -30,6 +36,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance Arc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr index 3e82d4e57b757..87f7ed56cd3c6 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:17:21 + --> $DIR/arc.rs:19:21 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,13 +46,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:23:13 + --> $DIR/arc.rs:27:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | std::sync::Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -76,13 +76,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:32:14 + --> $DIR/arc.rs:38:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_clone_in_vec_init/rc.rs b/tests/ui/rc_clone_in_vec_init/rc.rs index 5b7ac062ddc94..01cc433cbdae1 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/tests/ui/rc_clone_in_vec_init/rc.rs @@ -8,6 +8,8 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Rc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -16,12 +18,16 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Rc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance std::rc::Rc::new(Mutex::new({ let x = 1; dbg!(x); @@ -31,6 +37,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr index 278e497480483..3fa187f0b813d 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:18:21 + --> $DIR/rc.rs:20:21 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,13 +46,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:24:13 + --> $DIR/rc.rs:28:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | std::rc::Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -76,13 +76,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:33:14 + --> $DIR/rc.rs:39:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_clone_in_vec_init/weak.rs b/tests/ui/rc_clone_in_vec_init/weak.rs index 386cccd88f6c2..fd2895d40458a 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/tests/ui/rc_clone_in_vec_init/weak.rs @@ -8,10 +8,18 @@ fn main() {} fn should_warn_simple_case() { let v = vec![SyncWeak::::new(); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![UnSyncWeak::::new(); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance } fn should_warn_simple_case_with_big_indentation() { @@ -20,13 +28,19 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance Arc::downgrade(&Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -36,6 +50,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance Rc::downgrade(&Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/tests/ui/rc_clone_in_vec_init/weak.stderr b/tests/ui/rc_clone_in_vec_init/weak.stderr index ffb78590a0c88..9b60c22c28106 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:11:14 + --> $DIR/weak.rs:13:14 | LL | let v2 = vec![UnSyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:13:13 + --> $DIR/weak.rs:17:13 | LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:14:13 + --> $DIR/weak.rs:20:13 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:22:21 + --> $DIR/weak.rs:30:21 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -115,7 +115,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:23:22 + --> $DIR/weak.rs:33:22 | LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -138,13 +138,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:29:13 + --> $DIR/weak.rs:41:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | Arc::downgrade(&Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -168,13 +168,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:38:14 + --> $DIR/weak.rs:52:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Rc::downgrade(&Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index 432972bbc3175..40adb3ddce955 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -6,6 +6,7 @@ use std::sync::Mutex; pub struct MyStructWithPrivItem { foo: Rc>, + //~^ ERROR: usage of `Rc>` } pub struct MyStructWithPubItem { @@ -24,8 +25,11 @@ pub enum MyEnum { // All of these test should be trigger the lint because they are not // part of the public api fn test1(foo: Rc>) {} +//~^ ERROR: usage of `Rc>` fn test2(foo: Rc>) {} +//~^ ERROR: usage of `Rc>` fn test3(foo: Rc>>) {} +//~^ ERROR: usage of `Rc>` // All of these test should be allowed because they are part of the // public api and `avoid_breaking_exported_api` is `false` by default. diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr index cee3bd8b224dc..e21337b0f2ed4 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -8,7 +8,7 @@ LL | foo: Rc>, = note: `-D clippy::rc-mutex` implied by `-D warnings` error: usage of `Rc>` - --> $DIR/rc_mutex.rs:26:18 + --> $DIR/rc_mutex.rs:27:18 | LL | fn test1(foo: Rc>) {} | ^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn test1(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> $DIR/rc_mutex.rs:27:15 + --> $DIR/rc_mutex.rs:29:15 | LL | fn test2(foo: Rc>) {} | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn test2(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> $DIR/rc_mutex.rs:28:15 + --> $DIR/rc_mutex.rs:31:15 | LL | fn test3(foo: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/read_zero_byte_vec.rs b/tests/ui/read_zero_byte_vec.rs index 979955489b64e..76b9b98185119 100644 --- a/tests/ui/read_zero_byte_vec.rs +++ b/tests/ui/read_zero_byte_vec.rs @@ -19,29 +19,36 @@ fn test() -> io::Result<()> { // should lint let mut data = Vec::with_capacity(20); f.read_exact(&mut data).unwrap(); + //~^ ERROR: reading zero byte data to `Vec` + //~| NOTE: `-D clippy::read-zero-byte-vec` implied by `-D warnings` // should lint let mut data2 = Vec::with_capacity(cap); f.read_exact(&mut data2)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data3 = Vec::new(); f.read_exact(&mut data3)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data4 = vec![]; let _ = f.read(&mut data4)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let _ = { let mut data5 = Vec::new(); f.read(&mut data5) + //~^ ERROR: reading zero byte data to `Vec` }; // should lint let _ = { let mut data6: Vec = Default::default(); f.read(&mut data6) + //~^ ERROR: reading zero byte data to `Vec` }; // should not lint @@ -72,20 +79,24 @@ async fn test_futures(r: &mut R) { // should lint let mut data = Vec::new(); r.read(&mut data).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data2 = Vec::new(); r.read_exact(&mut data2).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` } async fn test_tokio(r: &mut R) { // should lint let mut data = Vec::new(); r.read(&mut data).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data2 = Vec::new(); r.read_exact(&mut data2).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` } fn main() {} diff --git a/tests/ui/read_zero_byte_vec.stderr b/tests/ui/read_zero_byte_vec.stderr index 4c7f605f4c2a5..b80a614eceba3 100644 --- a/tests/ui/read_zero_byte_vec.stderr +++ b/tests/ui/read_zero_byte_vec.stderr @@ -7,55 +7,55 @@ LL | f.read_exact(&mut data).unwrap(); = note: `-D clippy::read-zero-byte-vec` implied by `-D warnings` error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:25:5 + --> $DIR/read_zero_byte_vec.rs:27:5 | LL | f.read_exact(&mut data2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data2.resize(cap, 0); f.read_exact(&mut data2)?;` error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:29:5 + --> $DIR/read_zero_byte_vec.rs:32:5 | LL | f.read_exact(&mut data3)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:33:5 + --> $DIR/read_zero_byte_vec.rs:37:5 | LL | let _ = f.read(&mut data4)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:38:9 + --> $DIR/read_zero_byte_vec.rs:43:9 | LL | f.read(&mut data5) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:44:9 + --> $DIR/read_zero_byte_vec.rs:50:9 | LL | f.read(&mut data6) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:74:5 + --> $DIR/read_zero_byte_vec.rs:81:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:78:5 + --> $DIR/read_zero_byte_vec.rs:86:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:84:5 + --> $DIR/read_zero_byte_vec.rs:93:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:88:5 + --> $DIR/read_zero_byte_vec.rs:98:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/readonly_write_lock.fixed b/tests/ui/readonly_write_lock.fixed index ae622a4100bf3..76f4a43ae5300 100644 --- a/tests/ui/readonly_write_lock.fixed +++ b/tests/ui/readonly_write_lock.fixed @@ -14,11 +14,14 @@ fn main() { { let writer = lock.read().unwrap(); + //~^ ERROR: this write lock is used only for reading + //~| NOTE: `-D clippy::readonly-write-lock` implied by `-D warnings` dbg!(&writer); } { let writer = lock.read().unwrap(); + //~^ ERROR: this write lock is used only for reading accept_i32(*writer); } diff --git a/tests/ui/readonly_write_lock.rs b/tests/ui/readonly_write_lock.rs index 656b45787e8a0..3d1d3855fe129 100644 --- a/tests/ui/readonly_write_lock.rs +++ b/tests/ui/readonly_write_lock.rs @@ -14,11 +14,14 @@ fn main() { { let writer = lock.write().unwrap(); + //~^ ERROR: this write lock is used only for reading + //~| NOTE: `-D clippy::readonly-write-lock` implied by `-D warnings` dbg!(&writer); } { let writer = lock.write().unwrap(); + //~^ ERROR: this write lock is used only for reading accept_i32(*writer); } diff --git a/tests/ui/readonly_write_lock.stderr b/tests/ui/readonly_write_lock.stderr index e3d8fce7b2ce0..ca754e5c8f29d 100644 --- a/tests/ui/readonly_write_lock.stderr +++ b/tests/ui/readonly_write_lock.stderr @@ -7,7 +7,7 @@ LL | let writer = lock.write().unwrap(); = note: `-D clippy::readonly-write-lock` implied by `-D warnings` error: this write lock is used only for reading - --> $DIR/readonly_write_lock.rs:21:22 + --> $DIR/readonly_write_lock.rs:23:22 | LL | let writer = lock.write().unwrap(); | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()` diff --git a/tests/ui/recursive_format_impl.rs b/tests/ui/recursive_format_impl.rs index b92490b4c5234..b3eafc6dad7a9 100644 --- a/tests/ui/recursive_format_impl.rs +++ b/tests/ui/recursive_format_impl.rs @@ -29,6 +29,8 @@ impl B for A { impl fmt::Display for A { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.to_string()) + //~^ ERROR: using `self.to_string` in `fmt::Display` implementation will cause inf + //~| NOTE: `-D clippy::recursive-format-impl` implied by `-D warnings` } } @@ -73,6 +75,7 @@ struct G; impl std::fmt::Display for G { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -82,12 +85,14 @@ struct H; impl std::fmt::Display for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } impl std::fmt::Debug for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", &self) + //~^ ERROR: using `self` as `Debug` in `impl Debug` will cause infinite recursion } } @@ -97,6 +102,7 @@ struct H2; impl std::fmt::Display for H2 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &&&self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -171,12 +177,14 @@ impl std::ops::Deref for J { impl std::fmt::Display for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } impl std::fmt::Debug for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", &*self) + //~^ ERROR: using `self` as `Debug` in `impl Debug` will cause infinite recursion } } @@ -193,6 +201,7 @@ impl std::ops::Deref for J2 { impl std::fmt::Display for J2 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", *self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -209,6 +218,7 @@ impl std::ops::Deref for J3 { impl std::fmt::Display for J3 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", **&&*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -225,6 +235,7 @@ impl std::ops::Deref for J4 { impl std::fmt::Display for J4 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &&**&&*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } diff --git a/tests/ui/recursive_format_impl.stderr b/tests/ui/recursive_format_impl.stderr index 8a58b9a3b178b..c80e90ba61bc2 100644 --- a/tests/ui/recursive_format_impl.stderr +++ b/tests/ui/recursive_format_impl.stderr @@ -7,7 +7,7 @@ LL | write!(f, "{}", self.to_string()) = note: `-D clippy::recursive-format-impl` implied by `-D warnings` error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:75:9 + --> $DIR/recursive_format_impl.rs:77:9 | LL | write!(f, "{}", self) | ^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | write!(f, "{}", self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:84:9 + --> $DIR/recursive_format_impl.rs:87:9 | LL | write!(f, "{}", &self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | write!(f, "{}", &self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Debug` in `impl Debug` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:90:9 + --> $DIR/recursive_format_impl.rs:94:9 | LL | write!(f, "{:?}", &self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | write!(f, "{:?}", &self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:99:9 + --> $DIR/recursive_format_impl.rs:104:9 | LL | write!(f, "{}", &&&self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | write!(f, "{}", &&&self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:173:9 + --> $DIR/recursive_format_impl.rs:179:9 | LL | write!(f, "{}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | write!(f, "{}", &*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Debug` in `impl Debug` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:179:9 + --> $DIR/recursive_format_impl.rs:186:9 | LL | write!(f, "{:?}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | write!(f, "{:?}", &*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:195:9 + --> $DIR/recursive_format_impl.rs:203:9 | LL | write!(f, "{}", *self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | write!(f, "{}", *self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:211:9 + --> $DIR/recursive_format_impl.rs:220:9 | LL | write!(f, "{}", **&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL | write!(f, "{}", **&&*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:227:9 + --> $DIR/recursive_format_impl.rs:237:9 | LL | write!(f, "{}", &&**&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index 9eb58a3e53f6a..b3257c04f8296 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -14,14 +14,24 @@ mod outer_box { use std::sync::Arc; pub fn box_test6(foo: Box>) {} + //~^ ERROR: usage of `Box>` + //~| NOTE: `Rc` is already on the heap, `Box>` makes an extra allocation pub fn box_test7(foo: Box>) {} + //~^ ERROR: usage of `Box>` + //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation pub fn box_test8() -> Box>> { + //~^ ERROR: usage of `Box>>` + //~| NOTE: `Rc>` is already on the heap, `Box>>` makes an e unimplemented!(); } pub fn box_test9(foo: Box>) -> Box>> { + //~^ ERROR: usage of `Box>` + //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation + //~| ERROR: usage of `Box>>` + //~| NOTE: `Arc>` is already on the heap, `Box>>` makes an extra a unimplemented!(); } } @@ -33,14 +43,24 @@ mod outer_rc { use std::sync::Arc; pub fn rc_test5(a: Rc>) {} + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Box` is already on the heap, `Rc>` makes an extra allocati pub fn rc_test7(a: Rc>) {} + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocati pub fn rc_test8() -> Rc>> { + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an unimplemented!(); } pub fn rc_test9(foo: Rc>) -> Rc>> { + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocation + //~| ERROR: usage of `Rc>>` + //~| NOTE: `Arc>` is already on the heap, `Rc>>` makes an extra al unimplemented!(); } } @@ -52,14 +72,24 @@ mod outer_arc { use std::sync::Arc; pub fn arc_test5(a: Arc>) {} + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Box` is already on the heap, `Arc>` makes an extra allocat pub fn arc_test6(a: Arc>) {} + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocatio pub fn arc_test8() -> Arc>> { + //~^ ERROR: usage of `Arc>>` + //~| NOTE: `Box>` is already on the heap, `Arc>>` makes an unimplemented!(); } pub fn arc_test9(foo: Arc>) -> Arc>> { + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocation + //~| ERROR: usage of `Arc>>` + //~| NOTE: `Rc>` is already on the heap, `Arc>>` makes an extra all unimplemented!(); } } @@ -82,6 +112,8 @@ mod box_dyn { pub fn test_rc(_: Rc>) {} pub fn test_arc(_: Arc>) {} pub fn test_rc_box(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an ex } // https://github.com/rust-lang/rust-clippy/issues/8604 @@ -114,9 +146,17 @@ mod box_fat_ptr { pub fn test_box_custom(_: Box>) {} pub fn test_rc_box_str(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extra pub fn test_rc_box_slice(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes a pub fn test_rc_box_path(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extr pub fn test_rc_box_custom(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes } fn main() {} diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index a9a1eed702b43..233e3eb42896e 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -9,7 +9,7 @@ LL | pub fn box_test6(foo: Box>) {} = note: `-D clippy::redundant-allocation` implied by `-D warnings` error: usage of `Box>` - --> $DIR/redundant_allocation.rs:18:30 + --> $DIR/redundant_allocation.rs:20:30 | LL | pub fn box_test7(foo: Box>) {} | ^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | pub fn box_test7(foo: Box>) {} = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> $DIR/redundant_allocation.rs:20:27 + --> $DIR/redundant_allocation.rs:24:27 | LL | pub fn box_test8() -> Box>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | pub fn box_test8() -> Box>> { = help: consider using just `Box>` or `Rc>` error: usage of `Box>` - --> $DIR/redundant_allocation.rs:24:30 + --> $DIR/redundant_allocation.rs:30:30 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> $DIR/redundant_allocation.rs:24:46 + --> $DIR/redundant_allocation.rs:30:46 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box>` or `Arc>` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:35:24 + --> $DIR/redundant_allocation.rs:45:24 | LL | pub fn rc_test5(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | pub fn rc_test5(a: Rc>) {} = help: consider using just `Rc` or `Box` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:37:24 + --> $DIR/redundant_allocation.rs:49:24 | LL | pub fn rc_test7(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | pub fn rc_test7(a: Rc>) {} = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:39:26 + --> $DIR/redundant_allocation.rs:53:26 | LL | pub fn rc_test8() -> Rc>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | pub fn rc_test8() -> Rc>> { = help: consider using just `Rc>` or `Box>` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:43:29 + --> $DIR/redundant_allocation.rs:59:29 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:43:44 + --> $DIR/redundant_allocation.rs:59:44 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc>` or `Arc>` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:54:25 + --> $DIR/redundant_allocation.rs:74:25 | LL | pub fn arc_test5(a: Arc>) {} | ^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | pub fn arc_test5(a: Arc>) {} = help: consider using just `Arc` or `Box` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:56:25 + --> $DIR/redundant_allocation.rs:78:25 | LL | pub fn arc_test6(a: Arc>) {} | ^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | pub fn arc_test6(a: Arc>) {} = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> $DIR/redundant_allocation.rs:58:27 + --> $DIR/redundant_allocation.rs:82:27 | LL | pub fn arc_test8() -> Arc>> { | ^^^^^^^^^^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | pub fn arc_test8() -> Arc>> { = help: consider using just `Arc>` or `Box>` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:62:30 + --> $DIR/redundant_allocation.rs:88:30 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> $DIR/redundant_allocation.rs:62:45 + --> $DIR/redundant_allocation.rs:88:45 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc>` or `Rc>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:84:27 + --> $DIR/redundant_allocation.rs:114:27 | LL | pub fn test_rc_box(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | pub fn test_rc_box(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:116:31 + --> $DIR/redundant_allocation.rs:148:31 | LL | pub fn test_rc_box_str(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^ @@ -153,7 +153,7 @@ LL | pub fn test_rc_box_str(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:117:33 + --> $DIR/redundant_allocation.rs:151:33 | LL | pub fn test_rc_box_slice(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | pub fn test_rc_box_slice(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:118:32 + --> $DIR/redundant_allocation.rs:154:32 | LL | pub fn test_rc_box_path(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^ @@ -171,7 +171,7 @@ LL | pub fn test_rc_box_path(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:119:34 + --> $DIR/redundant_allocation.rs:157:34 | LL | pub fn test_rc_box_custom(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_closure_call_early.rs b/tests/ui/redundant_closure_call_early.rs index 5649d8dd14c48..6f9c9fd522241 100644 --- a/tests/ui/redundant_closure_call_early.rs +++ b/tests/ui/redundant_closure_call_early.rs @@ -7,9 +7,12 @@ fn main() { // lint here let mut k = (|m| m + 1)(i); + //~^ ERROR: try not to call a closure in the expression where it is declared + //~| NOTE: `-D clippy::redundant-closure-call` implied by `-D warnings` // lint here k = (|a, b| a * b)(1, 5); + //~^ ERROR: try not to call a closure in the expression where it is declared // don't lint these #[allow(clippy::needless_return)] diff --git a/tests/ui/redundant_closure_call_early.stderr b/tests/ui/redundant_closure_call_early.stderr index 2735e41738f0d..4a2ce175b5ce1 100644 --- a/tests/ui/redundant_closure_call_early.stderr +++ b/tests/ui/redundant_closure_call_early.stderr @@ -7,7 +7,7 @@ LL | let mut k = (|m| m + 1)(i); = note: `-D clippy::redundant-closure-call` implied by `-D warnings` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_early.rs:12:9 + --> $DIR/redundant_closure_call_early.rs:14:9 | LL | k = (|a, b| a * b)(1, 5); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_closure_call_late.rs b/tests/ui/redundant_closure_call_late.rs index 5612827bd3933..dc369c3bc092f 100644 --- a/tests/ui/redundant_closure_call_late.rs +++ b/tests/ui/redundant_closure_call_late.rs @@ -14,12 +14,16 @@ fn main() { // lint here let redun_closure = || 1; i = redun_closure(); + //~^ ERROR: closure called just once immediately after it was declared + //~| NOTE: `-D clippy::redundant-closure-call` implied by `-D warnings` // shadowed closures are supported, lint here let shadowed_closure = || 1; i = shadowed_closure(); + //~^ ERROR: closure called just once immediately after it was declared let shadowed_closure = || 2; i = shadowed_closure(); + //~^ ERROR: closure called just once immediately after it was declared // don't lint here let shadowed_closure = || 2; diff --git a/tests/ui/redundant_closure_call_late.stderr b/tests/ui/redundant_closure_call_late.stderr index 4eca43a2b599a..4a0fe95d57345 100644 --- a/tests/ui/redundant_closure_call_late.stderr +++ b/tests/ui/redundant_closure_call_late.stderr @@ -7,13 +7,13 @@ LL | i = redun_closure(); = note: `-D clippy::redundant-closure-call` implied by `-D warnings` error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:20:5 + --> $DIR/redundant_closure_call_late.rs:22:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:22:5 + --> $DIR/redundant_closure_call_late.rs:25:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs index 64f566735cd95..8bcf2ce5233da 100644 --- a/tests/ui/redundant_else.rs +++ b/tests/ui/redundant_else.rs @@ -8,6 +8,7 @@ fn main() { println!("Love your neighbor;"); break; } else { + //~^ ERROR: redundant else block println!("yet don't pull down your hedge."); } // continue @@ -15,6 +16,7 @@ fn main() { println!("He that lies down with Dogs,"); continue; } else { + //~^ ERROR: redundant else block println!("shall rise up with fleas."); } // match block @@ -24,6 +26,7 @@ fn main() { _ => return, } } else { + //~^ ERROR: redundant else block println!("You may delay, but time will not."); } } @@ -33,6 +36,7 @@ fn main() { } else if foo() { return; } else { + //~^ ERROR: redundant else block println!("A fat kitchen makes a lean will."); } // let binding outside of block @@ -40,6 +44,7 @@ fn main() { if foo() { return; } else { + //~^ ERROR: redundant else block 1 } }; @@ -50,6 +55,7 @@ fn main() { } else if foo() { return; } else { + //~^ ERROR: redundant else block 2 } }; @@ -59,6 +65,7 @@ fn main() { if foo() { return; } else { + //~^ ERROR: redundant else block 1 } } else { diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index de9d00a60246c..d6759422e953b 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -3,6 +3,7 @@ error: redundant else block | LL | } else { | ________________^ +LL | | LL | | println!("yet don't pull down your hedge."); LL | | } | |_________^ @@ -11,10 +12,11 @@ LL | | } = note: `-D clippy::redundant-else` implied by `-D warnings` error: redundant else block - --> $DIR/redundant_else.rs:17:16 + --> $DIR/redundant_else.rs:18:16 | LL | } else { | ________________^ +LL | | LL | | println!("shall rise up with fleas."); LL | | } | |_________^ @@ -22,10 +24,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:26:16 + --> $DIR/redundant_else.rs:28:16 | LL | } else { | ________________^ +LL | | LL | | println!("You may delay, but time will not."); LL | | } | |_________^ @@ -33,10 +36,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:35:12 + --> $DIR/redundant_else.rs:38:12 | LL | } else { | ____________^ +LL | | LL | | println!("A fat kitchen makes a lean will."); LL | | } | |_____^ @@ -44,10 +48,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:42:16 + --> $DIR/redundant_else.rs:46:16 | LL | } else { | ________________^ +LL | | LL | | 1 LL | | } | |_________^ @@ -55,10 +60,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:52:16 + --> $DIR/redundant_else.rs:57:16 | LL | } else { | ________________^ +LL | | LL | | 2 LL | | } | |_________^ @@ -66,10 +72,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:61:16 + --> $DIR/redundant_else.rs:67:16 | LL | } else { | ________________^ +LL | | LL | | 1 LL | | } | |_________^ diff --git a/tests/ui/redundant_static_lifetimes_multiple.rs b/tests/ui/redundant_static_lifetimes_multiple.rs index abaa146010c90..bfcab420b1f40 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.rs +++ b/tests/ui/redundant_static_lifetimes_multiple.rs @@ -2,13 +2,24 @@ // these are rustfixable, but run-rustfix tests cannot handle them const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static +//~^ ERROR: constants have by default a `'static` lifetime +//~| NOTE: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` +//~| ERROR: constants have by default a `'static` lifetime const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; +//~^ ERROR: constants have by default a `'static` lifetime +//~| ERROR: constants have by default a `'static` lifetime static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime fn main() {} diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr index 0ef9841e90620..297f505d96841 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -13,49 +13,49 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:6:29 + --> $DIR/redundant_static_lifetimes_multiple.rs:9:29 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:6:39 + --> $DIR/redundant_static_lifetimes_multiple.rs:9:39 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:8:40 + --> $DIR/redundant_static_lifetimes_multiple.rs:13:40 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:8:55 + --> $DIR/redundant_static_lifetimes_multiple.rs:13:55 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:10:26 + --> $DIR/redundant_static_lifetimes_multiple.rs:17:26 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:10:38 + --> $DIR/redundant_static_lifetimes_multiple.rs:17:38 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:12:37 + --> $DIR/redundant_static_lifetimes_multiple.rs:21:37 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:12:47 + --> $DIR/redundant_static_lifetimes_multiple.rs:21:47 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` diff --git a/tests/ui/redundant_type_annotations.rs b/tests/ui/redundant_type_annotations.rs index 09dbd3c9b39e1..acf53fea2bb2c 100644 --- a/tests/ui/redundant_type_annotations.rs +++ b/tests/ui/redundant_type_annotations.rs @@ -79,8 +79,12 @@ impl Pie { // Everything here should be lint let v: u32 = self.return_an_int(); + //~^ ERROR: redundant type annotation + //~| NOTE: `-D clippy::redundant-type-annotations` implied by `-D warnings` let v: &u32 = self.return_a_ref(); + //~^ ERROR: redundant type annotation let v: &Slice = self.return_a_ref_to_struct(); + //~^ ERROR: redundant type annotation } } @@ -153,36 +157,50 @@ fn test_functions() { // Everything here should be lint let _return: String = return_a_string(); + //~^ ERROR: redundant type annotation let _return: Pie = return_a_struct(); + //~^ ERROR: redundant type annotation let _return: Pizza = return_an_enum(); + //~^ ERROR: redundant type annotation let _return: u32 = return_an_int(); + //~^ ERROR: redundant type annotation let _return: String = String::new(); + //~^ ERROR: redundant type annotation let new_pie: Pie = Pie::new(); + //~^ ERROR: redundant type annotation let _return: u32 = new_pie.return_an_int(); + //~^ ERROR: redundant type annotation let _return: u32 = Pie::associated_return_an_int(); + //~^ ERROR: redundant type annotation let _return: String = Pie::associated_return_a_string(); + //~^ ERROR: redundant type annotation } fn test_simple_types() { // Everything here should be lint let _var: u32 = u32::MAX; + //~^ ERROR: redundant type annotation let _var: u32 = 5_u32; + //~^ ERROR: redundant type annotation let _var: &str = "test"; + //~^ ERROR: redundant type annotation let _var: &[u8] = b"test"; + //~^ ERROR: redundant type annotation let _var: bool = false; + //~^ ERROR: redundant type annotation } fn issue11190() {} diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index 988ebe6372268..927761c74372c 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -7,97 +7,97 @@ LL | let v: u32 = self.return_an_int(); = note: `-D clippy::redundant-type-annotations` implied by `-D warnings` error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:82:9 + --> $DIR/redundant_type_annotations.rs:84:9 | LL | let v: &u32 = self.return_a_ref(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:83:9 + --> $DIR/redundant_type_annotations.rs:86:9 | LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:155:5 + --> $DIR/redundant_type_annotations.rs:159:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:157:5 + --> $DIR/redundant_type_annotations.rs:162:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:159:5 + --> $DIR/redundant_type_annotations.rs:165:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:161:5 + --> $DIR/redundant_type_annotations.rs:168:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:163:5 + --> $DIR/redundant_type_annotations.rs:171:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:165:5 + --> $DIR/redundant_type_annotations.rs:174:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:167:5 + --> $DIR/redundant_type_annotations.rs:177:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:169:5 + --> $DIR/redundant_type_annotations.rs:180:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:171:5 + --> $DIR/redundant_type_annotations.rs:183:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:177:5 + --> $DIR/redundant_type_annotations.rs:190:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:179:5 + --> $DIR/redundant_type_annotations.rs:193:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:181:5 + --> $DIR/redundant_type_annotations.rs:196:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:183:5 + --> $DIR/redundant_type_annotations.rs:199:5 | LL | let _var: &[u8] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:185:5 + --> $DIR/redundant_type_annotations.rs:202:5 | LL | let _var: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index b14ae6841e908..a4444c95e33c7 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -29,12 +29,15 @@ fn main() { // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::ref-binding-to-reference` implied by `-D warnings` None => return, }; // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(*x); x @@ -45,17 +48,20 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m2!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, } // Err, reference to a &String let _ = |&ref x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; }; } // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; *x } @@ -63,6 +69,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; } } @@ -71,6 +78,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; } } diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 016feb103df6e..2505d7d500bf8 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -11,7 +11,7 @@ LL | Some(x) => &x, | ~ ~~ error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:37:14 + --> $DIR/ref_binding_to_reference.rs:39:14 | LL | Some(ref x) => { | ^^^^^ @@ -19,13 +19,14 @@ LL | Some(ref x) => { help: try | LL ~ Some(x) => { +LL | LL | f1(x); LL ~ f1(x); LL ~ &x | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:47:14 + --> $DIR/ref_binding_to_reference.rs:50:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -36,7 +37,7 @@ LL | Some(x) => m2!(&x), | ~ ~~ error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:52:15 + --> $DIR/ref_binding_to_reference.rs:56:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -44,11 +45,12 @@ LL | let _ = |&ref x: &&String| { help: try | LL ~ let _ = |&x: &&String| { +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:58:12 + --> $DIR/ref_binding_to_reference.rs:63:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -56,12 +58,13 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL | LL ~ let _: &&String = &x; LL ~ x | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:65:11 + --> $DIR/ref_binding_to_reference.rs:71:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -69,11 +72,12 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:73:11 + --> $DIR/ref_binding_to_reference.rs:80:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -81,6 +85,7 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &&String = &x; | diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs index 9c766ca329215..44001c45e99a9 100644 --- a/tests/ui/ref_option_ref.rs +++ b/tests/ui/ref_option_ref.rs @@ -8,27 +8,37 @@ static THRESHOLD: i32 = 10; static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~| NOTE: `-D clippy::ref-option-ref` implied by `-D warnings` const CONST_THRESHOLD: &i32 = &10; const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt type RefOptRefU32<'a> = &'a Option<&'a u32>; +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt type RefOptRef<'a, T> = &'a Option<&'a T>; +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt fn foo(data: &Option<&u32>) {} +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt fn bar(data: &u32) -> &Option<&u32> { + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt &None } struct StructRef<'a> { data: &'a Option<&'a u32>, + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt enum EnumRef<'a> { Variant1(u32), Variant2(&'a Option<&'a u32>), + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } trait RefOptTrait { @@ -38,12 +48,14 @@ trait RefOptTrait { impl RefOptTrait for u32 { type A = &'static Option<&'static Self>; + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to fn foo(&self, _: Self::A) {} } fn main() { let x: &Option<&u32> = &None; + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } fn issue9682(arg: &Option<&mut String>) { diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr index b61334758e854..430dd9c0e8dc8 100644 --- a/tests/ui/ref_option_ref.stderr +++ b/tests/ui/ref_option_ref.stderr @@ -7,61 +7,61 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); = note: `-D clippy::ref-option-ref` implied by `-D warnings` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:12:18 + --> $DIR/ref_option_ref.rs:14:18 | LL | const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:14:25 + --> $DIR/ref_option_ref.rs:17:25 | LL | type RefOptRefU32<'a> = &'a Option<&'a u32>; | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:15:25 + --> $DIR/ref_option_ref.rs:19:25 | LL | type RefOptRef<'a, T> = &'a Option<&'a T>; | ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:17:14 + --> $DIR/ref_option_ref.rs:22:14 | LL | fn foo(data: &Option<&u32>) {} | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:19:23 + --> $DIR/ref_option_ref.rs:25:23 | LL | fn bar(data: &u32) -> &Option<&u32> { | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:24:11 + --> $DIR/ref_option_ref.rs:31:11 | LL | data: &'a Option<&'a u32>, | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:27:32 + --> $DIR/ref_option_ref.rs:35:32 | LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:31:14 + --> $DIR/ref_option_ref.rs:40:14 | LL | Variant2(&'a Option<&'a u32>), | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:40:14 + --> $DIR/ref_option_ref.rs:50:14 | LL | type A = &'static Option<&'static Self>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:46:12 + --> $DIR/ref_option_ref.rs:57:12 | LL | let x: &Option<&u32> = &None; | ^^^^^^^^^^^^^ help: try: `Option<&u32>` diff --git a/tests/ui/ref_patterns.rs b/tests/ui/ref_patterns.rs index c51e0bc76efda..acd42ec89b62f 100644 --- a/tests/ui/ref_patterns.rs +++ b/tests/ui/ref_patterns.rs @@ -6,14 +6,17 @@ fn use_in_pattern() { match opt { None => {}, Some(ref opt) => {}, + //~^ ERROR: usage of ref pattern } } fn use_in_binding() { let x = 5; let ref y = x; + //~^ ERROR: usage of ref pattern } fn use_in_parameter(ref x: i32) {} +//~^ ERROR: usage of ref pattern fn main() {} diff --git a/tests/ui/ref_patterns.stderr b/tests/ui/ref_patterns.stderr index aa007782683a6..5883a7883e64d 100644 --- a/tests/ui/ref_patterns.stderr +++ b/tests/ui/ref_patterns.stderr @@ -8,7 +8,7 @@ LL | Some(ref opt) => {}, = note: `-D clippy::ref-patterns` implied by `-D warnings` error: usage of ref pattern - --> $DIR/ref_patterns.rs:14:9 + --> $DIR/ref_patterns.rs:15:9 | LL | let ref y = x; | ^^^^^ @@ -16,7 +16,7 @@ LL | let ref y = x; = help: consider using `&` for clarity instead error: usage of ref pattern - --> $DIR/ref_patterns.rs:17:21 + --> $DIR/ref_patterns.rs:19:21 | LL | fn use_in_parameter(ref x: i32) {} | ^^^^^ diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 89d1d94945454..5259d9ce04bbf 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -16,13 +16,19 @@ const NOT_A_REAL_REGEX: &str = "foobar"; fn syntax_error() { let pipe_in_wrong_position = Regex::new("|"); + //~^ ERROR: trivial regex let pipe_in_wrong_position_builder = RegexBuilder::new("|"); + //~^ ERROR: trivial regex let wrong_char_ranice = Regex::new("[z-a]"); + //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th + //~| NOTE: `-D clippy::invalid-regex` implied by `-D warnings` let some_unicode = Regex::new("[é-è]"); + //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th let some_regex = Regex::new(OPENING_PAREN); let binary_pipe_in_wrong_position = BRegex::new("|"); + //~^ ERROR: trivial regex let some_binary_regex = BRegex::new(OPENING_PAREN); let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); @@ -47,36 +53,49 @@ fn syntax_error() { let escaped_string_span = Regex::new("\\b\\c"); let aux_span = Regex::new("(?ixi)"); + //~^ ERROR: regex syntax error: duplicate flag let should_not_lint = Regex::new("(?u)."); let should_not_lint = BRegex::new("(?u)."); let invalid_utf8_should_not_lint = BRegex::new("(?-u)."); let invalid_utf8_should_lint = Regex::new("(?-u)."); + //~^ ERROR: regex syntax error: pattern can match invalid UTF-8 } fn trivial_regex() { let trivial_eq = Regex::new("^foobar$"); + //~^ ERROR: trivial regex let trivial_eq_builder = RegexBuilder::new("^foobar$"); + //~^ ERROR: trivial regex let trivial_starts_with = Regex::new("^foobar"); + //~^ ERROR: trivial regex let trivial_ends_with = Regex::new("foobar$"); + //~^ ERROR: trivial regex let trivial_contains = Regex::new("foobar"); + //~^ ERROR: trivial regex let trivial_contains = Regex::new(NOT_A_REAL_REGEX); + //~^ ERROR: trivial regex let trivial_backslash = Regex::new("a\\.b"); + //~^ ERROR: trivial regex // unlikely corner cases let trivial_empty = Regex::new(""); + //~^ ERROR: trivial regex let trivial_empty = Regex::new("^"); + //~^ ERROR: trivial regex let trivial_empty = Regex::new("^$"); + //~^ ERROR: trivial regex let binary_trivial_empty = BRegex::new("^$"); + //~^ ERROR: trivial regex // non-trivial regexes let non_trivial_dot = Regex::new("a.b"); diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 4f758799f73c6..ed5aa29e079e1 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -8,7 +8,7 @@ LL | let pipe_in_wrong_position = Regex::new("|"); = note: `-D clippy::trivial-regex` implied by `-D warnings` error: trivial regex - --> $DIR/regex.rs:19:60 + --> $DIR/regex.rs:20:60 | LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); | ^^^ @@ -16,7 +16,7 @@ LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); = help: the regex is unlikely to be useful as it is error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:20:42 + --> $DIR/regex.rs:22:42 | LL | let wrong_char_ranice = Regex::new("[z-a]"); | ^^^ @@ -24,7 +24,7 @@ LL | let wrong_char_ranice = Regex::new("[z-a]"); = note: `-D clippy::invalid-regex` implied by `-D warnings` error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:21:37 + --> $DIR/regex.rs:25:37 | LL | let some_unicode = Regex::new("[é-è]"); | ^^^ @@ -33,13 +33,13 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:23:33 + --> $DIR/regex.rs:28:33 | LL | let some_regex = Regex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ error: trivial regex - --> $DIR/regex.rs:25:53 + --> $DIR/regex.rs:30:53 | LL | let binary_pipe_in_wrong_position = BRegex::new("|"); | ^^^ @@ -50,7 +50,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:26:41 + --> $DIR/regex.rs:32:41 | LL | let some_binary_regex = BRegex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -59,7 +59,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:27:56 + --> $DIR/regex.rs:33:56 | LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:39:37 + --> $DIR/regex.rs:45:37 | LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:40:39 + --> $DIR/regex.rs:46:39 | LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ error: regex parse error: \b\c ^^ error: unrecognized escape sequence - --> $DIR/regex.rs:47:42 + --> $DIR/regex.rs:53:42 | LL | let escaped_string_span = Regex::new("\\b\\c"); | ^^^^^^^^ @@ -94,19 +94,19 @@ LL | let escaped_string_span = Regex::new("\\b\\c"); = help: consider using a raw string literal: `r".."` error: regex syntax error: duplicate flag - --> $DIR/regex.rs:49:34 + --> $DIR/regex.rs:55:34 | LL | let aux_span = Regex::new("(?ixi)"); | ^ ^ error: regex syntax error: pattern can match invalid UTF-8 - --> $DIR/regex.rs:54:53 + --> $DIR/regex.rs:61:53 | LL | let invalid_utf8_should_lint = Regex::new("(?-u)."); | ^ error: trivial regex - --> $DIR/regex.rs:58:33 + --> $DIR/regex.rs:66:33 | LL | let trivial_eq = Regex::new("^foobar$"); | ^^^^^^^^^^ @@ -114,7 +114,7 @@ LL | let trivial_eq = Regex::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:60:48 + --> $DIR/regex.rs:69:48 | LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); | ^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:62:42 + --> $DIR/regex.rs:72:42 | LL | let trivial_starts_with = Regex::new("^foobar"); | ^^^^^^^^^ @@ -130,7 +130,7 @@ LL | let trivial_starts_with = Regex::new("^foobar"); = help: consider using `str::starts_with` error: trivial regex - --> $DIR/regex.rs:64:40 + --> $DIR/regex.rs:75:40 | LL | let trivial_ends_with = Regex::new("foobar$"); | ^^^^^^^^^ @@ -138,7 +138,7 @@ LL | let trivial_ends_with = Regex::new("foobar$"); = help: consider using `str::ends_with` error: trivial regex - --> $DIR/regex.rs:66:39 + --> $DIR/regex.rs:78:39 | LL | let trivial_contains = Regex::new("foobar"); | ^^^^^^^^ @@ -146,7 +146,7 @@ LL | let trivial_contains = Regex::new("foobar"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:68:39 + --> $DIR/regex.rs:81:39 | LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); | ^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:70:40 + --> $DIR/regex.rs:84:40 | LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ @@ -162,7 +162,7 @@ LL | let trivial_backslash = Regex::new("a\\.b"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:73:36 + --> $DIR/regex.rs:88:36 | LL | let trivial_empty = Regex::new(""); | ^^ @@ -170,7 +170,7 @@ LL | let trivial_empty = Regex::new(""); = help: the regex is unlikely to be useful as it is error: trivial regex - --> $DIR/regex.rs:75:36 + --> $DIR/regex.rs:91:36 | LL | let trivial_empty = Regex::new("^"); | ^^^ @@ -178,7 +178,7 @@ LL | let trivial_empty = Regex::new("^"); = help: the regex is unlikely to be useful as it is error: trivial regex - --> $DIR/regex.rs:77:36 + --> $DIR/regex.rs:94:36 | LL | let trivial_empty = Regex::new("^$"); | ^^^^ @@ -186,7 +186,7 @@ LL | let trivial_empty = Regex::new("^$"); = help: consider using `str::is_empty` error: trivial regex - --> $DIR/regex.rs:79:44 + --> $DIR/regex.rs:97:44 | LL | let binary_trivial_empty = BRegex::new("^$"); | ^^^^ diff --git a/tests/ui/repl_uninit.rs b/tests/ui/repl_uninit.rs index f15b58e28de2e..01bdf79e64225 100644 --- a/tests/ui/repl_uninit.rs +++ b/tests/ui/repl_uninit.rs @@ -13,18 +13,22 @@ fn main() { // the following is UB if `might_panic` panics unsafe { let taken_v = mem::replace(&mut v, mem::uninitialized()); + //~^ ERROR: replacing with `mem::uninitialized()` + //~| NOTE: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } unsafe { let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); + //~^ ERROR: replacing with `mem::MaybeUninit::uninit().assume_init()` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } unsafe { let taken_v = mem::replace(&mut v, mem::zeroed()); + //~^ ERROR: replacing with `mem::zeroed()` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } @@ -37,5 +41,6 @@ fn main() { // this is still not OK, because uninit let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; + //~^ ERROR: replacing with `mem::uninitialized()` *uref = taken_u + 1; } diff --git a/tests/ui/repl_uninit.stderr b/tests/ui/repl_uninit.stderr index 09468eeaea4bf..6bbefcadb8639 100644 --- a/tests/ui/repl_uninit.stderr +++ b/tests/ui/repl_uninit.stderr @@ -7,13 +7,13 @@ LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); = note: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` error: replacing with `mem::MaybeUninit::uninit().assume_init()` - --> $DIR/repl_uninit.rs:21:23 + --> $DIR/repl_uninit.rs:23:23 | LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` error: replacing with `mem::zeroed()` - --> $DIR/repl_uninit.rs:27:23 + --> $DIR/repl_uninit.rs:30:23 | LL | let taken_v = mem::replace(&mut v, mem::zeroed()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let taken_v = mem::replace(&mut v, mem::zeroed()); = help: consider using a default value or the `take_mut` crate instead error: replacing with `mem::uninitialized()` - --> $DIR/repl_uninit.rs:39:28 + --> $DIR/repl_uninit.rs:43:28 | LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` diff --git a/tests/ui/rest_pat_in_fully_bound_structs.rs b/tests/ui/rest_pat_in_fully_bound_structs.rs index 086331af6b567..e25609f756017 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.rs +++ b/tests/ui/rest_pat_in_fully_bound_structs.rs @@ -20,13 +20,16 @@ fn main() { match a_struct { A { a: 5, b: 42, c: "", .. } => {}, // Lint - A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr + A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr _ => {}, } match a_struct { A { a: 5, b: 42, .. } => {}, A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr _ => {}, } diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr index e15633fb1a136..f8e4087823d61 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -8,15 +8,15 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:23:9 + --> $DIR/rest_pat_in_fully_bound_structs.rs:24:9 | -LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint +LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider removing `..` from this binding error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:29:9 + --> $DIR/rest_pat_in_fully_bound_structs.rs:31:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/result_large_err.rs b/tests/ui/result_large_err.rs index 1c12cebfd971a..14a1f7e1db57f 100644 --- a/tests/ui/result_large_err.rs +++ b/tests/ui/result_large_err.rs @@ -6,6 +6,7 @@ pub fn small_err() -> Result<(), u128> { } pub fn large_err() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -17,16 +18,19 @@ pub struct FullyDefinedLargeError { impl FullyDefinedLargeError { pub fn ret() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } pub fn struct_error() -> Result<(), FullyDefinedLargeError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } type Fdlr = std::result::Result; pub fn large_err_via_type_alias(x: T) -> Fdlr { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(x) } @@ -35,6 +39,7 @@ pub fn param_small_error() -> Result<(), (R, u128)> { } pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -46,6 +51,7 @@ pub enum LargeErrorVariants { impl LargeErrorVariants<()> { pub fn large_enum_error() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } @@ -58,12 +64,14 @@ enum MultipleLargeVariants { impl MultipleLargeVariants { fn large_enum_error() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } trait TraitForcesLargeError { fn large_error() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } @@ -83,6 +91,7 @@ pub union FullyDefinedUnionError { } pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -92,6 +101,7 @@ pub union UnionError { } pub fn param_large_union() -> Result<(), UnionError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -101,10 +111,12 @@ pub struct ArrayError { } pub fn array_error_subst() -> Result<(), ArrayError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } diff --git a/tests/ui/result_large_err.stderr b/tests/ui/result_large_err.stderr index c386edfd21571..c51531f55db67 100644 --- a/tests/ui/result_large_err.stderr +++ b/tests/ui/result_large_err.stderr @@ -8,7 +8,7 @@ LL | pub fn large_err() -> Result<(), [u8; 512]> { = note: `-D clippy::result-large-err` implied by `-D warnings` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:19:21 + --> $DIR/result_large_err.rs:20:21 | LL | pub fn ret() -> Result<(), Self> { | ^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -16,7 +16,7 @@ LL | pub fn ret() -> Result<(), Self> { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:24:26 + --> $DIR/result_large_err.rs:26:26 | LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -24,7 +24,7 @@ LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:29:45 + --> $DIR/result_large_err.rs:32:45 | LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { | ^^^^^^^ the `Err`-variant is at least 240 bytes @@ -32,7 +32,7 @@ LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:37:34 + --> $DIR/result_large_err.rs:41:34 | LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 256 bytes @@ -40,7 +40,7 @@ LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeErro = help: try reducing the size of `(u128, R, FullyDefinedLargeError)`, for example by boxing large elements or replacing it with `Box<(u128, R, FullyDefinedLargeError)>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:48:34 + --> $DIR/result_large_err.rs:53:34 | LL | _Omg([u8; 512]), | --------------- the largest variant contains at least 512 bytes @@ -51,7 +51,7 @@ LL | pub fn large_enum_error() -> Result<(), Self> { = help: try reducing the size of `LargeErrorVariants<()>`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:60:30 + --> $DIR/result_large_err.rs:66:30 | LL | _Biggest([u8; 1024]), | -------------------- the largest variant contains at least 1024 bytes @@ -64,7 +64,7 @@ LL | fn large_enum_error() -> Result<(), Self> { = help: try reducing the size of `MultipleLargeVariants`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:66:25 + --> $DIR/result_large_err.rs:73:25 | LL | fn large_error() -> Result<(), [u8; 512]> { | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -72,7 +72,7 @@ LL | fn large_error() -> Result<(), [u8; 512]> { = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:85:29 + --> $DIR/result_large_err.rs:93:29 | LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -80,7 +80,7 @@ LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { = help: try reducing the size of `FullyDefinedUnionError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:94:40 + --> $DIR/result_large_err.rs:103:40 | LL | pub fn param_large_union() -> Result<(), UnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -88,7 +88,7 @@ LL | pub fn param_large_union() -> Result<(), UnionError> { = help: try reducing the size of `UnionError`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:103:34 + --> $DIR/result_large_err.rs:113:34 | LL | pub fn array_error_subst() -> Result<(), ArrayError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes @@ -96,7 +96,7 @@ LL | pub fn array_error_subst() -> Result<(), ArrayError> { = help: try reducing the size of `ArrayError`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:107:31 + --> $DIR/result_large_err.rs:118:31 | LL | pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes diff --git a/tests/ui/result_map_unit_fn_unfixable.rs b/tests/ui/result_map_unit_fn_unfixable.rs index ae853554d325e..a4dfc8f293d3f 100644 --- a/tests/ui/result_map_unit_fn_unfixable.rs +++ b/tests/ui/result_map_unit_fn_unfixable.rs @@ -21,26 +21,33 @@ fn result_map_unit_fn() { let x = HasResult { field: Ok(10) }; x.field.map(|value| { do_nothing(value); do_nothing(value) }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t + //~| NOTE: `-D clippy::result-map-unit-fn` implied by `-D warnings` x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t // Suggestion for the let block should be `{ ... }` as it's too difficult to build a // proper suggestion for these cases x.field.map(|value| { + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t do_nothing(value); do_nothing(value) }); x.field.map(|value| { do_nothing(value); do_nothing(value); }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let variable name for them let res: Result = Ok(42).map(diverge); "12".parse::().map(diverge); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a function that returns let res: Result<(), usize> = Ok(plus_one(1)).map(do_nothing); // Should suggest `if let Ok(_y) ...` to not override the existing foo variable let y: Result = Ok(42); y.map(do_nothing); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a function that returns } fn main() {} diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index 75ec1ba80245e..ba17e22d0b359 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -9,7 +9,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:25:5 + --> $DIR/result_map_unit_fn_unfixable.rs:27:5 | LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,9 +17,10 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) | help: try: `if let Ok(value) = x.field { ... }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:29:5 + --> $DIR/result_map_unit_fn_unfixable.rs:32:5 | LL | // x.field.map(|value| { +LL | || LL | || do_nothing(value); LL | || do_nothing(value) LL | || }); @@ -28,7 +29,7 @@ LL | || }); | error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:33:5 + --> $DIR/result_map_unit_fn_unfixable.rs:37:5 | LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -36,7 +37,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | help: try: `if let Ok(value) = x.field { ... }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:37:5 + --> $DIR/result_map_unit_fn_unfixable.rs:42:5 | LL | "12".parse::().map(diverge); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -44,7 +45,7 @@ LL | "12".parse::().map(diverge); | help: try: `if let Ok(a) = "12".parse::() { diverge(a) }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:43:5 + --> $DIR/result_map_unit_fn_unfixable.rs:49:5 | LL | y.map(do_nothing); | ^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/result_unit_error.rs b/tests/ui/result_unit_error.rs index a4ec803024edf..f3159f2e95154 100644 --- a/tests/ui/result_unit_error.rs +++ b/tests/ui/result_unit_error.rs @@ -1,6 +1,7 @@ #![warn(clippy::result_unit_err)] pub fn returns_unit_error() -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Err(()) } @@ -10,8 +11,10 @@ fn private_unit_errors() -> Result { pub trait HasUnitError { fn get_that_error(&self) -> Result; + //~^ ERROR: this returns a `Result<_, ()>` fn get_this_one_too(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Err(()) } } @@ -30,6 +33,7 @@ pub struct UnitErrorHolder; impl UnitErrorHolder { pub fn unit_error(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } } @@ -39,6 +43,7 @@ pub mod issue_6546 { type ResInv = Result; pub fn should_lint() -> ResInv<(), usize> { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr index 8393a4bf03bc0..252c72481f513 100644 --- a/tests/ui/result_unit_error.stderr +++ b/tests/ui/result_unit_error.stderr @@ -8,7 +8,7 @@ LL | pub fn returns_unit_error() -> Result { = note: `-D clippy::result-unit-err` implied by `-D warnings` error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:12:5 + --> $DIR/result_unit_error.rs:13:5 | LL | fn get_that_error(&self) -> Result; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn get_that_error(&self) -> Result; = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:14:5 + --> $DIR/result_unit_error.rs:16:5 | LL | fn get_this_one_too(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn get_this_one_too(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:32:5 + --> $DIR/result_unit_error.rs:35:5 | LL | pub fn unit_error(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | pub fn unit_error(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:41:5 + --> $DIR/result_unit_error.rs:45:5 | LL | pub fn should_lint() -> ResInv<(), usize> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/return_self_not_must_use.rs b/tests/ui/return_self_not_must_use.rs index 9b33ad6d3f6b3..ec6f0feb8e656 100644 --- a/tests/ui/return_self_not_must_use.rs +++ b/tests/ui/return_self_not_must_use.rs @@ -6,6 +6,7 @@ pub struct Bar; pub trait Whatever { fn what(&self) -> Self; + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` // There should be no warning here! (returns a reference) fn what2(&self) -> &Self; } @@ -16,9 +17,11 @@ impl Bar { Self } pub fn foo(&self) -> Self { + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` Self } pub fn bar(self) -> Self { + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` self } // There should be no warning here! (private method) diff --git a/tests/ui/return_self_not_must_use.stderr b/tests/ui/return_self_not_must_use.stderr index 34932fe1c2c55..adfd6564d99cb 100644 --- a/tests/ui/return_self_not_must_use.stderr +++ b/tests/ui/return_self_not_must_use.stderr @@ -8,9 +8,10 @@ LL | fn what(&self) -> Self; = note: `-D clippy::return-self-not-must-use` implied by `-D warnings` error: missing `#[must_use]` attribute on a method returning `Self` - --> $DIR/return_self_not_must_use.rs:18:5 + --> $DIR/return_self_not_must_use.rs:19:5 | LL | / pub fn foo(&self) -> Self { +LL | | LL | | Self LL | | } | |_____^ @@ -18,9 +19,10 @@ LL | | } = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type error: missing `#[must_use]` attribute on a method returning `Self` - --> $DIR/return_self_not_must_use.rs:21:5 + --> $DIR/return_self_not_must_use.rs:23:5 | LL | / pub fn bar(self) -> Self { +LL | | LL | | self LL | | } | |_____^ diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/tests/ui/reversed_empty_ranges_loops_unfixable.rs index 50264ef68cc06..cd1701dd4bf23 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.rs @@ -3,10 +3,13 @@ fn main() { for i in 5..5 { + //~^ ERROR: this range is empty so it will yield no values + //~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings` println!("{}", i); } for i in (5 + 2)..(8 - 1) { + //~^ ERROR: this range is empty so it will yield no values println!("{}", i); } } diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr index 4490ff35f5a69..f644631749524 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr @@ -7,7 +7,7 @@ LL | for i in 5..5 { = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_unfixable.rs:9:14 + --> $DIR/reversed_empty_ranges_loops_unfixable.rs:11:14 | LL | for i in (5 + 2)..(8 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/reversed_empty_ranges_unfixable.rs b/tests/ui/reversed_empty_ranges_unfixable.rs index 264d3d1e95af4..16c1121ae0697 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_unfixable.rs @@ -6,9 +6,13 @@ const SOME_NUM: usize = 3; fn main() { let arr = [1, 2, 3, 4, 5]; let _ = &arr[3usize..=1usize]; + //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim + //~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings` let _ = &arr[SOME_NUM..1]; + //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim for _ in ANSWER..ANSWER {} + //~^ ERROR: this range is empty so it will yield no values // Should not be linted, see issue #5689 let _ = (42 + 10..42 + 10).map(|x| x / 2).find(|&x| x == 21); diff --git a/tests/ui/reversed_empty_ranges_unfixable.stderr b/tests/ui/reversed_empty_ranges_unfixable.stderr index f23d4eb0f9ca4..d32301742d346 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_unfixable.stderr @@ -7,13 +7,13 @@ LL | let _ = &arr[3usize..=1usize]; = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` error: this range is reversed and using it to index a slice will panic at run-time - --> $DIR/reversed_empty_ranges_unfixable.rs:9:18 + --> $DIR/reversed_empty_ranges_unfixable.rs:11:18 | LL | let _ = &arr[SOME_NUM..1]; | ^^^^^^^^^^^ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_unfixable.rs:11:14 + --> $DIR/reversed_empty_ranges_unfixable.rs:14:14 | LL | for _ in ANSWER..ANSWER {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/same_item_push.rs b/tests/ui/same_item_push.rs index af01a8df71b01..df9c2817f5083 100644 --- a/tests/ui/same_item_push.rs +++ b/tests/ui/same_item_push.rs @@ -21,28 +21,33 @@ fn main() { let item = 2; for _ in 5..=20 { vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec: Vec = Vec::new(); for _ in 0..15 { let item = 2; vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec: Vec = Vec::new(); for _ in 0..15 { vec.push(13); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec = Vec::new(); for _ in 0..20 { vec.push(VALUE); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec = Vec::new(); let item = VALUE; for _ in 0..20 { vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } // ** non-linted cases ** diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr index 1d1254d9fcc61..8e876e914cea9 100644 --- a/tests/ui/same_item_push.stderr +++ b/tests/ui/same_item_push.stderr @@ -8,7 +8,7 @@ LL | vec.push(item); = note: `-D clippy::same-item-push` implied by `-D warnings` error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:29:9 + --> $DIR/same_item_push.rs:30:9 | LL | vec.push(item); | ^^^ @@ -16,7 +16,7 @@ LL | vec.push(item); = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:34:9 + --> $DIR/same_item_push.rs:36:9 | LL | vec.push(13); | ^^^ @@ -24,7 +24,7 @@ LL | vec.push(13); = help: try using vec![13;SIZE] or vec.resize(NEW_SIZE, 13) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:39:9 + --> $DIR/same_item_push.rs:42:9 | LL | vec.push(VALUE); | ^^^ @@ -32,7 +32,7 @@ LL | vec.push(VALUE); = help: try using vec![VALUE;SIZE] or vec.resize(NEW_SIZE, VALUE) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:45:9 + --> $DIR/same_item_push.rs:49:9 | LL | vec.push(item); | ^^^ diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index f31a7e33c4b9e..1c166a19b0ad7 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -19,6 +19,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S { @@ -33,6 +34,7 @@ mod should_lint { impl S { fn clone() {} + //~^ ERROR: method's name is the same as an existing method in a trait } } @@ -43,6 +45,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S { @@ -57,6 +60,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} @@ -69,6 +73,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index 0c6908c09593f..b31d2537eadfc 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -5,57 +5,57 @@ LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:25:13 + --> $DIR/same_name_method.rs:26:13 | LL | fn foo() {} | ^^^^^^^^^^^ = note: `-D clippy::same-name-method` implied by `-D warnings` error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:35:13 + --> $DIR/same_name_method.rs:36:13 | LL | fn clone() {} | ^^^^^^^^^^^^^ | note: existing `clone` defined here - --> $DIR/same_name_method.rs:31:18 + --> $DIR/same_name_method.rs:32:18 | LL | #[derive(Clone)] | ^^^^^ = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:45:13 + --> $DIR/same_name_method.rs:47:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:49:13 + --> $DIR/same_name_method.rs:52:13 | LL | fn foo() {} | ^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:59:13 + --> $DIR/same_name_method.rs:62:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:62:9 + --> $DIR/same_name_method.rs:66:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:71:13 + --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:74:9 + --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs index a7f9fbaae7cf6..213bca6c45158 100644 --- a/tests/ui/self_assignment.rs +++ b/tests/ui/self_assignment.rs @@ -11,18 +11,30 @@ pub struct S<'a> { pub fn positives(mut a: usize, b: &mut u32, mut s: S) { a = a; + //~^ ERROR: self-assignment of `a` to `a` + //~| NOTE: `-D clippy::self-assignment` implied by `-D warnings` *b = *b; + //~^ ERROR: self-assignment of `*b` to `*b` s = s; + //~^ ERROR: self-assignment of `s` to `s` s.a = s.a; + //~^ ERROR: self-assignment of `s.a` to `s.a` s.b[9] = s.b[5 + 4]; + //~^ ERROR: self-assignment of `s.b[5 + 4]` to `s.b[9]` s.c[0][1] = s.c[0][1]; + //~^ ERROR: self-assignment of `s.c[0][1]` to `s.c[0][1]` s.b[a] = s.b[a]; + //~^ ERROR: self-assignment of `s.b[a]` to `s.b[a]` *s.e = *s.e; + //~^ ERROR: self-assignment of `*s.e` to `*s.e` s.b[a + 10] = s.b[10 + a]; + //~^ ERROR: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` let mut t = (0, 1); t.1 = t.1; + //~^ ERROR: self-assignment of `t.1` to `t.1` t.0 = (t.0); + //~^ ERROR: self-assignment of `(t.0)` to `t.0` } pub fn negatives_not_equal(mut a: usize, b: &mut usize, mut s: S) { diff --git a/tests/ui/self_assignment.stderr b/tests/ui/self_assignment.stderr index 25b8569fa3d0a..ecb62f96a93a6 100644 --- a/tests/ui/self_assignment.stderr +++ b/tests/ui/self_assignment.stderr @@ -7,61 +7,61 @@ LL | a = a; = note: `-D clippy::self-assignment` implied by `-D warnings` error: self-assignment of `*b` to `*b` - --> $DIR/self_assignment.rs:14:5 + --> $DIR/self_assignment.rs:16:5 | LL | *b = *b; | ^^^^^^^ error: self-assignment of `s` to `s` - --> $DIR/self_assignment.rs:15:5 + --> $DIR/self_assignment.rs:18:5 | LL | s = s; | ^^^^^ error: self-assignment of `s.a` to `s.a` - --> $DIR/self_assignment.rs:16:5 + --> $DIR/self_assignment.rs:20:5 | LL | s.a = s.a; | ^^^^^^^^^ error: self-assignment of `s.b[5 + 4]` to `s.b[9]` - --> $DIR/self_assignment.rs:17:5 + --> $DIR/self_assignment.rs:22:5 | LL | s.b[9] = s.b[5 + 4]; | ^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.c[0][1]` to `s.c[0][1]` - --> $DIR/self_assignment.rs:18:5 + --> $DIR/self_assignment.rs:24:5 | LL | s.c[0][1] = s.c[0][1]; | ^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.b[a]` to `s.b[a]` - --> $DIR/self_assignment.rs:19:5 + --> $DIR/self_assignment.rs:26:5 | LL | s.b[a] = s.b[a]; | ^^^^^^^^^^^^^^^ error: self-assignment of `*s.e` to `*s.e` - --> $DIR/self_assignment.rs:20:5 + --> $DIR/self_assignment.rs:28:5 | LL | *s.e = *s.e; | ^^^^^^^^^^^ error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` - --> $DIR/self_assignment.rs:21:5 + --> $DIR/self_assignment.rs:30:5 | LL | s.b[a + 10] = s.b[10 + a]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `t.1` to `t.1` - --> $DIR/self_assignment.rs:24:5 + --> $DIR/self_assignment.rs:34:5 | LL | t.1 = t.1; | ^^^^^^^^^ error: self-assignment of `(t.0)` to `t.0` - --> $DIR/self_assignment.rs:25:5 + --> $DIR/self_assignment.rs:36:5 | LL | t.0 = (t.0); | ^^^^^^^^^^^ diff --git a/tests/ui/self_named_constructors.rs b/tests/ui/self_named_constructors.rs index 356f701c98544..dc326b399481c 100644 --- a/tests/ui/self_named_constructors.rs +++ b/tests/ui/self_named_constructors.rs @@ -5,6 +5,8 @@ struct ShouldNotSpawn; impl ShouldSpawn { pub fn should_spawn() -> ShouldSpawn { + //~^ ERROR: constructor `should_spawn` has the same name as the type + //~| NOTE: `-D clippy::self-named-constructors` implied by `-D warnings` ShouldSpawn } diff --git a/tests/ui/self_named_constructors.stderr b/tests/ui/self_named_constructors.stderr index ba989f06dc80d..2024d86f91fcc 100644 --- a/tests/ui/self_named_constructors.stderr +++ b/tests/ui/self_named_constructors.stderr @@ -2,6 +2,8 @@ error: constructor `should_spawn` has the same name as the type --> $DIR/self_named_constructors.rs:7:5 | LL | / pub fn should_spawn() -> ShouldSpawn { +LL | | +LL | | LL | | ShouldSpawn LL | | } | |_____^ diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index 5843344eba89a..610a50020ec56 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -37,6 +37,8 @@ impl<'de> serde::de::Visitor<'de> for B { } fn visit_string(self, _v: String) -> Result + //~^ ERROR: you should not implement `visit_string` without also implementing `visit_s + //~| NOTE: `-D clippy::serde-api-misuse` implied by `-D warnings` where E: serde::de::Error, { diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index 760c9c9908a6f..a0d8217010e93 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -2,9 +2,10 @@ error: you should not implement `visit_string` without also implementing `visit_ --> $DIR/serde.rs:39:5 | LL | / fn visit_string(self, _v: String) -> Result +LL | | +LL | | LL | | where -LL | | E: serde::de::Error, -LL | | { +... | LL | | unimplemented!() LL | | } | |_____^ diff --git a/tests/ui/should_impl_trait/method_list_1.rs b/tests/ui/should_impl_trait/method_list_1.rs index 20d49f5a97634..85eed3f06f64a 100644 --- a/tests/ui/should_impl_trait/method_list_1.rs +++ b/tests/ui/should_impl_trait/method_list_1.rs @@ -23,62 +23,77 @@ impl T { // trait method list part 1, should lint all // ***************************************** pub fn add(self, other: T) -> T { + //~^ ERROR: method `add` can be confused for the standard trait method `std::ops::Add: unimplemented!() } pub fn as_mut(&mut self) -> &mut T { + //~^ ERROR: method `as_mut` can be confused for the standard trait method `std::conver unimplemented!() } pub fn as_ref(&self) -> &T { + //~^ ERROR: method `as_ref` can be confused for the standard trait method `std::conver unimplemented!() } pub fn bitand(self, rhs: T) -> T { + //~^ ERROR: method `bitand` can be confused for the standard trait method `std::ops::B unimplemented!() } pub fn bitor(self, rhs: Self) -> Self { + //~^ ERROR: method `bitor` can be confused for the standard trait method `std::ops::Bi unimplemented!() } pub fn bitxor(self, rhs: Self) -> Self { + //~^ ERROR: method `bitxor` can be confused for the standard trait method `std::ops::B unimplemented!() } pub fn borrow(&self) -> &str { + //~^ ERROR: method `borrow` can be confused for the standard trait method `std::borrow unimplemented!() } pub fn borrow_mut(&mut self) -> &mut str { + //~^ ERROR: method `borrow_mut` can be confused for the standard trait method `std::bo unimplemented!() } pub fn clone(&self) -> Self { + //~^ ERROR: method `clone` can be confused for the standard trait method `std::clone:: unimplemented!() } pub fn cmp(&self, other: &Self) -> Self { + //~^ ERROR: method `cmp` can be confused for the standard trait method `std::cmp::Ord: unimplemented!() } pub fn default() -> Self { + //~^ ERROR: method `default` can be confused for the standard trait method `std::defau unimplemented!() } pub fn deref(&self) -> &Self { + //~^ ERROR: method `deref` can be confused for the standard trait method `std::ops::De unimplemented!() } pub fn deref_mut(&mut self) -> &mut Self { + //~^ ERROR: method `deref_mut` can be confused for the standard trait method `std::ops unimplemented!() } pub fn div(self, rhs: Self) -> Self { + //~^ ERROR: method `div` can be confused for the standard trait method `std::ops::Div: unimplemented!() } pub fn drop(&mut self) { + //~^ ERROR: method `drop` can be confused for the standard trait method `std::ops::Dro unimplemented!() } // ********** diff --git a/tests/ui/should_impl_trait/method_list_1.stderr b/tests/ui/should_impl_trait/method_list_1.stderr index 161dd66b086ee..7ad00d14d0cda 100644 --- a/tests/ui/should_impl_trait/method_list_1.stderr +++ b/tests/ui/should_impl_trait/method_list_1.stderr @@ -2,6 +2,7 @@ error: method `add` can be confused for the standard trait method `std::ops::Add --> $DIR/method_list_1.rs:25:5 | LL | / pub fn add(self, other: T) -> T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -10,9 +11,10 @@ LL | | } = note: `-D clippy::should-implement-trait` implied by `-D warnings` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> $DIR/method_list_1.rs:29:5 + --> $DIR/method_list_1.rs:30:5 | LL | / pub fn as_mut(&mut self) -> &mut T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -20,9 +22,10 @@ LL | | } = help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref` - --> $DIR/method_list_1.rs:33:5 + --> $DIR/method_list_1.rs:35:5 | LL | / pub fn as_ref(&self) -> &T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -30,9 +33,10 @@ LL | | } = help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand` - --> $DIR/method_list_1.rs:37:5 + --> $DIR/method_list_1.rs:40:5 | LL | / pub fn bitand(self, rhs: T) -> T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -40,9 +44,10 @@ LL | | } = help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor` - --> $DIR/method_list_1.rs:41:5 + --> $DIR/method_list_1.rs:45:5 | LL | / pub fn bitor(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -50,9 +55,10 @@ LL | | } = help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor` - --> $DIR/method_list_1.rs:45:5 + --> $DIR/method_list_1.rs:50:5 | LL | / pub fn bitxor(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -60,9 +66,10 @@ LL | | } = help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow` - --> $DIR/method_list_1.rs:49:5 + --> $DIR/method_list_1.rs:55:5 | LL | / pub fn borrow(&self) -> &str { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -70,9 +77,10 @@ LL | | } = help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut` - --> $DIR/method_list_1.rs:53:5 + --> $DIR/method_list_1.rs:60:5 | LL | / pub fn borrow_mut(&mut self) -> &mut str { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -80,9 +88,10 @@ LL | | } = help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone` - --> $DIR/method_list_1.rs:57:5 + --> $DIR/method_list_1.rs:65:5 | LL | / pub fn clone(&self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -90,9 +99,10 @@ LL | | } = help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp` - --> $DIR/method_list_1.rs:61:5 + --> $DIR/method_list_1.rs:70:5 | LL | / pub fn cmp(&self, other: &Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,9 +110,10 @@ LL | | } = help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name error: method `default` can be confused for the standard trait method `std::default::Default::default` - --> $DIR/method_list_1.rs:65:5 + --> $DIR/method_list_1.rs:75:5 | LL | / pub fn default() -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -110,9 +121,10 @@ LL | | } = help: consider implementing the trait `std::default::Default` or choosing a less ambiguous method name error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref` - --> $DIR/method_list_1.rs:69:5 + --> $DIR/method_list_1.rs:80:5 | LL | / pub fn deref(&self) -> &Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -120,9 +132,10 @@ LL | | } = help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut` - --> $DIR/method_list_1.rs:73:5 + --> $DIR/method_list_1.rs:85:5 | LL | / pub fn deref_mut(&mut self) -> &mut Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -130,9 +143,10 @@ LL | | } = help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name error: method `div` can be confused for the standard trait method `std::ops::Div::div` - --> $DIR/method_list_1.rs:77:5 + --> $DIR/method_list_1.rs:90:5 | LL | / pub fn div(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -140,9 +154,10 @@ LL | | } = help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop` - --> $DIR/method_list_1.rs:81:5 + --> $DIR/method_list_1.rs:95:5 | LL | / pub fn drop(&mut self) { +LL | | LL | | unimplemented!() LL | | } | |_____^ diff --git a/tests/ui/should_impl_trait/method_list_2.rs b/tests/ui/should_impl_trait/method_list_2.rs index 27a66f2ed188f..550ec00726817 100644 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ b/tests/ui/should_impl_trait/method_list_2.rs @@ -24,62 +24,79 @@ impl T { // ***************************************** pub fn eq(&self, other: &Self) -> bool { + //~^ ERROR: method `eq` can be confused for the standard trait method `std::cmp::Parti unimplemented!() } pub fn from_iter(iter: T) -> Self { + //~^ ERROR: method `from_iter` can be confused for the standard trait method `std::ite unimplemented!() } pub fn from_str(s: &str) -> Result { + //~^ ERROR: method `from_str` can be confused for the standard trait method `std::str: unimplemented!() } pub fn hash(&self, state: &mut T) { + //~^ ERROR: method `hash` can be confused for the standard trait method `std::hash::Ha + //~| ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` unimplemented!() } pub fn index(&self, index: usize) -> &Self { + //~^ ERROR: method `index` can be confused for the standard trait method `std::ops::In unimplemented!() } pub fn index_mut(&mut self, index: usize) -> &mut Self { + //~^ ERROR: method `index_mut` can be confused for the standard trait method `std::ops unimplemented!() } pub fn into_iter(self) -> Self { + //~^ ERROR: method `into_iter` can be confused for the standard trait method `std::ite unimplemented!() } pub fn mul(self, rhs: Self) -> Self { + //~^ ERROR: method `mul` can be confused for the standard trait method `std::ops::Mul: unimplemented!() } pub fn neg(self) -> Self { + //~^ ERROR: method `neg` can be confused for the standard trait method `std::ops::Neg: unimplemented!() } pub fn next(&mut self) -> Option { + //~^ ERROR: method `next` can be confused for the standard trait method `std::iter::It unimplemented!() } pub fn not(self) -> Self { + //~^ ERROR: method `not` can be confused for the standard trait method `std::ops::Not: unimplemented!() } pub fn rem(self, rhs: Self) -> Self { + //~^ ERROR: method `rem` can be confused for the standard trait method `std::ops::Rem: unimplemented!() } pub fn shl(self, rhs: Self) -> Self { + //~^ ERROR: method `shl` can be confused for the standard trait method `std::ops::Shl: unimplemented!() } pub fn shr(self, rhs: Self) -> Self { + //~^ ERROR: method `shr` can be confused for the standard trait method `std::ops::Shr: unimplemented!() } pub fn sub(self, rhs: Self) -> Self { + //~^ ERROR: method `sub` can be confused for the standard trait method `std::ops::Sub: unimplemented!() } // ********** diff --git a/tests/ui/should_impl_trait/method_list_2.stderr b/tests/ui/should_impl_trait/method_list_2.stderr index a3bb05bf176ba..0073c899813f7 100644 --- a/tests/ui/should_impl_trait/method_list_2.stderr +++ b/tests/ui/should_impl_trait/method_list_2.stderr @@ -2,6 +2,7 @@ error: method `eq` can be confused for the standard trait method `std::cmp::Part --> $DIR/method_list_2.rs:26:5 | LL | / pub fn eq(&self, other: &Self) -> bool { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -10,9 +11,10 @@ LL | | } = note: `-D clippy::should-implement-trait` implied by `-D warnings` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` - --> $DIR/method_list_2.rs:30:5 + --> $DIR/method_list_2.rs:31:5 | LL | / pub fn from_iter(iter: T) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -20,9 +22,10 @@ LL | | } = help: consider implementing the trait `std::iter::FromIterator` or choosing a less ambiguous method name error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str` - --> $DIR/method_list_2.rs:34:5 + --> $DIR/method_list_2.rs:36:5 | LL | / pub fn from_str(s: &str) -> Result { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -30,9 +33,12 @@ LL | | } = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash` - --> $DIR/method_list_2.rs:38:5 + --> $DIR/method_list_2.rs:41:5 | LL | / pub fn hash(&self, state: &mut T) { +LL | | +LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -40,9 +46,10 @@ LL | | } = help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name error: method `index` can be confused for the standard trait method `std::ops::Index::index` - --> $DIR/method_list_2.rs:42:5 + --> $DIR/method_list_2.rs:48:5 | LL | / pub fn index(&self, index: usize) -> &Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -50,9 +57,10 @@ LL | | } = help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut` - --> $DIR/method_list_2.rs:46:5 + --> $DIR/method_list_2.rs:53:5 | LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -60,9 +68,10 @@ LL | | } = help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter` - --> $DIR/method_list_2.rs:50:5 + --> $DIR/method_list_2.rs:58:5 | LL | / pub fn into_iter(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -70,9 +79,10 @@ LL | | } = help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul` - --> $DIR/method_list_2.rs:54:5 + --> $DIR/method_list_2.rs:63:5 | LL | / pub fn mul(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -80,9 +90,10 @@ LL | | } = help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg` - --> $DIR/method_list_2.rs:58:5 + --> $DIR/method_list_2.rs:68:5 | LL | / pub fn neg(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -90,9 +101,10 @@ LL | | } = help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name error: method `next` can be confused for the standard trait method `std::iter::Iterator::next` - --> $DIR/method_list_2.rs:62:5 + --> $DIR/method_list_2.rs:73:5 | LL | / pub fn next(&mut self) -> Option { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,9 +112,10 @@ LL | | } = help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name error: method `not` can be confused for the standard trait method `std::ops::Not::not` - --> $DIR/method_list_2.rs:66:5 + --> $DIR/method_list_2.rs:78:5 | LL | / pub fn not(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -110,9 +123,10 @@ LL | | } = help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem` - --> $DIR/method_list_2.rs:70:5 + --> $DIR/method_list_2.rs:83:5 | LL | / pub fn rem(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -120,9 +134,10 @@ LL | | } = help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl` - --> $DIR/method_list_2.rs:74:5 + --> $DIR/method_list_2.rs:88:5 | LL | / pub fn shl(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -130,9 +145,10 @@ LL | | } = help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr` - --> $DIR/method_list_2.rs:78:5 + --> $DIR/method_list_2.rs:93:5 | LL | / pub fn shr(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -140,9 +156,10 @@ LL | | } = help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub` - --> $DIR/method_list_2.rs:82:5 + --> $DIR/method_list_2.rs:98:5 | LL | / pub fn sub(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -150,7 +167,7 @@ LL | | } = help: consider implementing the trait `std::ops::Sub` or choosing a less ambiguous method name error: this argument is a mutable reference, but not used mutably - --> $DIR/method_list_2.rs:38:31 + --> $DIR/method_list_2.rs:41:31 | LL | pub fn hash(&self, state: &mut T) { | ^^^^^^ help: consider changing to: `&T` diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 0dcf4b804cf8b..0305d895fc585 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -53,6 +53,8 @@ fn should_trigger_lint_with_mutex_guard_in_match_scrutinee() { // is preserved until the end of the match, but there is no clear indication that this is the // case. match mutex.lock().unwrap().foo() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().bar(); }, @@ -139,6 +141,8 @@ fn should_trigger_lint_with_wrapped_mutex() { // lifetime is not obvious. Additionally, it is not obvious from looking at the scrutinee that // the temporary contains such a type, making it potentially even more surprising. match s.lock_m().get_the_value() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -160,6 +164,8 @@ fn should_trigger_lint_with_double_wrapped_mutex() { // looking at the scrutinee that the temporary contains such a type, making it potentially even // more surprising. match s.lock_m_m().get_the_value() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -208,6 +214,8 @@ fn should_trigger_lint_for_vec() { // which have significant drops. The types with significant drops are also non-obvious when // reading the expression in the scrutinee. match counter.temp_increment().len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 2 => { let current_count = counter.i.load(Ordering::Relaxed); println!("Current count {}", current_count); @@ -231,6 +239,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { { match (mutex1.lock().unwrap().s.len(), true) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -240,6 +250,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex1.lock().unwrap().s.len(), true) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (_, 3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -250,6 +262,10 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~| ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (3, _, 3) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -261,6 +277,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { let mutex3 = Mutex::new(StateWithField { s: "three".to_owned() }); match mutex3.lock().unwrap().s.as_str() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior "three" => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -271,6 +289,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex3.lock().unwrap().s.as_str()) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (_, "three") => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -290,6 +310,8 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); match mutex.lock().unwrap().s.len() > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().s.len(); }, @@ -297,6 +319,8 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { }; match 1 < mutex.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().s.len(); }, @@ -315,6 +339,8 @@ fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op( }); match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { println!( "{} < {}", @@ -326,6 +352,8 @@ fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op( }; match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { println!( "{} >= {}", @@ -361,6 +389,8 @@ fn should_trigger_lint_for_return_from_closure_in_scrutinee() { // Should trigger lint because the temporary with a significant drop is returned from the // closure but not used directly in any match arms, so it has a potentially surprising lifetime. match get_mutex_guard().s.len() > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex1.lock().unwrap().s.len(); }, @@ -378,6 +408,8 @@ fn should_trigger_lint_for_return_from_match_in_scrutinee() { // significant drop is but not used directly in any match arms, so it has a potentially // surprising lifetime. match match i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap(), } @@ -404,6 +436,8 @@ fn should_trigger_lint_for_return_from_if_in_scrutinee() { // with a significant drop is but not used directly in any match arms, so it has a potentially // surprising lifetime. match if i > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior mutex1.lock().unwrap() } else { mutex2.lock().unwrap() @@ -458,6 +492,8 @@ fn should_trigger_lint_for_boxed_mutex_guard() { // Should trigger lint because a temporary Box holding a type with a significant drop in a match // scrutinee may have a potentially surprising lifetime. match s.lock().deref().deref() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 0 | 1 => println!("Value was less than 2"), _ => println!("Value is {}", s.lock().deref()), }; @@ -486,6 +522,8 @@ fn should_trigger_lint_for_boxed_mutex_guard_holding_string() { // Should trigger lint because a temporary Box holding a type with a significant drop in a match // scrutinee may have a potentially surprising lifetime. match s.lock().deref().deref() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior matcher => println!("Value is {}", s.lock().deref()), _ => println!("Value was not a match"), }; @@ -505,24 +543,32 @@ fn should_trigger_lint_in_assign_expr() { let mut i = 100; match mutex.lock().unwrap().i = i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i = mutex.lock().unwrap().i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match mutex.lock().unwrap().i += 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i += mutex.lock().unwrap().i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, @@ -586,6 +632,8 @@ impl ResultReturner { fn should_trigger_lint_for_non_ref_move_and_clone_suggestion() { let rwlock = RwLock::::new(ResultReturner { s: "1".to_string() }); match rwlock.read().unwrap().to_number() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior Ok(n) => println!("Converted to number: {}", n), Err(e) => println!("Could not convert {} to number", e), }; @@ -596,6 +644,8 @@ fn should_trigger_lint_for_read_write_lock_for_loop() { // designed to look for. let rwlock = RwLock::>::new(vec!["1".to_string()]); for s in rwlock.read().unwrap().iter() { + //~^ ERROR: temporary with significant `Drop` in `for` loop condition will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior println!("{}", s); } } @@ -611,6 +661,8 @@ fn should_trigger_lint_without_significant_drop_in_arm() { // is preserved until the end of the match, but there is no clear indication that this is the // case. match mutex.lock().unwrap().foo() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => do_bar(&mutex), false => {}, }; diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index b56ace200a8ba..6ead59b072580 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -3,7 +3,7 @@ error: temporary with significant `Drop` in `match` scrutinee will live until th | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().bar(); | --------------------- another value with significant `Drop` created here ... @@ -19,7 +19,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:141:11 + --> $DIR/significant_drop_in_scrutinee.rs:143:11 | LL | match s.lock_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:162:11 + --> $DIR/significant_drop_in_scrutinee.rs:166:11 | LL | match s.lock_m_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:210:11 + --> $DIR/significant_drop_in_scrutinee.rs:216:11 | LL | match counter.temp_increment().len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:233:16 + --> $DIR/significant_drop_in_scrutinee.rs:241:16 | LL | match (mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL ~ match (value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:242:22 + --> $DIR/significant_drop_in_scrutinee.rs:252:22 | LL | match (true, mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL ~ match (true, value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:252:16 + --> $DIR/significant_drop_in_scrutinee.rs:264:16 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:252:54 + --> $DIR/significant_drop_in_scrutinee.rs:264:54 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -153,7 +153,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:263:15 + --> $DIR/significant_drop_in_scrutinee.rs:279:15 | LL | match mutex3.lock().unwrap().s.as_str() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:273:22 + --> $DIR/significant_drop_in_scrutinee.rs:291:22 | LL | match (true, mutex3.lock().unwrap().s.as_str()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,11 +185,11 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:292:11 + --> $DIR/significant_drop_in_scrutinee.rs:312:11 | LL | match mutex.lock().unwrap().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().s.len(); | --------------------- another value with significant `Drop` created here ... @@ -204,11 +204,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:299:11 + --> $DIR/significant_drop_in_scrutinee.rs:321:11 | LL | match 1 < mutex.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().s.len(); | --------------------- another value with significant `Drop` created here ... @@ -223,7 +223,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:317:11 + --> $DIR/significant_drop_in_scrutinee.rs:341:11 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -244,7 +244,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:328:11 + --> $DIR/significant_drop_in_scrutinee.rs:354:11 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,11 +265,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:363:11 + --> $DIR/significant_drop_in_scrutinee.rs:391:11 | LL | match get_mutex_guard().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex1.lock().unwrap().s.len(); | ---------------------- another value with significant `Drop` created here ... @@ -284,14 +284,14 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:380:11 + --> $DIR/significant_drop_in_scrutinee.rs:410:11 | LL | match match i { | ___________^ +LL | | +LL | | LL | | 100 => mutex1.lock().unwrap(), -LL | | _ => mutex2.lock().unwrap(), -LL | | } -LL | | .s +... | LL | | .len() LL | | > 1 | |___________^ @@ -306,6 +306,8 @@ LL | }; help: try moving the temporary above the match | LL ~ let value = match i { +LL + +LL + LL + 100 => mutex1.lock().unwrap(), LL + _ => mutex2.lock().unwrap(), LL + } @@ -316,13 +318,13 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:406:11 + --> $DIR/significant_drop_in_scrutinee.rs:438:11 | LL | match if i > 1 { | ___________^ +LL | | +LL | | LL | | mutex1.lock().unwrap() -LL | | } else { -LL | | mutex2.lock().unwrap() ... | LL | | .len() LL | | > 1 @@ -338,6 +340,8 @@ LL | }; help: try moving the temporary above the match | LL ~ let value = if i > 1 { +LL + +LL + LL + mutex1.lock().unwrap() LL + } else { LL + mutex2.lock().unwrap() @@ -349,11 +353,11 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:460:11 + --> $DIR/significant_drop_in_scrutinee.rs:494:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ -LL | 0 | 1 => println!("Value was less than 2"), +... LL | _ => println!("Value is {}", s.lock().deref()), | ---------------- another value with significant `Drop` created here LL | }; @@ -367,10 +371,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:488:11 + --> $DIR/significant_drop_in_scrutinee.rs:524:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ +... LL | matcher => println!("Value is {}", s.lock().deref()), | ---------------- another value with significant `Drop` created here LL | _ => println!("Value was not a match"), @@ -380,11 +385,11 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:507:11 + --> $DIR/significant_drop_in_scrutinee.rs:545:11 | LL | match mutex.lock().unwrap().i = i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -399,11 +404,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:513:11 + --> $DIR/significant_drop_in_scrutinee.rs:553:11 | LL | match i = mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -418,11 +423,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:519:11 + --> $DIR/significant_drop_in_scrutinee.rs:561:11 | LL | match mutex.lock().unwrap().i += 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -437,11 +442,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:525:11 + --> $DIR/significant_drop_in_scrutinee.rs:569:11 | LL | match i += mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -456,7 +461,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:588:11 + --> $DIR/significant_drop_in_scrutinee.rs:634:11 | LL | match rwlock.read().unwrap().to_number() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -467,18 +472,18 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> $DIR/significant_drop_in_scrutinee.rs:598:14 + --> $DIR/significant_drop_in_scrutinee.rs:646:14 | LL | for s in rwlock.read().unwrap().iter() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | println!("{}", s); +... LL | } | - temporary lives until here | = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:613:11 + --> $DIR/significant_drop_in_scrutinee.rs:663:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index c21225d153bd6..c5a941316da30 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -19,8 +19,10 @@ fn main() { let apple: i32; let bpple: i32; + //~^ ERROR: binding's name is too similar to existing binding let cpple: i32; + //~^ ERROR: binding's name is too similar to existing binding let a_bar: i32; let b_bar: i32; @@ -45,10 +47,12 @@ fn main() { let blubx: i32; let bluby: i32; + //~^ ERROR: binding's name is too similar to existing binding let cake: i32; let cakes: i32; let coke: i32; + //~^ ERROR: binding's name is too similar to existing binding match 5 { cheese @ 1 => {}, @@ -67,10 +71,12 @@ fn main() { let xyz1abc: i32; let xyz2abc: i32; let xyzeabc: i32; + //~^ ERROR: binding's name is too similar to existing binding let parser: i32; let parsed: i32; let parsee: i32; + //~^ ERROR: binding's name is too similar to existing binding let setter: i32; let getter: i32; @@ -92,6 +98,7 @@ fn foo() { let Foo { apple: spring, bpple: sprang, + //~^ ERROR: binding's name is too similar to existing binding } = unimplemented!(); } diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 43c5cee4b4577..059e26d589113 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -12,7 +12,7 @@ LL | let apple: i32; = note: `-D clippy::similar-names` implied by `-D warnings` error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:23:9 + --> $DIR/similar_names.rs:24:9 | LL | let cpple: i32; | ^^^^^ @@ -24,61 +24,61 @@ LL | let apple: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:47:9 + --> $DIR/similar_names.rs:49:9 | LL | let bluby: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:46:9 + --> $DIR/similar_names.rs:48:9 | LL | let blubx: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:51:9 + --> $DIR/similar_names.rs:54:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:49:9 + --> $DIR/similar_names.rs:52:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:69:9 + --> $DIR/similar_names.rs:73:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:67:9 + --> $DIR/similar_names.rs:71:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:73:9 + --> $DIR/similar_names.rs:78:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:71:9 + --> $DIR/similar_names.rs:76:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:94:16 + --> $DIR/similar_names.rs:100:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:93:16 + --> $DIR/similar_names.rs:99:16 | LL | apple: spring, | ^^^^^^ diff --git a/tests/ui/single_char_lifetime_names.rs b/tests/ui/single_char_lifetime_names.rs index 69c5b236f7cf8..6731b5b13564d 100644 --- a/tests/ui/single_char_lifetime_names.rs +++ b/tests/ui/single_char_lifetime_names.rs @@ -3,6 +3,8 @@ // Lifetimes should only be linted when they're introduced struct DiagnosticCtx<'a, 'b> +//~^ ERROR: single-character lifetime names are likely uninformative +//~| ERROR: single-character lifetime names are likely uninformative where 'a: 'b, { @@ -12,6 +14,8 @@ where // Only the lifetimes on the `impl`'s generics should be linted impl<'a, 'b> DiagnosticCtx<'a, 'b> { + //~^ ERROR: single-character lifetime names are likely uninformative + //~| ERROR: single-character lifetime names are likely uninformative fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> { Self { _source: source, @@ -32,6 +36,7 @@ impl<'src, 'unit> DiagnosticCtx<'src, 'unit> { // Only 'a should be linted here fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { + //~^ ERROR: single-character lifetime names are likely uninformative base.split_once(other) .map(|(left, right)| (left, Some(right))) .unwrap_or((base, None)) diff --git a/tests/ui/single_char_lifetime_names.stderr b/tests/ui/single_char_lifetime_names.stderr index bfe6d44b5898d..19bea0ae0c23b 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -16,7 +16,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:14:6 + --> $DIR/single_char_lifetime_names.rs:16:6 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -24,7 +24,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:14:10 + --> $DIR/single_char_lifetime_names.rs:16:10 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -32,7 +32,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:34:15 + --> $DIR/single_char_lifetime_names.rs:38:15 | LL | fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { | ^^ diff --git a/tests/ui/single_component_path_imports_nested_first.rs b/tests/ui/single_component_path_imports_nested_first.rs index f9dec47e64022..b4a1ce1d6aec4 100644 --- a/tests/ui/single_component_path_imports_nested_first.rs +++ b/tests/ui/single_component_path_imports_nested_first.rs @@ -2,6 +2,8 @@ #![allow(unused_imports)] //@no-rustfix use regex; +//~^ ERROR: this import is redundant +//~| NOTE: `-D clippy::single-component-path-imports` implied by `-D warnings` use serde as edres; @@ -13,6 +15,8 @@ fn main() { mod root_nested_use_mod { use {regex, serde}; + //~^ ERROR: this import is redundant + //~| ERROR: this import is redundant #[allow(dead_code)] fn root_nested_use_mod() {} } diff --git a/tests/ui/single_component_path_imports_nested_first.stderr b/tests/ui/single_component_path_imports_nested_first.stderr index ff148355e1215..b2a0521f7d143 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -7,7 +7,7 @@ LL | use regex; = note: `-D clippy::single-component-path-imports` implied by `-D warnings` error: this import is redundant - --> $DIR/single_component_path_imports_nested_first.rs:15:10 + --> $DIR/single_component_path_imports_nested_first.rs:17:10 | LL | use {regex, serde}; | ^^^^^ @@ -15,7 +15,7 @@ LL | use {regex, serde}; = help: remove this import error: this import is redundant - --> $DIR/single_component_path_imports_nested_first.rs:15:17 + --> $DIR/single_component_path_imports_nested_first.rs:17:17 | LL | use {regex, serde}; | ^^^^^ diff --git a/tests/ui/size_of_in_element_count/expressions.rs b/tests/ui/size_of_in_element_count/expressions.rs index 2594e8fa6ad3e..91b7ea3922c55 100644 --- a/tests/ui/size_of_in_element_count/expressions.rs +++ b/tests/ui/size_of_in_element_count/expressions.rs @@ -13,12 +13,15 @@ fn main() { // Count expression involving multiplication of size_of (Should trigger the lint) unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving nested multiplications of size_of (Should trigger the lint) unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving divisions of size_of (Should trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving divisions by size_of (Should not trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / size_of::()) }; @@ -28,6 +31,7 @@ fn main() { // Count expression involving recursive divisions by size_of (Should trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // No size_of calls (Should not trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), SIZE) }; diff --git a/tests/ui/size_of_in_element_count/expressions.stderr b/tests/ui/size_of_in_element_count/expressions.stderr index 037f695f3ee91..0c31c3a1f4b32 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -8,7 +8,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::( = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:18:62 + --> $DIR/expressions.rs:19:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * si = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:21:47 + --> $DIR/expressions.rs:23:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:30:47 + --> $DIR/expressions.rs:33:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/size_of_in_element_count/functions.rs b/tests/ui/size_of_in_element_count/functions.rs index 09d08ac37dce5..3501cbdf81cfb 100644 --- a/tests/ui/size_of_in_element_count/functions.rs +++ b/tests/ui/size_of_in_element_count/functions.rs @@ -16,31 +16,52 @@ fn main() { // Count is size_of (Should trigger the lint) unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().sub(size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_ptr().wrapping_sub(size_of::()); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_ptr().add(size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_mut_ptr().wrapping_add(size_of::()); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_ptr().offset(size_of::() as isize) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_mut_ptr().wrapping_offset(size_of::() as isize); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` } diff --git a/tests/ui/size_of_in_element_count/functions.stderr b/tests/ui/size_of_in_element_count/functions.stderr index 4351e6a14fe58..4901d11736d5e 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -8,7 +8,7 @@ LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of: = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:19:62 + --> $DIR/functions.rs:20:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:21:49 + --> $DIR/functions.rs:23:49 | LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:22:64 + --> $DIR/functions.rs:25:64 | LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of:: $DIR/functions.rs:23:51 + --> $DIR/functions.rs:27:51 | LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:24:66 + --> $DIR/functions.rs:29:66 | LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::< = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:26:47 + --> $DIR/functions.rs:32:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:27:47 + --> $DIR/functions.rs:34:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:29:46 + --> $DIR/functions.rs:37:46 | LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:30:47 + --> $DIR/functions.rs:39:47 | LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:32:66 + --> $DIR/functions.rs:42:66 | LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::< = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:34:46 + --> $DIR/functions.rs:45:46 | LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:35:38 + --> $DIR/functions.rs:47:38 | LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:37:49 + --> $DIR/functions.rs:50:49 | LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:38:41 + --> $DIR/functions.rs:52:41 | LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:40:33 + --> $DIR/functions.rs:55:33 | LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:41:29 + --> $DIR/functions.rs:57:29 | LL | y.as_ptr().wrapping_sub(size_of::()); | ^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | y.as_ptr().wrapping_sub(size_of::()); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:42:29 + --> $DIR/functions.rs:59:29 | LL | unsafe { y.as_ptr().add(size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | unsafe { y.as_ptr().add(size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:43:33 + --> $DIR/functions.rs:61:33 | LL | y.as_mut_ptr().wrapping_add(size_of::()); | ^^^^^^^^^^^^^^^ @@ -152,7 +152,7 @@ LL | y.as_mut_ptr().wrapping_add(size_of::()); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:44:32 + --> $DIR/functions.rs:63:32 | LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:45:36 + --> $DIR/functions.rs:65:36 | LL | y.as_mut_ptr().wrapping_offset(size_of::() as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/size_of_ref.rs b/tests/ui/size_of_ref.rs index 1e83ab82907d3..670c6c080eca6 100644 --- a/tests/ui/size_of_ref.rs +++ b/tests/ui/size_of_ref.rs @@ -11,7 +11,9 @@ fn main() { size_of_val(y); // no lint size_of_val(&&x); + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference size_of_val(&y); + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference } struct S { @@ -23,5 +25,6 @@ impl S { /// Get size of object including `self`, in bytes. pub fn size(&self) -> usize { std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference } } diff --git a/tests/ui/size_of_ref.stderr b/tests/ui/size_of_ref.stderr index d4c13ac3290b6..c7a1758825cba 100644 --- a/tests/ui/size_of_ref.stderr +++ b/tests/ui/size_of_ref.stderr @@ -8,7 +8,7 @@ LL | size_of_val(&&x); = note: `-D clippy::size-of-ref` implied by `-D warnings` error: argument to `std::mem::size_of_val()` is a reference to a reference - --> $DIR/size_of_ref.rs:14:5 + --> $DIR/size_of_ref.rs:15:5 | LL | size_of_val(&y); | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | size_of_val(&y); = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type error: argument to `std::mem::size_of_val()` is a reference to a reference - --> $DIR/size_of_ref.rs:25:9 + --> $DIR/size_of_ref.rs:27:9 | LL | std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs index b152a016d9a1f..f8d85ed38cd5a 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -12,10 +12,13 @@ fn extend_vector() { let len = 300; let mut vec1 = Vec::with_capacity(len); vec1.extend(repeat(0).take(len)); + //~^ ERROR: slow zero-filling initialization + //~| NOTE: `-D clippy::slow-vector-initialization` implied by `-D warnings` // Extend with len expression let mut vec2 = Vec::with_capacity(len - 10); vec2.extend(repeat(0).take(len - 10)); + //~^ ERROR: slow zero-filling initialization // Extend with mismatching expression should not be warned let mut vec3 = Vec::with_capacity(24322); @@ -23,6 +26,7 @@ fn extend_vector() { let mut vec4 = Vec::with_capacity(len); vec4.extend(repeat(0).take(vec4.capacity())); + //~^ ERROR: slow zero-filling initialization } fn mixed_extend_resize_vector() { @@ -33,9 +37,11 @@ fn mixed_extend_resize_vector() { // Slow initialization let mut resized_vec = Vec::with_capacity(30); resized_vec.resize(30, 0); + //~^ ERROR: slow zero-filling initialization let mut extend_vec = Vec::with_capacity(30); extend_vec.extend(repeat(0).take(30)); + //~^ ERROR: slow zero-filling initialization } fn resize_vector() { @@ -43,6 +49,7 @@ fn resize_vector() { let len = 300; let mut vec1 = Vec::with_capacity(len); vec1.resize(len, 0); + //~^ ERROR: slow zero-filling initialization // Resize mismatch len let mut vec2 = Vec::with_capacity(200); @@ -51,13 +58,16 @@ fn resize_vector() { // Resize with len expression let mut vec3 = Vec::with_capacity(len - 10); vec3.resize(len - 10, 0); + //~^ ERROR: slow zero-filling initialization let mut vec4 = Vec::with_capacity(len); vec4.resize(vec4.capacity(), 0); + //~^ ERROR: slow zero-filling initialization // Reinitialization should be warned vec1 = Vec::with_capacity(10); vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization } fn from_empty_vec() { @@ -65,17 +75,22 @@ fn from_empty_vec() { let len = 300; let mut vec1 = Vec::new(); vec1.resize(len, 0); + //~^ ERROR: slow zero-filling initialization // Resize with len expression let mut vec3 = Vec::new(); vec3.resize(len - 10, 0); + //~^ ERROR: slow zero-filling initialization // Reinitialization should be warned vec1 = Vec::new(); vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization } fn do_stuff(vec: &mut [u8]) {} +//~^ ERROR: this argument is a mutable reference, but not used mutably +//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` fn extend_vector_with_manipulations_between() { let len = 300; diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr index 532ce4ac19113..4800e6e441862 100644 --- a/tests/ui/slow_vector_initialization.stderr +++ b/tests/ui/slow_vector_initialization.stderr @@ -9,7 +9,7 @@ LL | vec1.extend(repeat(0).take(len)); = note: `-D clippy::slow-vector-initialization` implied by `-D warnings` error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:18:5 + --> $DIR/slow_vector_initialization.rs:20:5 | LL | let mut vec2 = Vec::with_capacity(len - 10); | ---------------------------- help: consider replacing this with: `vec![0; len - 10]` @@ -17,7 +17,7 @@ LL | vec2.extend(repeat(0).take(len - 10)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:25:5 + --> $DIR/slow_vector_initialization.rs:28:5 | LL | let mut vec4 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -25,7 +25,7 @@ LL | vec4.extend(repeat(0).take(vec4.capacity())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:35:5 + --> $DIR/slow_vector_initialization.rs:39:5 | LL | let mut resized_vec = Vec::with_capacity(30); | ---------------------- help: consider replacing this with: `vec![0; 30]` @@ -33,7 +33,7 @@ LL | resized_vec.resize(30, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:38:5 + --> $DIR/slow_vector_initialization.rs:43:5 | LL | let mut extend_vec = Vec::with_capacity(30); | ---------------------- help: consider replacing this with: `vec![0; 30]` @@ -41,7 +41,7 @@ LL | extend_vec.extend(repeat(0).take(30)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:45:5 + --> $DIR/slow_vector_initialization.rs:51:5 | LL | let mut vec1 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -49,7 +49,7 @@ LL | vec1.resize(len, 0); | ^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:53:5 + --> $DIR/slow_vector_initialization.rs:60:5 | LL | let mut vec3 = Vec::with_capacity(len - 10); | ---------------------------- help: consider replacing this with: `vec![0; len - 10]` @@ -57,7 +57,7 @@ LL | vec3.resize(len - 10, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:56:5 + --> $DIR/slow_vector_initialization.rs:64:5 | LL | let mut vec4 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -65,7 +65,7 @@ LL | vec4.resize(vec4.capacity(), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:60:5 + --> $DIR/slow_vector_initialization.rs:69:5 | LL | vec1 = Vec::with_capacity(10); | ---------------------- help: consider replacing this with: `vec![0; 10]` @@ -73,7 +73,7 @@ LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:67:5 + --> $DIR/slow_vector_initialization.rs:77:5 | LL | let mut vec1 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; len]` @@ -81,7 +81,7 @@ LL | vec1.resize(len, 0); | ^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:71:5 + --> $DIR/slow_vector_initialization.rs:82:5 | LL | let mut vec3 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; len - 10]` @@ -89,7 +89,7 @@ LL | vec3.resize(len - 10, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:75:5 + --> $DIR/slow_vector_initialization.rs:87:5 | LL | vec1 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; 10]` @@ -97,7 +97,7 @@ LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ error: this argument is a mutable reference, but not used mutably - --> $DIR/slow_vector_initialization.rs:78:18 + --> $DIR/slow_vector_initialization.rs:91:18 | LL | fn do_stuff(vec: &mut [u8]) {} | ^^^^^^^^^ help: consider changing to: `&[u8]` diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs index 75b114ba0aed9..2e44487d77e35 100644 --- a/tests/ui/std_instead_of_core.rs +++ b/tests/ui/std_instead_of_core.rs @@ -7,21 +7,29 @@ extern crate alloc; fn std_instead_of_core() { // Regular import use std::hash::Hasher; + //~^ ERROR: used import from `std` instead of `core` // Absolute path use ::std::hash::Hash; + //~^ ERROR: used import from `std` instead of `core` // Don't lint on `env` macro use std::env; // Multiple imports use std::fmt::{Debug, Result}; + //~^ ERROR: used import from `std` instead of `core` + //~| ERROR: used import from `std` instead of `core` // Function calls let ptr = std::ptr::null::(); + //~^ ERROR: used import from `std` instead of `core` let ptr_mut = ::std::ptr::null_mut::(); + //~^ ERROR: used import from `std` instead of `core` // Types let cell = std::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` let cell_absolute = ::std::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` let _ = std::env!("PATH"); @@ -30,18 +38,22 @@ fn std_instead_of_core() { // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator` use std::iter::Iterator; + //~^ ERROR: used import from `std` instead of `core` } #[warn(clippy::std_instead_of_alloc)] fn std_instead_of_alloc() { // Only lint once. use std::vec; + //~^ ERROR: used import from `std` instead of `alloc` use std::vec::Vec; + //~^ ERROR: used import from `std` instead of `alloc` } #[warn(clippy::alloc_instead_of_core)] fn alloc_instead_of_core() { use alloc::slice::from_ref; + //~^ ERROR: used import from `alloc` instead of `core` } fn main() { diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr index d2102497350bd..f2db81e51633a 100644 --- a/tests/ui/std_instead_of_core.stderr +++ b/tests/ui/std_instead_of_core.stderr @@ -8,7 +8,7 @@ LL | use std::hash::Hasher; = note: `-D clippy::std-instead-of-core` implied by `-D warnings` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:11:9 + --> $DIR/std_instead_of_core.rs:12:9 | LL | use ::std::hash::Hash; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | use ::std::hash::Hash; = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:16:20 + --> $DIR/std_instead_of_core.rs:18:20 | LL | use std::fmt::{Debug, Result}; | ^^^^^ @@ -24,7 +24,7 @@ LL | use std::fmt::{Debug, Result}; = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:16:27 + --> $DIR/std_instead_of_core.rs:18:27 | LL | use std::fmt::{Debug, Result}; | ^^^^^^ @@ -32,7 +32,7 @@ LL | use std::fmt::{Debug, Result}; = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:19:15 + --> $DIR/std_instead_of_core.rs:23:15 | LL | let ptr = std::ptr::null::(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let ptr = std::ptr::null::(); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:20:19 + --> $DIR/std_instead_of_core.rs:25:19 | LL | let ptr_mut = ::std::ptr::null_mut::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let ptr_mut = ::std::ptr::null_mut::(); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:23:16 + --> $DIR/std_instead_of_core.rs:29:16 | LL | let cell = std::cell::Cell::new(8u32); | ^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let cell = std::cell::Cell::new(8u32); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:24:25 + --> $DIR/std_instead_of_core.rs:31:25 | LL | let cell_absolute = ::std::cell::Cell::new(8u32); | ^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let cell_absolute = ::std::cell::Cell::new(8u32); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:32:9 + --> $DIR/std_instead_of_core.rs:40:9 | LL | use std::iter::Iterator; | ^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | use std::iter::Iterator; = help: consider importing the item from `core` error: used import from `std` instead of `alloc` - --> $DIR/std_instead_of_core.rs:38:9 + --> $DIR/std_instead_of_core.rs:47:9 | LL | use std::vec; | ^^^^^^^^ @@ -81,7 +81,7 @@ LL | use std::vec; = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings` error: used import from `std` instead of `alloc` - --> $DIR/std_instead_of_core.rs:39:9 + --> $DIR/std_instead_of_core.rs:49:9 | LL | use std::vec::Vec; | ^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | use std::vec::Vec; = help: consider importing the item from `alloc` error: used import from `alloc` instead of `core` - --> $DIR/std_instead_of_core.rs:44:9 + --> $DIR/std_instead_of_core.rs:55:9 | LL | use alloc::slice::from_ref; | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/str_to_string.rs b/tests/ui/str_to_string.rs index 08f734025181c..f93b289c29ab3 100644 --- a/tests/ui/str_to_string.rs +++ b/tests/ui/str_to_string.rs @@ -2,6 +2,8 @@ fn main() { let hello = "hello world".to_string(); + //~^ ERROR: `to_string()` called on a `&str` let msg = &hello[..]; msg.to_string(); + //~^ ERROR: `to_string()` called on a `&str` } diff --git a/tests/ui/str_to_string.stderr b/tests/ui/str_to_string.stderr index 1d47da571fa1f..25af1d376638f 100644 --- a/tests/ui/str_to_string.stderr +++ b/tests/ui/str_to_string.stderr @@ -8,7 +8,7 @@ LL | let hello = "hello world".to_string(); = note: `-D clippy::str-to-string` implied by `-D warnings` error: `to_string()` called on a `&str` - --> $DIR/str_to_string.rs:6:5 + --> $DIR/str_to_string.rs:7:5 | LL | msg.to_string(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/string_slice.rs b/tests/ui/string_slice.rs index be4dfc8816c7f..440a86b104a3d 100644 --- a/tests/ui/string_slice.rs +++ b/tests/ui/string_slice.rs @@ -3,8 +3,12 @@ fn main() { &"Ölkanne"[1..]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character + //~| NOTE: `-D clippy::string-slice` implied by `-D warnings` let m = "Mötörhead"; &m[2..5]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character let s = String::from(m); &s[0..2]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character } diff --git a/tests/ui/string_slice.stderr b/tests/ui/string_slice.stderr index 55040bf5df2de..94dad58cd972e 100644 --- a/tests/ui/string_slice.stderr +++ b/tests/ui/string_slice.stderr @@ -7,13 +7,13 @@ LL | &"Ölkanne"[1..]; = note: `-D clippy::string-slice` implied by `-D warnings` error: indexing into a string may panic if the index is within a UTF-8 character - --> $DIR/string_slice.rs:7:6 + --> $DIR/string_slice.rs:9:6 | LL | &m[2..5]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> $DIR/string_slice.rs:9:6 + --> $DIR/string_slice.rs:12:6 | LL | &s[0..2]; | ^^^^^^^ diff --git a/tests/ui/string_to_string.rs b/tests/ui/string_to_string.rs index 4c66855f70941..007685b601797 100644 --- a/tests/ui/string_to_string.rs +++ b/tests/ui/string_to_string.rs @@ -4,4 +4,5 @@ fn main() { let mut message = String::from("Hello"); let mut v = message.to_string(); + //~^ ERROR: `to_string()` called on a `String` } diff --git a/tests/ui/struct_excessive_bools.rs b/tests/ui/struct_excessive_bools.rs index ce4fe830a0a21..8137ce7a81c51 100644 --- a/tests/ui/struct_excessive_bools.rs +++ b/tests/ui/struct_excessive_bools.rs @@ -20,6 +20,7 @@ struct Foo { } struct BadFoo { + //~^ ERROR: more than 3 bools in a struct a: bool, b: bool, c: bool, @@ -36,6 +37,7 @@ struct Bar { fn main() { struct FooFoo { + //~^ ERROR: more than 3 bools in a struct a: bool, b: bool, c: bool, diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr index e4d50043acb0b..05b2363eb5680 100644 --- a/tests/ui/struct_excessive_bools.stderr +++ b/tests/ui/struct_excessive_bools.stderr @@ -2,6 +2,7 @@ error: more than 3 bools in a struct --> $DIR/struct_excessive_bools.rs:22:1 | LL | / struct BadFoo { +LL | | LL | | a: bool, LL | | b: bool, LL | | c: bool, @@ -13,9 +14,10 @@ LL | | } = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` error: more than 3 bools in a struct - --> $DIR/struct_excessive_bools.rs:38:5 + --> $DIR/struct_excessive_bools.rs:39:5 | LL | / struct FooFoo { +LL | | LL | | a: bool, LL | | b: bool, LL | | c: bool, diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index ae253a0487cb4..1bd4cd5fb50de 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -11,12 +11,16 @@ impl Add for Foo { fn add(self, other: Self) -> Self { Foo(self.0 - other.0) + //~^ ERROR: suspicious use of `-` in `Add` impl + //~| NOTE: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` } } impl AddAssign for Foo { fn add_assign(&mut self, other: Foo) { *self = *self - other; + //~^ ERROR: suspicious use of `-` in `AddAssign` impl + //~| NOTE: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` } } @@ -30,6 +34,7 @@ impl BitOrAssign for Foo { impl MulAssign for Foo { fn mul_assign(&mut self, other: Foo) { self.0 /= other.0; + //~^ ERROR: suspicious use of `/` in `MulAssign` impl } } @@ -68,6 +73,7 @@ impl Rem for Foo { fn rem(self, other: Self) -> Self { Foo(self.0 / other.0) + //~^ ERROR: suspicious use of `/` in `Rem` impl } } @@ -76,6 +82,7 @@ impl BitAnd for Foo { fn bitand(self, other: Self) -> Self { Foo(self.0 | other.0) + //~^ ERROR: suspicious use of `|` in `BitAnd` impl } } @@ -84,6 +91,7 @@ impl BitOr for Foo { fn bitor(self, other: Self) -> Self { Foo(self.0 ^ other.0) + //~^ ERROR: suspicious use of `^` in `BitOr` impl } } @@ -92,6 +100,7 @@ impl BitXor for Foo { fn bitxor(self, other: Self) -> Self { Foo(self.0 & other.0) + //~^ ERROR: suspicious use of `&` in `BitXor` impl } } @@ -100,6 +109,7 @@ impl Shl for Foo { fn shl(self, other: Self) -> Self { Foo(self.0 >> other.0) + //~^ ERROR: suspicious use of `>>` in `Shl` impl } } @@ -108,6 +118,7 @@ impl Shr for Foo { fn shr(self, other: Self) -> Self { Foo(self.0 << other.0) + //~^ ERROR: suspicious use of `<<` in `Shr` impl } } diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index ced1305874e58..4a4be0712b289 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -7,7 +7,7 @@ LL | Foo(self.0 - other.0) = note: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` error: suspicious use of `-` in `AddAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:19:23 + --> $DIR/suspicious_arithmetic_impl.rs:21:23 | LL | *self = *self - other; | ^ @@ -15,43 +15,43 @@ LL | *self = *self - other; = note: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` error: suspicious use of `/` in `MulAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:32:16 + --> $DIR/suspicious_arithmetic_impl.rs:36:16 | LL | self.0 /= other.0; | ^^ error: suspicious use of `/` in `Rem` impl - --> $DIR/suspicious_arithmetic_impl.rs:70:20 + --> $DIR/suspicious_arithmetic_impl.rs:75:20 | LL | Foo(self.0 / other.0) | ^ error: suspicious use of `|` in `BitAnd` impl - --> $DIR/suspicious_arithmetic_impl.rs:78:20 + --> $DIR/suspicious_arithmetic_impl.rs:84:20 | LL | Foo(self.0 | other.0) | ^ error: suspicious use of `^` in `BitOr` impl - --> $DIR/suspicious_arithmetic_impl.rs:86:20 + --> $DIR/suspicious_arithmetic_impl.rs:93:20 | LL | Foo(self.0 ^ other.0) | ^ error: suspicious use of `&` in `BitXor` impl - --> $DIR/suspicious_arithmetic_impl.rs:94:20 + --> $DIR/suspicious_arithmetic_impl.rs:102:20 | LL | Foo(self.0 & other.0) | ^ error: suspicious use of `>>` in `Shl` impl - --> $DIR/suspicious_arithmetic_impl.rs:102:20 + --> $DIR/suspicious_arithmetic_impl.rs:111:20 | LL | Foo(self.0 >> other.0) | ^^ error: suspicious use of `<<` in `Shr` impl - --> $DIR/suspicious_arithmetic_impl.rs:110:20 + --> $DIR/suspicious_arithmetic_impl.rs:120:20 | LL | Foo(self.0 << other.0) | ^^ diff --git a/tests/ui/suspicious_command_arg_space.fixed b/tests/ui/suspicious_command_arg_space.fixed index 65f8c85d8d9ad..5d7b1e0c17f25 100644 --- a/tests/ui/suspicious_command_arg_space.fixed +++ b/tests/ui/suspicious_command_arg_space.fixed @@ -1,7 +1,10 @@ fn main() { // Things it should warn about: std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + //~| NOTE: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments // Things it should not warn about: std::process::Command::new("echo").arg("hello world").spawn().unwrap(); diff --git a/tests/ui/suspicious_command_arg_space.rs b/tests/ui/suspicious_command_arg_space.rs index bdc6113a25001..8abd9803a0c6f 100644 --- a/tests/ui/suspicious_command_arg_space.rs +++ b/tests/ui/suspicious_command_arg_space.rs @@ -1,7 +1,10 @@ fn main() { // Things it should warn about: std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + //~| NOTE: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` std::process::Command::new("cat").arg("--number file").spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments // Things it should not warn about: std::process::Command::new("echo").arg("hello world").spawn().unwrap(); diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index 9bc0ca93aec9e..0ed4eb20ecb5b 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -11,7 +11,7 @@ LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap | ~~~~ ~~~~~~~~~~~~~~~ error: single argument that looks like it should be multiple arguments - --> $DIR/suspicious_command_arg_space.rs:4:43 + --> $DIR/suspicious_command_arg_space.rs:6:43 | LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index 5f1980b43c40f..9e9c4775748ca 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -2,12 +2,15 @@ #![warn(clippy::suspicious_doc_comments)] //@no-rustfix ///! a +//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate +//~| NOTE: `-D clippy::suspicious-doc-comments` implied by `-D warnings` ///! b /// c ///! d pub fn foo() {} ///! a +//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate ///! b /// c ///! d diff --git a/tests/ui/suspicious_doc_comments_unfixable.stderr b/tests/ui/suspicious_doc_comments_unfixable.stderr index f89146dad36e0..3a93c289fc702 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.stderr +++ b/tests/ui/suspicious_doc_comments_unfixable.stderr @@ -2,6 +2,8 @@ error: this is an outer doc comment and does not apply to the parent module or c --> $DIR/suspicious_doc_comments_unfixable.rs:4:1 | LL | / ///! a +LL | | +LL | | LL | | ///! b LL | | /// c LL | | ///! d @@ -11,15 +13,18 @@ LL | | ///! d help: use an inner doc comment to document the parent module or crate | LL + //! a +LL | +LL | LL + //! b LL | /// c LL + //! d | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments_unfixable.rs:10:1 + --> $DIR/suspicious_doc_comments_unfixable.rs:12:1 | LL | / ///! a +LL | | LL | | ///! b LL | | /// c LL | | ///! d @@ -28,6 +33,7 @@ LL | | ///! d help: use an inner doc comment to document the parent module or crate | LL + //! a +LL | LL + //! b LL | /// c LL + //! d diff --git a/tests/ui/suspicious_map.rs b/tests/ui/suspicious_map.rs index 3a2a10cf09ea5..d4247fcd9265e 100644 --- a/tests/ui/suspicious_map.rs +++ b/tests/ui/suspicious_map.rs @@ -2,9 +2,11 @@ fn main() { let _ = (0..3).map(|x| x + 2).count(); + //~^ ERROR: this call to `map()` won't have an effect on the call to `count()` let f = |x| x + 1; let _ = (0..3).map(f).count(); + //~^ ERROR: this call to `map()` won't have an effect on the call to `count()` } fn negative() { diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr index e251674819e46..154083f99fa29 100644 --- a/tests/ui/suspicious_map.stderr +++ b/tests/ui/suspicious_map.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..3).map(|x| x + 2).count(); = note: `-D clippy::suspicious-map` implied by `-D warnings` error: this call to `map()` won't have an effect on the call to `count()` - --> $DIR/suspicious_map.rs:7:13 + --> $DIR/suspicious_map.rs:8:13 | LL | let _ = (0..3).map(f).count(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_splitn.rs b/tests/ui/suspicious_splitn.rs index 528f2ddcc8624..7aa6097062201 100644 --- a/tests/ui/suspicious_splitn.rs +++ b/tests/ui/suspicious_splitn.rs @@ -8,14 +8,32 @@ fn main() { let _ = [].splitn(0, |&x: &u32| x == 1); let _ = "a,b".splitn(0, ','); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = "a,b".rsplitn(0, ','); + //~^ ERROR: `rsplitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = "a,b".splitn(1, ','); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire string followed by `No let _ = [0, 1, 2].splitn(0, |&x| x == 1); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); + //~^ ERROR: `splitn_mut` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = [0, 1, 2].splitn(1, |&x| x == 1); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire slice followed by `Non let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); + //~^ ERROR: `rsplitn_mut` called with `1` split + //~| NOTE: the resulting iterator will always return the entire slice followed by `Non const X: usize = 0; let _ = "a,b".splitn(X + 1, ','); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire string followed by `No let _ = "a,b".splitn(X, ','); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` } diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 55ce63d4faa8c..2bdf1043abb73 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -8,7 +8,7 @@ LL | let _ = "a,b".splitn(0, ','); = note: `-D clippy::suspicious-splitn` implied by `-D warnings` error: `rsplitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:11:13 + --> $DIR/suspicious_splitn.rs:13:13 | LL | let _ = "a,b".rsplitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = "a,b".rsplitn(0, ','); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:12:13 + --> $DIR/suspicious_splitn.rs:16:13 | LL | let _ = "a,b".splitn(1, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = "a,b".splitn(1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:13:13 + --> $DIR/suspicious_splitn.rs:19:13 | LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn_mut` called with `0` splits - --> $DIR/suspicious_splitn.rs:14:13 + --> $DIR/suspicious_splitn.rs:22:13 | LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:15:13 + --> $DIR/suspicious_splitn.rs:25:13 | LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `rsplitn_mut` called with `1` split - --> $DIR/suspicious_splitn.rs:16:13 + --> $DIR/suspicious_splitn.rs:28:13 | LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:19:13 + --> $DIR/suspicious_splitn.rs:33:13 | LL | let _ = "a,b".splitn(X + 1, ','); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _ = "a,b".splitn(X + 1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:20:13 + --> $DIR/suspicious_splitn.rs:36:13 | LL | let _ = "a,b".splitn(X, ','); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_to_owned.rs b/tests/ui/suspicious_to_owned.rs index bf228264e23d4..f32b07d45f635 100644 --- a/tests/ui/suspicious_to_owned.rs +++ b/tests/ui/suspicious_to_owned.rs @@ -15,6 +15,8 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(moo); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, str> itself and does not cause the + //~| NOTE: `-D clippy::suspicious-to-owned` implied by `-D warnings` // we expect no lints for this let cow = Cow::Borrowed(moo); let _ = cow.into_owned(); @@ -25,6 +27,7 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(&moos); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cau // we expect no lints for this let cow = Cow::Borrowed(&moos); let _ = cow.into_owned(); @@ -35,6 +38,7 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(&moos_vec); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, Vec> itself and does not cau // we expect no lints for this let cow = Cow::Borrowed(&moos_vec); let _ = cow.into_owned(); @@ -45,6 +49,7 @@ fn main() { // we expect this to be linted let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, str> itself and does not cause the // we expect no lints for this let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.into_owned(); @@ -59,5 +64,8 @@ fn main() { // we expect implicit_clone lints for these let _ = String::from(moo).to_owned(); + //~^ ERROR: implicitly cloning a `String` by calling `to_owned` on its dereferenced ty + //~| NOTE: `-D clippy::implicit-clone` implied by `-D warnings` let _ = moos_vec.to_owned(); + //~^ ERROR: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type } diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 1c2618e513c3d..cbda1649c629f 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -15,7 +15,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned - --> $DIR/suspicious_to_owned.rs:27:13 + --> $DIR/suspicious_to_owned.rs:29:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, Vec> itself and does not cause the Cow<'_, Vec> contents to become owned - --> $DIR/suspicious_to_owned.rs:37:13 + --> $DIR/suspicious_to_owned.rs:40:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned - --> $DIR/suspicious_to_owned.rs:47:13 + --> $DIR/suspicious_to_owned.rs:51:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:61:13 + --> $DIR/suspicious_to_owned.rs:66:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` @@ -68,7 +68,7 @@ LL | let _ = String::from(moo).to_owned(); = note: `-D clippy::implicit-clone` implied by `-D warnings` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:62:13 + --> $DIR/suspicious_to_owned.rs:69:13 | LL | let _ = moos_vec.to_owned(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `moos_vec.clone()` diff --git a/tests/ui/suspicious_unary_op_formatting.rs b/tests/ui/suspicious_unary_op_formatting.rs index 3c5ca1762fe49..a7a62154ee0f2 100644 --- a/tests/ui/suspicious_unary_op_formatting.rs +++ b/tests/ui/suspicious_unary_op_formatting.rs @@ -7,14 +7,18 @@ fn main() { let a = 42; if a >- 30 {} + //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o if a >=- 30 {} + //~^ ERROR: by not having a space between `>=` and `-` it looks like `>=-` is a single let b = true; let c = false; if b &&! c {} + //~^ ERROR: by not having a space between `&&` and `!` it looks like `&&!` is a single if a >- 30 {} + //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o // those are ok: if a >-30 {} diff --git a/tests/ui/suspicious_unary_op_formatting.stderr b/tests/ui/suspicious_unary_op_formatting.stderr index 52b0e99a1d3e8..c44a43ea1ec28 100644 --- a/tests/ui/suspicious_unary_op_formatting.stderr +++ b/tests/ui/suspicious_unary_op_formatting.stderr @@ -8,7 +8,7 @@ LL | if a >- 30 {} = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:10:9 + --> $DIR/suspicious_unary_op_formatting.rs:11:9 | LL | if a >=- 30 {} | ^^^^^ @@ -16,7 +16,7 @@ LL | if a >=- 30 {} = help: put a space between `>=` and `-` and remove the space after `-` error: by not having a space between `&&` and `!` it looks like `&&!` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:15:9 + --> $DIR/suspicious_unary_op_formatting.rs:17:9 | LL | if b &&! c {} | ^^^^^ @@ -24,7 +24,7 @@ LL | if b &&! c {} = help: put a space between `&&` and `!` and remove the space after `!` error: by not having a space between `>` and `-` it looks like `>-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:17:9 + --> $DIR/suspicious_unary_op_formatting.rs:20:9 | LL | if a >- 30 {} | ^^^^^^ diff --git a/tests/ui/suspicious_xor_used_as_pow.rs b/tests/ui/suspicious_xor_used_as_pow.rs index f7c44c9e6fa1e..a5319e1b2308e 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -17,11 +17,18 @@ macro_rules! macro_test_inside { fn main() { // Should warn: let _ = 2 ^ 5; + //~^ ERROR: `^` is not the exponentiation operator + //~| NOTE: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` let _ = 2i32 ^ 9i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 2i32 ^ 2i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 50i32 ^ 3i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 5i32 ^ 8i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 2i32 ^ 32i32; + //~^ ERROR: `^` is not the exponentiation operator macro_test_inside!(); // Should not warn: diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index d93a55ba9065c..1a260e64e77a3 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -7,31 +7,31 @@ LL | let _ = 2 ^ 5; = note: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:20:13 + --> $DIR/suspicious_xor_used_as_pow.rs:22:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(9i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:21:13 + --> $DIR/suspicious_xor_used_as_pow.rs:24:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(2i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:22:13 + --> $DIR/suspicious_xor_used_as_pow.rs:26:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ help: did you mean to write: `50i32.pow(3i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:23:13 + --> $DIR/suspicious_xor_used_as_pow.rs:28:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ help: did you mean to write: `5i32.pow(8i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:24:13 + --> $DIR/suspicious_xor_used_as_pow.rs:30:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)` diff --git a/tests/ui/swap_ptr_to_ref_unfixable.rs b/tests/ui/swap_ptr_to_ref_unfixable.rs index 66ea7c6529bd2..08e56a5d01b22 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.rs +++ b/tests/ui/swap_ptr_to_ref_unfixable.rs @@ -12,7 +12,11 @@ fn main() { unsafe { core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer + //~| NOTE: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer } } diff --git a/tests/ui/swap_ptr_to_ref_unfixable.stderr b/tests/ui/swap_ptr_to_ref_unfixable.stderr index c261205d556e4..f0c1e7e7428bf 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.stderr +++ b/tests/ui/swap_ptr_to_ref_unfixable.stderr @@ -7,13 +7,13 @@ LL | core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref_unfixable.rs:15:9 + --> $DIR/swap_ptr_to_ref_unfixable.rs:17:9 | LL | core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref_unfixable.rs:16:9 + --> $DIR/swap_ptr_to_ref_unfixable.rs:19:9 | LL | core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index ac4c1bc65979f..e2b982aeaf52a 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -45,13 +45,18 @@ fn main() { let mut t = (0, 0); Struct { field: 0 }.field = 1; + //~^ ERROR: assignment to temporary + //~| NOTE: `-D clippy::temporary-assignment` implied by `-D warnings` MultiStruct { + //~^ ERROR: assignment to temporary structure: Struct { field: 0 }, } .structure .field = 1; ArrayStruct { array: [0] }.array[0] = 1; + //~^ ERROR: assignment to temporary (0, 0).0 = 1; + //~^ ERROR: assignment to temporary // no error s.field = 1; diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 7d79901a28d1b..12e2c5a2fc317 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -7,9 +7,10 @@ LL | Struct { field: 0 }.field = 1; = note: `-D clippy::temporary-assignment` implied by `-D warnings` error: assignment to temporary - --> $DIR/temporary_assignment.rs:48:5 + --> $DIR/temporary_assignment.rs:50:5 | LL | / MultiStruct { +LL | | LL | | structure: Struct { field: 0 }, LL | | } LL | | .structure @@ -17,13 +18,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:53:5 + --> $DIR/temporary_assignment.rs:56:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:54:5 + --> $DIR/temporary_assignment.rs:58:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ diff --git a/tests/ui/tests_outside_test_module.rs b/tests/ui/tests_outside_test_module.rs index d53c692b78e13..0abde4a57bf77 100644 --- a/tests/ui/tests_outside_test_module.rs +++ b/tests/ui/tests_outside_test_module.rs @@ -8,6 +8,8 @@ fn main() { // Should lint #[test] fn my_test() {} +//~^ ERROR: this function marked with #[test] is outside a #[cfg(test)] module +//~| NOTE: move it to a testing module marked with #[cfg(test)] #[cfg(test)] mod tests { diff --git a/tests/ui/trailing_empty_array.rs b/tests/ui/trailing_empty_array.rs index 928475b5f35ea..3d06c2621681d 100644 --- a/tests/ui/trailing_empty_array.rs +++ b/tests/ui/trailing_empty_array.rs @@ -3,33 +3,39 @@ // Do lint: struct RarelyUseful { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } struct OnlyField { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib first_and_last: [usize; 0], } struct GenericArrayType { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [T; 0], } #[must_use] struct OnlyAnotherAttribute { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } #[derive(Debug)] struct OnlyADeriveAttribute { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } const ZERO: usize = 0; struct ZeroSizedWithConst { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; ZERO], } @@ -39,6 +45,7 @@ const fn compute_zero() -> usize { (4 + 6) - (2 * 5) } struct ZeroSizedWithConstFunction { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; compute_zero()], } @@ -47,15 +54,19 @@ const fn compute_zero_from_arg(x: usize) -> usize { x - 1 } struct ZeroSizedWithConstFunction2 { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; compute_zero_from_arg(1)], } struct ZeroSizedArrayWrapper([usize; 0]); +//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib struct TupleStruct(i32, [usize; 0]); +//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib struct LotsOfFields { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib f1: u32, f2: u32, f3: u32, diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index 2e1484400352d..d89e77f61ce4a 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -2,6 +2,7 @@ error: trailing zero-sized array in a struct which is not marked with a `repr` a --> $DIR/trailing_empty_array.rs:5:1 | LL | / struct RarelyUseful { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -11,9 +12,10 @@ LL | | } = note: `-D clippy::trailing-empty-array` implied by `-D warnings` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:10:1 + --> $DIR/trailing_empty_array.rs:11:1 | LL | / struct OnlyField { +LL | | LL | | first_and_last: [usize; 0], LL | | } | |_^ @@ -21,9 +23,10 @@ LL | | } = help: consider annotating `OnlyField` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:14:1 + --> $DIR/trailing_empty_array.rs:16:1 | LL | / struct GenericArrayType { +LL | | LL | | field: i32, LL | | last: [T; 0], LL | | } @@ -32,9 +35,10 @@ LL | | } = help: consider annotating `GenericArrayType` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:20:1 + --> $DIR/trailing_empty_array.rs:23:1 | LL | / struct OnlyAnotherAttribute { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -43,9 +47,10 @@ LL | | } = help: consider annotating `OnlyAnotherAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:26:1 + --> $DIR/trailing_empty_array.rs:30:1 | LL | / struct OnlyADeriveAttribute { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -54,9 +59,10 @@ LL | | } = help: consider annotating `OnlyADeriveAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:32:1 + --> $DIR/trailing_empty_array.rs:37:1 | LL | / struct ZeroSizedWithConst { +LL | | LL | | field: i32, LL | | last: [usize; ZERO], LL | | } @@ -65,9 +71,10 @@ LL | | } = help: consider annotating `ZeroSizedWithConst` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:41:1 + --> $DIR/trailing_empty_array.rs:47:1 | LL | / struct ZeroSizedWithConstFunction { +LL | | LL | | field: i32, LL | | last: [usize; compute_zero()], LL | | } @@ -76,9 +83,10 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:49:1 + --> $DIR/trailing_empty_array.rs:56:1 | LL | / struct ZeroSizedWithConstFunction2 { +LL | | LL | | field: i32, LL | | last: [usize; compute_zero_from_arg(1)], LL | | } @@ -87,7 +95,7 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction2` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:54:1 + --> $DIR/trailing_empty_array.rs:62:1 | LL | struct ZeroSizedArrayWrapper([usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +103,7 @@ LL | struct ZeroSizedArrayWrapper([usize; 0]); = help: consider annotating `ZeroSizedArrayWrapper` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:56:1 + --> $DIR/trailing_empty_array.rs:65:1 | LL | struct TupleStruct(i32, [usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,12 +111,12 @@ LL | struct TupleStruct(i32, [usize; 0]); = help: consider annotating `TupleStruct` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:58:1 + --> $DIR/trailing_empty_array.rs:68:1 | LL | / struct LotsOfFields { +LL | | LL | | f1: u32, LL | | f2: u32, -LL | | f3: u32, ... | LL | | last: [usize; 0], LL | | } diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index 8aceb76ddd851..f7de976f1e00e 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -4,7 +4,10 @@ fn main() { let x: i32 = 42; let _ = x.trailing_zeros() >= 4; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~| NOTE: `-D clippy::verbose-bit-mask` implied by `-D warnings` let _ = x.trailing_zeros() >= 5; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index 888f0587fe348..a05b09233e212 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -4,7 +4,10 @@ fn main() { let x: i32 = 42; let _ = (x & 0b1111 == 0); + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~| NOTE: `-D clippy::verbose-bit-mask` implied by `-D warnings` let _ = x & 0b1_1111 == 0; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 7c44f139c0952..fb4025a75481d 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -7,7 +7,7 @@ LL | let _ = (x & 0b1111 == 0); = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/trailing_zeros.rs:7:13 + --> $DIR/trailing_zeros.rs:9:13 | LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.rs b/tests/ui/trait_duplication_in_bounds_unfixable.rs index 5630a0345adb1..effed3a26938b 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.rs +++ b/tests/ui/trait_duplication_in_bounds_unfixable.rs @@ -4,6 +4,8 @@ use std::collections::BTreeMap; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; fn bad_foo(arg0: T, arg1: Z) +//~^ ERROR: this trait bound is already specified in the where clause +//~| ERROR: this trait bound is already specified in the where clause where T: Clone, T: Default, @@ -33,6 +35,7 @@ trait T: Default { fn f() where Self: Default; + //~^ ERROR: this trait bound is already specified in trait declaration } trait U: Default { @@ -47,15 +50,19 @@ trait ZZ: Default { fn f() where Self: Default + Clone; + //~^ ERROR: this trait bound is already specified in trait declaration } trait BadTrait: Default + Clone { fn f() where Self: Default + Clone; + //~^ ERROR: this trait bound is already specified in trait declaration + //~| ERROR: this trait bound is already specified in trait declaration fn g() where Self: Default; + //~^ ERROR: this trait bound is already specified in trait declaration fn h() where Self: Copy; @@ -91,6 +98,7 @@ trait FooIter: Iterator { fn bar() where Self: Iterator, + //~^ ERROR: this trait bound is already specified in trait declaration { } } diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/tests/ui/trait_duplication_in_bounds_unfixable.stderr index 4d56a94646cb6..80dc7d8b6c32d 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.stderr +++ b/tests/ui/trait_duplication_in_bounds_unfixable.stderr @@ -20,7 +20,7 @@ LL | fn bad_foo(arg0: T, arg1: Z) = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:35:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:37:15 | LL | Self: Default; | ^^^^^^^ @@ -28,7 +28,7 @@ LL | Self: Default; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:49:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:52:15 | LL | Self: Default + Clone; | ^^^^^^^ @@ -36,7 +36,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:55:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:59:15 | LL | Self: Default + Clone; | ^^^^^^^ @@ -44,7 +44,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:55:25 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:59:25 | LL | Self: Default + Clone; | ^^^^^ @@ -52,7 +52,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:58:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:64:15 | LL | Self: Default; | ^^^^^^^ @@ -60,7 +60,7 @@ LL | Self: Default; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:93:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:100:15 | LL | Self: Iterator, | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 9bd83d089af3e..32f6027e99111 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -22,30 +22,41 @@ unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { let _: &'a U = core::intrinsics::transmute(t); let _: *const T = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer + //~| NOTE: `-D clippy::useless-transmute` implied by `-D warnings` let _: *mut T = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer let _: *const U = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer } #[warn(clippy::useless_transmute)] fn useless() { unsafe { let _: Vec = core::intrinsics::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = core::mem::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = std::intrinsics::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = std::mem::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = my_transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: *const usize = std::mem::transmute(5_isize); + //~^ ERROR: transmute from an integer to a pointer let _ = 5_isize as *const usize; let _: *const usize = std::mem::transmute(1 + 1usize); + //~^ ERROR: transmute from an integer to a pointer let _ = (1 + 1_usize) as *const usize; } @@ -77,19 +88,27 @@ fn crosspointer() { unsafe { let _: Usize = core::intrinsics::transmute(int_const_ptr); + //~^ ERROR: transmute from a type (`*const Usize`) to the type that it points to ( + //~| NOTE: `-D clippy::crosspointer-transmute` implied by `-D warnings` let _: Usize = core::intrinsics::transmute(int_mut_ptr); + //~^ ERROR: transmute from a type (`*mut Usize`) to the type that it points to (`U let _: *const Usize = core::intrinsics::transmute(my_int()); + //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*const Usi let _: *mut Usize = core::intrinsics::transmute(my_int()); + //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize } } #[warn(clippy::transmute_int_to_char)] fn int_to_char() { let _: char = unsafe { std::mem::transmute(0_u32) }; + //~^ ERROR: transmute from a `u32` to a `char` + //~| NOTE: `-D clippy::transmute-int-to-char` implied by `-D warnings` let _: char = unsafe { std::mem::transmute(0_i32) }; + //~^ ERROR: transmute from a `i32` to a `char` // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; @@ -99,15 +118,22 @@ fn int_to_char() { #[warn(clippy::transmute_int_to_bool)] fn int_to_bool() { let _: bool = unsafe { std::mem::transmute(0_u8) }; + //~^ ERROR: transmute from a `u8` to a `bool` + //~| NOTE: `-D clippy::transmute-int-to-bool` implied by `-D warnings` } #[warn(clippy::transmute_int_to_float)] mod int_to_float { fn test() { let _: f32 = unsafe { std::mem::transmute(0_u32) }; + //~^ ERROR: transmute from a `u32` to a `f32` + //~| NOTE: `-D clippy::transmute-int-to-float` implied by `-D warnings` let _: f32 = unsafe { std::mem::transmute(0_i32) }; + //~^ ERROR: transmute from a `i32` to a `f32` let _: f64 = unsafe { std::mem::transmute(0_u64) }; + //~^ ERROR: transmute from a `u64` to a `f64` let _: f64 = unsafe { std::mem::transmute(0_i64) }; + //~^ ERROR: transmute from a `i64` to a `f64` } mod issue_5747 { @@ -128,23 +154,38 @@ mod num_to_bytes { fn test() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); + //~^ ERROR: transmute from a `u8` to a `[u8; 1]` + //~| NOTE: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` let _: [u8; 4] = std::mem::transmute(0u32); + //~^ ERROR: transmute from a `u32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0u128); + //~^ ERROR: transmute from a `u128` to a `[u8; 16]` let _: [u8; 1] = std::mem::transmute(0i8); + //~^ ERROR: transmute from a `i8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0i32); + //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); + //~^ ERROR: transmute from a `i128` to a `[u8; 16]` let _: [u8; 4] = std::mem::transmute(0.0f32); + //~^ ERROR: transmute from a `f32` to a `[u8; 4]` let _: [u8; 8] = std::mem::transmute(0.0f64); + //~^ ERROR: transmute from a `f64` to a `[u8; 8]` } } const fn test_const() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); + //~^ ERROR: transmute from a `u8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0u32); + //~^ ERROR: transmute from a `u32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0u128); + //~^ ERROR: transmute from a `u128` to a `[u8; 16]` let _: [u8; 1] = std::mem::transmute(0i8); + //~^ ERROR: transmute from a `i8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0i32); + //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); + //~^ ERROR: transmute from a `i128` to a `[u8; 16]` let _: [u8; 4] = std::mem::transmute(0.0f32); let _: [u8; 8] = std::mem::transmute(0.0f64); } @@ -155,8 +196,12 @@ fn bytes_to_str(mb: &mut [u8]) { const B: &[u8] = b""; let _: &str = unsafe { std::mem::transmute(B) }; + //~^ ERROR: transmute from a `&[u8]` to a `&str` + //~| NOTE: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` let _: &mut str = unsafe { std::mem::transmute(mb) }; + //~^ ERROR: transmute from a `&mut [u8]` to a `&mut str` const _: &str = unsafe { std::mem::transmute(B) }; + //~^ ERROR: transmute from a `&[u8]` to a `&str` } fn main() {} diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index 008b4a981d7e6..2765f763d6df7 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -7,61 +7,61 @@ LL | let _: *const T = core::intrinsics::transmute(t); = note: `-D clippy::useless-transmute` implied by `-D warnings` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:26:21 + --> $DIR/transmute.rs:28:21 | LL | let _: *mut T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:28:23 + --> $DIR/transmute.rs:31:23 | LL | let _: *const U = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:34:27 + --> $DIR/transmute.rs:38:27 | LL | let _: Vec = core::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:36:27 + --> $DIR/transmute.rs:41:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:38:27 + --> $DIR/transmute.rs:44:27 | LL | let _: Vec = std::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:40:27 + --> $DIR/transmute.rs:47:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:42:27 + --> $DIR/transmute.rs:50:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> $DIR/transmute.rs:44:31 + --> $DIR/transmute.rs:53:31 | LL | let _: *const usize = std::mem::transmute(5_isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` error: transmute from an integer to a pointer - --> $DIR/transmute.rs:48:31 + --> $DIR/transmute.rs:58:31 | LL | let _: *const usize = std::mem::transmute(1 + 1usize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize` error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:79:24 + --> $DIR/transmute.rs:90:24 | LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,25 +69,25 @@ LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); = note: `-D clippy::crosspointer-transmute` implied by `-D warnings` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:81:24 + --> $DIR/transmute.rs:94:24 | LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> $DIR/transmute.rs:83:31 + --> $DIR/transmute.rs:97:31 | LL | let _: *const Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> $DIR/transmute.rs:85:29 + --> $DIR/transmute.rs:100:29 | LL | let _: *mut Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u32` to a `char` - --> $DIR/transmute.rs:91:28 + --> $DIR/transmute.rs:107:28 | LL | let _: char = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()` @@ -95,13 +95,13 @@ LL | let _: char = unsafe { std::mem::transmute(0_u32) }; = note: `-D clippy::transmute-int-to-char` implied by `-D warnings` error: transmute from a `i32` to a `char` - --> $DIR/transmute.rs:92:28 + --> $DIR/transmute.rs:110:28 | LL | let _: char = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` error: transmute from a `u8` to a `bool` - --> $DIR/transmute.rs:101:28 + --> $DIR/transmute.rs:120:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -109,7 +109,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` error: transmute from a `u32` to a `f32` - --> $DIR/transmute.rs:107:31 + --> $DIR/transmute.rs:128:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` @@ -117,25 +117,25 @@ LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` error: transmute from a `i32` to a `f32` - --> $DIR/transmute.rs:108:31 + --> $DIR/transmute.rs:131:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` error: transmute from a `u64` to a `f64` - --> $DIR/transmute.rs:109:31 + --> $DIR/transmute.rs:133:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)` error: transmute from a `i64` to a `f64` - --> $DIR/transmute.rs:110:31 + --> $DIR/transmute.rs:135:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `u8` to a `[u8; 1]` - --> $DIR/transmute.rs:130:30 + --> $DIR/transmute.rs:156:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` @@ -143,85 +143,85 @@ LL | let _: [u8; 1] = std::mem::transmute(0u8); = note: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` error: transmute from a `u32` to a `[u8; 4]` - --> $DIR/transmute.rs:131:30 + --> $DIR/transmute.rs:159:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> $DIR/transmute.rs:132:31 + --> $DIR/transmute.rs:161:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> $DIR/transmute.rs:133:30 + --> $DIR/transmute.rs:163:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> $DIR/transmute.rs:134:30 + --> $DIR/transmute.rs:165:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> $DIR/transmute.rs:135:31 + --> $DIR/transmute.rs:167:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> $DIR/transmute.rs:136:30 + --> $DIR/transmute.rs:169:30 | LL | let _: [u8; 4] = std::mem::transmute(0.0f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f32.to_ne_bytes()` error: transmute from a `f64` to a `[u8; 8]` - --> $DIR/transmute.rs:137:30 + --> $DIR/transmute.rs:171:30 | LL | let _: [u8; 8] = std::mem::transmute(0.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f64.to_ne_bytes()` error: transmute from a `u8` to a `[u8; 1]` - --> $DIR/transmute.rs:142:30 + --> $DIR/transmute.rs:177:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` error: transmute from a `u32` to a `[u8; 4]` - --> $DIR/transmute.rs:143:30 + --> $DIR/transmute.rs:179:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> $DIR/transmute.rs:144:31 + --> $DIR/transmute.rs:181:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> $DIR/transmute.rs:145:30 + --> $DIR/transmute.rs:183:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> $DIR/transmute.rs:146:30 + --> $DIR/transmute.rs:185:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> $DIR/transmute.rs:147:31 + --> $DIR/transmute.rs:187:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:157:28 + --> $DIR/transmute.rs:198:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` @@ -229,13 +229,13 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; = note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` error: transmute from a `&mut [u8]` to a `&mut str` - --> $DIR/transmute.rs:158:32 + --> $DIR/transmute.rs:201:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:159:30 + --> $DIR/transmute.rs:203:30 | LL | const _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)` diff --git a/tests/ui/transmute_64bit.rs b/tests/ui/transmute_64bit.rs index ceecf9b279f06..767cc503a39df 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -4,7 +4,10 @@ fn main() { unsafe { let _: *const usize = std::mem::transmute(6.0f64); + //~^ ERROR: transmute from a `f64` to a pointer + //~| NOTE: `-D clippy::wrong-transmute` implied by `-D warnings` let _: *mut usize = std::mem::transmute(6.0f64); + //~^ ERROR: transmute from a `f64` to a pointer } } diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index d1854c009ef56..32d7e6bdf421a 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -7,7 +7,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); = note: `-D clippy::wrong-transmute` implied by `-D warnings` error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:8:29 + --> $DIR/transmute_64bit.rs:10:29 | LL | let _: *mut usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_collection.rs b/tests/ui/transmute_collection.rs index 5a431bee04a45..8bf454573355f 100644 --- a/tests/ui/transmute_collection.rs +++ b/tests/ui/transmute_collection.rs @@ -7,42 +7,61 @@ fn main() { unsafe { // wrong size let _ = transmute::<_, Vec>(vec![0u8]); + //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec` with mismat + //~| NOTE: `-D clippy::unsound-collection-transmute` implied by `-D warnings` // wrong layout let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); + //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with m // wrong size let _ = transmute::<_, VecDeque>(VecDeque::::new()); + //~^ ERROR: transmute from `std::collections::VecDeque` to `std::collections:: // wrong layout let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collecti // wrong size let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); + //~^ ERROR: transmute from `std::collections::BinaryHeap` to `std::collections // wrong layout let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collec // wrong size let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); + //~^ ERROR: transmute from `std::collections::BTreeSet` to `std::collections:: // wrong layout let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collecti // wrong size let _ = transmute::<_, HashSet>(HashSet::::new()); + //~^ ERROR: transmute from `std::collections::HashSet` to `std::collections::H // wrong layout let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collectio // wrong size let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collectio let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collect // wrong layout let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::coll let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::col // wrong size let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::collection let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::collecti // wrong layout let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::colle let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); + //~^ ERROR: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::coll let _ = transmute::<_, Vec>(Vec::>::new()); let _ = transmute::<_, Vec<*mut u32>>(Vec::>::new()); diff --git a/tests/ui/transmute_collection.stderr b/tests/ui/transmute_collection.stderr index ebc05c402abf6..e4b9963be89b3 100644 --- a/tests/ui/transmute_collection.stderr +++ b/tests/ui/transmute_collection.stderr @@ -7,103 +7,103 @@ LL | let _ = transmute::<_, Vec>(vec![0u8]); = note: `-D clippy::unsound-collection-transmute` implied by `-D warnings` error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:11:17 + --> $DIR/transmute_collection.rs:13:17 | LL | let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:14:17 + --> $DIR/transmute_collection.rs:17:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:16:17 + --> $DIR/transmute_collection.rs:20:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:19:17 + --> $DIR/transmute_collection.rs:24:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:21:17 + --> $DIR/transmute_collection.rs:27:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:24:17 + --> $DIR/transmute_collection.rs:31:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:26:17 + --> $DIR/transmute_collection.rs:34:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:29:17 + --> $DIR/transmute_collection.rs:38:17 | LL | let _ = transmute::<_, HashSet>(HashSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:31:17 + --> $DIR/transmute_collection.rs:41:17 | LL | let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:34:17 + --> $DIR/transmute_collection.rs:45:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:35:17 + --> $DIR/transmute_collection.rs:47:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:37:17 + --> $DIR/transmute_collection.rs:50:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:38:17 + --> $DIR/transmute_collection.rs:52:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:41:17 + --> $DIR/transmute_collection.rs:56:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:42:17 + --> $DIR/transmute_collection.rs:58:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:44:17 + --> $DIR/transmute_collection.rs:61:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:45:17 + --> $DIR/transmute_collection.rs:63:17 | LL | let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_float_to_int.fixed b/tests/ui/transmute_float_to_int.fixed index 37dbb9141da3a..cef0bcfa623ae 100644 --- a/tests/ui/transmute_float_to_int.fixed +++ b/tests/ui/transmute_float_to_int.fixed @@ -2,11 +2,18 @@ fn float_to_int() { let _: u32 = unsafe { 1f32.to_bits() }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` let _: i32 = unsafe { 1f32.to_bits() as i32 }; + //~^ ERROR: transmute from a `f32` to a `i32` let _: u64 = unsafe { 1f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: i64 = unsafe { 1f64.to_bits() as i64 }; + //~^ ERROR: transmute from a `f64` to a `i64` let _: u64 = unsafe { 1.0f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: u64 = unsafe { (-1.0f64).to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` } mod issue_5747 { diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index 806b2d77dc77d..3d95bec2a20a9 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -2,11 +2,18 @@ fn float_to_int() { let _: u32 = unsafe { std::mem::transmute(1f32) }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` let _: i32 = unsafe { std::mem::transmute(1f32) }; + //~^ ERROR: transmute from a `f32` to a `i32` let _: u64 = unsafe { std::mem::transmute(1f64) }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: i64 = unsafe { std::mem::transmute(1f64) }; + //~^ ERROR: transmute from a `f64` to a `i64` let _: u64 = unsafe { std::mem::transmute(1.0) }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: u64 = unsafe { std::mem::transmute(-1.0) }; + //~^ ERROR: transmute from a `f64` to a `u64` } mod issue_5747 { diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index eb786bb39f95a..dd21c0cde2c42 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -7,31 +7,31 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; = note: `-D clippy::transmute-float-to-int` implied by `-D warnings` error: transmute from a `f32` to a `i32` - --> $DIR/transmute_float_to_int.rs:5:27 + --> $DIR/transmute_float_to_int.rs:7:27 | LL | let _: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:6:27 + --> $DIR/transmute_float_to_int.rs:9:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> $DIR/transmute_float_to_int.rs:7:27 + --> $DIR/transmute_float_to_int.rs:11:27 | LL | let _: i64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:8:27 + --> $DIR/transmute_float_to_int.rs:13:27 | LL | let _: u64 = unsafe { std::mem::transmute(1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:9:27 + --> $DIR/transmute_float_to_int.rs:15:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed index b055a7c31c29b..866c0bbf1271e 100644 --- a/tests/ui/transmute_int_to_non_zero.fixed +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -16,16 +16,27 @@ fn main() { let int_i128: i128 = 1; let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZeroU16` let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZeroU32` let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZeroU64` let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZeroU128` let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZeroI8` let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZeroI16` let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZeroI32` let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZeroI64` let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZeroI128` let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; diff --git a/tests/ui/transmute_int_to_non_zero.rs b/tests/ui/transmute_int_to_non_zero.rs index a384067825068..803c4945c755a 100644 --- a/tests/ui/transmute_int_to_non_zero.rs +++ b/tests/ui/transmute_int_to_non_zero.rs @@ -16,16 +16,27 @@ fn main() { let int_i128: i128 = 1; let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZeroU16` let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZeroU32` let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZeroU64` let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZeroU128` let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZeroI8` let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZeroI16` let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZeroI32` let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZeroI64` let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZeroI128` let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr index 33f8ce79ea780..9efba88f38f6b 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -7,55 +7,55 @@ LL | let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; = note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` error: transmute from a `u16` to a `NonZeroU16` - --> $DIR/transmute_int_to_non_zero.rs:19:34 + --> $DIR/transmute_int_to_non_zero.rs:21:34 | LL | let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU16::new_unchecked(int_u16)` error: transmute from a `u32` to a `NonZeroU32` - --> $DIR/transmute_int_to_non_zero.rs:20:34 + --> $DIR/transmute_int_to_non_zero.rs:23:34 | LL | let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU32::new_unchecked(int_u32)` error: transmute from a `u64` to a `NonZeroU64` - --> $DIR/transmute_int_to_non_zero.rs:21:34 + --> $DIR/transmute_int_to_non_zero.rs:25:34 | LL | let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU64::new_unchecked(int_u64)` error: transmute from a `u128` to a `NonZeroU128` - --> $DIR/transmute_int_to_non_zero.rs:22:35 + --> $DIR/transmute_int_to_non_zero.rs:27:35 | LL | let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU128::new_unchecked(int_u128)` error: transmute from a `i8` to a `NonZeroI8` - --> $DIR/transmute_int_to_non_zero.rs:24:33 + --> $DIR/transmute_int_to_non_zero.rs:30:33 | LL | let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI8::new_unchecked(int_i8)` error: transmute from a `i16` to a `NonZeroI16` - --> $DIR/transmute_int_to_non_zero.rs:25:34 + --> $DIR/transmute_int_to_non_zero.rs:32:34 | LL | let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI16::new_unchecked(int_i16)` error: transmute from a `i32` to a `NonZeroI32` - --> $DIR/transmute_int_to_non_zero.rs:26:34 + --> $DIR/transmute_int_to_non_zero.rs:34:34 | LL | let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI32::new_unchecked(int_i32)` error: transmute from a `i64` to a `NonZeroI64` - --> $DIR/transmute_int_to_non_zero.rs:27:34 + --> $DIR/transmute_int_to_non_zero.rs:36:34 | LL | let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI64::new_unchecked(int_i64)` error: transmute from a `i128` to a `NonZeroI128` - --> $DIR/transmute_int_to_non_zero.rs:28:35 + --> $DIR/transmute_int_to_non_zero.rs:38:35 | LL | let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI128::new_unchecked(int_i128)` diff --git a/tests/ui/transmute_null_to_fn.rs b/tests/ui/transmute_null_to_fn.rs index b3ea3d9039e08..7d780c803ffd5 100644 --- a/tests/ui/transmute_null_to_fn.rs +++ b/tests/ui/transmute_null_to_fn.rs @@ -6,7 +6,9 @@ fn one_liners() { unsafe { let _: fn() = std::mem::transmute(0 as *const ()); + //~^ ERROR: transmuting a known null pointer into a function pointer let _: fn() = std::mem::transmute(std::ptr::null::<()>()); + //~^ ERROR: transmuting a known null pointer into a function pointer } } @@ -17,6 +19,7 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: fn() = std::mem::transmute(ZPTR); + //~^ ERROR: transmuting a known null pointer into a function pointer // Should NOT raise a lint. let _: fn() = std::mem::transmute(NOT_ZPTR); } diff --git a/tests/ui/transmute_null_to_fn.stderr b/tests/ui/transmute_null_to_fn.stderr index f0c65497d750e..6278f51dde25d 100644 --- a/tests/ui/transmute_null_to_fn.stderr +++ b/tests/ui/transmute_null_to_fn.stderr @@ -8,7 +8,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const ()); = note: `-D clippy::transmute-null-to-fn` implied by `-D warnings` error: transmuting a known null pointer into a function pointer - --> $DIR/transmute_null_to_fn.rs:9:23 + --> $DIR/transmute_null_to_fn.rs:10:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -16,7 +16,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> $DIR/transmute_null_to_fn.rs:19:23 + --> $DIR/transmute_null_to_fn.rs:21:23 | LL | let _: fn() = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior diff --git a/tests/ui/transmute_ptr_to_ptr.fixed b/tests/ui/transmute_ptr_to_ptr.fixed index 5380c49b96a12..19abced98bb85 100644 --- a/tests/ui/transmute_ptr_to_ptr.fixed +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -28,14 +28,21 @@ fn transmute_ptr_to_ptr() { unsafe { // pointer-to-pointer transmutes; bad let _: *const f32 = ptr as *const f32; + //~^ ERROR: transmute from a pointer to a pointer + //~| NOTE: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` let _: *mut f32 = mut_ptr as *mut f32; + //~^ ERROR: transmute from a pointer to a pointer // ref-ref transmutes; bad let _: &f32 = &*(&1u32 as *const u32 as *const f32); + //~^ ERROR: transmute from a reference to a reference let _: &f64 = &*(&1f32 as *const f32 as *const f64); + //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type let _: &mut f32 = &mut *(&mut 1u32 as *mut u32 as *mut f32); + //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = &*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam); + //~^ ERROR: transmute from a reference to a reference } // these are recommendations for solving the above; if these lint we need to update diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 61a6c98ed5ac7..abba2b8e5244d 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -28,14 +28,21 @@ fn transmute_ptr_to_ptr() { unsafe { // pointer-to-pointer transmutes; bad let _: *const f32 = std::mem::transmute(ptr); + //~^ ERROR: transmute from a pointer to a pointer + //~| NOTE: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` let _: *mut f32 = std::mem::transmute(mut_ptr); + //~^ ERROR: transmute from a pointer to a pointer // ref-ref transmutes; bad let _: &f32 = std::mem::transmute(&1u32); + //~^ ERROR: transmute from a reference to a reference let _: &f64 = std::mem::transmute(&1f32); + //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type let _: &mut f32 = std::mem::transmute(&mut 1u32); + //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); + //~^ ERROR: transmute from a reference to a reference } // these are recommendations for solving the above; if these lint we need to update diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 49a8a3347e404..ee414e46bb748 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -7,31 +7,31 @@ LL | let _: *const f32 = std::mem::transmute(ptr); = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmute_ptr_to_ptr.rs:31:27 + --> $DIR/transmute_ptr_to_ptr.rs:33:27 | LL | let _: *mut f32 = std::mem::transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `mut_ptr as *mut f32` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:33:23 + --> $DIR/transmute_ptr_to_ptr.rs:36:23 | LL | let _: &f32 = std::mem::transmute(&1u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:34:23 + --> $DIR/transmute_ptr_to_ptr.rs:38:23 | LL | let _: &f64 = std::mem::transmute(&1f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:37:27 + --> $DIR/transmute_ptr_to_ptr.rs:42:27 | LL | let _: &mut f32 = std::mem::transmute(&mut 1u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:38:37 + --> $DIR/transmute_ptr_to_ptr.rs:44:37 | LL | let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index 6afb1915e7e58..a087d09c1202a 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -27,8 +27,11 @@ fn main() { // Lint, Ty2 is unordered let _: Ty2C = transmute(value::>()); + //~^ ERROR: transmute from `Ty2` which has an undefined layout + //~| NOTE: `-D clippy::transmute-undefined-repr` implied by `-D warnings` // Lint, Ty2 is unordered let _: Ty2 = transmute(value::>()); + //~^ ERROR: transmute into `Ty2` which has an undefined layout // Ok, Ty2 types are the same let _: Ty2 = transmute(value::>>()); @@ -37,16 +40,24 @@ fn main() { // Lint, different Ty2 instances let _: Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `Ty>` to `Ty2`, both of which h + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Lint, different Ty2 instances let _: Ty> = transmute(value::>()); + //~^ ERROR: transmute from `Ty2` to `Ty>`, both of which h + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); // Lint, different Ty2 instances let _: &Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `Ty<&Ty2>` to `&Ty2`, both of which + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Lint, different Ty2 instances let _: Ty<&Ty2> = transmute(value::<&Ty2>()); + //~^ ERROR: transmute from `&Ty2` to `Ty<&Ty2>`, both of which + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Ok, pointer to usize conversion let _: Ty = transmute(value::<&Ty2>()); @@ -75,8 +86,12 @@ fn main() { // Lint, different Ty2 instances let _: &'static mut Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `std::boxed::Box>` to `&mut Ty2 + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Lint, different Ty2 instances let _: Box> = transmute(value::<&'static mut Ty2>()); + //~^ ERROR: transmute from `&mut Ty2` to `std::boxed::Box> + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Ok, type erasure let _: *const () = transmute(value::>>()); @@ -172,8 +187,12 @@ fn main() { // Err let _: *const Ty2 = transmute(value::<*const Ty2C>>()); + //~^ ERROR: transmute into `*const Ty2` which has an undefined layout + //~| NOTE: the contained type `Ty2` has an undefined layout // Err let _: *const Ty2C> = transmute(value::<*const Ty2>()); + //~^ ERROR: transmute from `*const Ty2` which has an undefined layout + //~| NOTE: the contained type `Ty2` has an undefined layout // Ok let _: NonNull = transmute(value::>()); @@ -219,8 +238,12 @@ fn _with_generics() { // Err let _: Vec> = transmute(value::>>()); + //~^ ERROR: transmute from `std::vec::Vec>` to `std::vec::Vec> = transmute(value::>>()); + //~^ ERROR: transmute from `std::vec::Vec>` to `std::vec::Vec>()); diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index 220bcb5b528dc..3618213ecd505 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -7,13 +7,13 @@ LL | let _: Ty2C = transmute(value::>()); = note: `-D clippy::transmute-undefined-repr` implied by `-D warnings` error: transmute into `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:31:32 + --> $DIR/transmute_undefined_repr.rs:33:32 | LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:39:32 + --> $DIR/transmute_undefined_repr.rs:42:32 | LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let _: Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty2` to `Ty>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:41:36 + --> $DIR/transmute_undefined_repr.rs:46:36 | LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | let _: Ty> = transmute(value::>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty<&Ty2>` to `&Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:47:33 + --> $DIR/transmute_undefined_repr.rs:54:33 | LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let _: &Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&Ty2` to `Ty<&Ty2>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:49:37 + --> $DIR/transmute_undefined_repr.rs:58:37 | LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `std::boxed::Box>` to `&mut Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:77:45 + --> $DIR/transmute_undefined_repr.rs:88:45 | LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | let _: &'static mut Ty2 = transmute(value::` to `std::boxed::Box>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:79:37 + --> $DIR/transmute_undefined_repr.rs:92:37 | LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _: Box> = transmute(value::<&'static mut Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:174:39 + --> $DIR/transmute_undefined_repr.rs:189:39 | LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL | let _: *const Ty2 = transmute(value::<*const Ty2C` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:176:50 + --> $DIR/transmute_undefined_repr.rs:193:50 | LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | let _: *const Ty2C> = transmute(value::<*const T = note: the contained type `Ty2` has an undefined layout error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:221:35 + --> $DIR/transmute_undefined_repr.rs:240:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | let _: Vec> = transmute(value::>>()); = note: two instances of the same generic type (`Vec`) may have different layouts error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:223:35 + --> $DIR/transmute_undefined_repr.rs:244:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmuting_null.rs b/tests/ui/transmuting_null.rs index ea3ee8edc81b1..88b8c9965237d 100644 --- a/tests/ui/transmuting_null.rs +++ b/tests/ui/transmuting_null.rs @@ -8,7 +8,10 @@ fn one_liners() { unsafe { let _: &u64 = std::mem::transmute(0 as *const u64); + //~^ ERROR: transmuting a known null pointer into a reference + //~| NOTE: `-D clippy::transmuting-null` implied by `-D warnings` let _: &u64 = std::mem::transmute(std::ptr::null::()); + //~^ ERROR: transmuting a known null pointer into a reference } } @@ -19,6 +22,7 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: &u64 = std::mem::transmute(ZPTR); + //~^ ERROR: transmuting a known null pointer into a reference // Should NOT raise a lint. let _: &u64 = std::mem::transmute(NOT_ZPTR); } diff --git a/tests/ui/transmuting_null.stderr b/tests/ui/transmuting_null.stderr index 1848fc2490a00..a8de01ec15dc4 100644 --- a/tests/ui/transmuting_null.stderr +++ b/tests/ui/transmuting_null.stderr @@ -7,13 +7,13 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); = note: `-D clippy::transmuting-null` implied by `-D warnings` error: transmuting a known null pointer into a reference - --> $DIR/transmuting_null.rs:11:23 + --> $DIR/transmuting_null.rs:13:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> $DIR/transmuting_null.rs:21:23 + --> $DIR/transmuting_null.rs:24:23 | LL | let _: &u64 = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type_complexity.rs b/tests/ui/type_complexity.rs index 816950110b201..be28ee2da0cd4 100644 --- a/tests/ui/type_complexity.rs +++ b/tests/ui/type_complexity.rs @@ -5,29 +5,42 @@ type Alias = Vec>>; // no warning here const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~| NOTE: `-D clippy::type-complexity` implied by `-D warnings` static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions struct S { f: Vec>>, + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } struct Ts(Vec>>); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions enum E { Tuple(Vec>>), + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions Struct { f: Vec>> }, + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } impl S { const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn impl_method(&self, p: Vec>>) {} + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } trait T { const A: Vec>>; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions type B = Vec>>; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn method(&self, p: Vec>>); + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn def_method(&self, p: Vec>>) {} + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } // Should not warn since there is likely no way to simplify this (#1013) @@ -40,13 +53,16 @@ impl T for () { } fn test1() -> Vec>> { + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions vec![] } fn test2(_x: Vec>>) {} +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn test3() { let _y: Vec>> = vec![]; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } #[repr(C)] diff --git a/tests/ui/type_complexity.stderr b/tests/ui/type_complexity.stderr index 9da7edb1c3b74..496dacfbfde61 100644 --- a/tests/ui/type_complexity.stderr +++ b/tests/ui/type_complexity.stderr @@ -7,85 +7,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); = note: `-D clippy::type-complexity` implied by `-D warnings` error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:8:12 + --> $DIR/type_complexity.rs:10:12 | LL | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:11:8 + --> $DIR/type_complexity.rs:14:8 | LL | f: Vec>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:14:11 + --> $DIR/type_complexity.rs:18:11 | LL | struct Ts(Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:17:11 + --> $DIR/type_complexity.rs:22:11 | LL | Tuple(Vec>>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:18:17 + --> $DIR/type_complexity.rs:24:17 | LL | Struct { f: Vec>> }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:22:14 + --> $DIR/type_complexity.rs:29:14 | LL | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:23:30 + --> $DIR/type_complexity.rs:31:30 | LL | fn impl_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:27:14 + --> $DIR/type_complexity.rs:36:14 | LL | const A: Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:28:14 + --> $DIR/type_complexity.rs:38:14 | LL | type B = Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:29:25 + --> $DIR/type_complexity.rs:40:25 | LL | fn method(&self, p: Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:30:29 + --> $DIR/type_complexity.rs:42:29 | LL | fn def_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:42:15 + --> $DIR/type_complexity.rs:55:15 | LL | fn test1() -> Vec>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:46:14 + --> $DIR/type_complexity.rs:60:14 | LL | fn test2(_x: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:49:13 + --> $DIR/type_complexity.rs:64:13 | LL | let _y: Vec>> = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type_repetition_in_bounds.rs b/tests/ui/type_repetition_in_bounds.rs index 874d97f7a46c7..504a003940502 100644 --- a/tests/ui/type_repetition_in_bounds.rs +++ b/tests/ui/type_repetition_in_bounds.rs @@ -8,6 +8,7 @@ pub fn foo(_t: T) where T: Copy, T: Clone, + //~^ ERROR: this type has already been used as a bound predicate { unimplemented!(); } @@ -25,6 +26,7 @@ trait LintBounds where Self: Clone, Self: Copy + Default + Ord, + //~^ ERROR: this type has already been used as a bound predicate Self: Add + AddAssign + Sub + SubAssign, Self: Mul + MulAssign + Div + DivAssign, { @@ -99,11 +101,13 @@ where pub fn f() where T: Clone, + //~^ ERROR: this type has already been used as a bound predicate { } pub fn g() where T: ?Sized, + //~^ ERROR: this type has already been used as a bound predicate { } @@ -129,6 +133,7 @@ mod issue8772_pass { pub fn f(arg: usize) where T: Trait, Box<[String]>, bool> + 'static, + //~^ ERROR: this type has already been used as a bound predicate U: Clone + Sync + 'static, { } diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr index 54973c5bda572..607cd1fbf6a7b 100644 --- a/tests/ui/type_repetition_in_bounds.stderr +++ b/tests/ui/type_repetition_in_bounds.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::type_repetition_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:27:5 + --> $DIR/type_repetition_in_bounds.rs:28:5 | LL | Self: Copy + Default + Ord, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | Self: Copy + Default + Ord, = help: consider combining the bounds: `Self: Clone + Copy + Default + Ord` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:101:5 + --> $DIR/type_repetition_in_bounds.rs:103:5 | LL | T: Clone, | ^^^^^^^^ @@ -28,7 +28,7 @@ LL | T: Clone, = help: consider combining the bounds: `T: ?Sized + Clone` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:106:5 + --> $DIR/type_repetition_in_bounds.rs:109:5 | LL | T: ?Sized, | ^^^^^^^^^ @@ -36,7 +36,7 @@ LL | T: ?Sized, = help: consider combining the bounds: `T: Clone + ?Sized` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:131:9 + --> $DIR/type_repetition_in_bounds.rs:135:9 | LL | T: Trait, Box<[String]>, bool> + 'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs index 2d567630e15de..10a4c22b5b91c 100644 --- a/tests/ui/uninit.rs +++ b/tests/ui/uninit.rs @@ -10,6 +10,8 @@ union MyOwnMaybeUninit { fn main() { let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior + //~| NOTE: `#[deny(clippy::uninit_assumed_init)]` on by default // This is OK, because ZSTs do not contain data. let _: () = unsafe { MaybeUninit::uninit().assume_init() }; @@ -31,6 +33,7 @@ fn main() { // Was a false negative. let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior polymorphic::<()>(); polymorphic_maybe_uninit_array::<10>(); @@ -39,6 +42,7 @@ fn main() { fn polymorphic() { // We are conservative around polymorphic types. let _: T = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior } fn polymorphic_maybe_uninit_array() { diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit.stderr index 248de56da76cb..1cc27ffe70d5d 100644 --- a/tests/ui/uninit.stderr +++ b/tests/ui/uninit.stderr @@ -7,13 +7,13 @@ LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; = note: `#[deny(clippy::uninit_assumed_init)]` on by default error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:33:29 + --> $DIR/uninit.rs:35:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:41:29 + --> $DIR/uninit.rs:44:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninit_vec.rs b/tests/ui/uninit_vec.rs index 79effc82fdf7c..c069b9adf2d96 100644 --- a/tests/ui/uninit_vec.rs +++ b/tests/ui/uninit_vec.rs @@ -15,29 +15,34 @@ union MyOwnMaybeUninit { fn main() { // with_capacity() -> set_len() should be detected let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { vec.set_len(200); } // reserve() -> set_len() should be detected vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { vec.set_len(200); } // new() -> set_len() should be detected let mut vec: Vec = Vec::new(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } // default() -> set_len() should be detected let mut vec: Vec = Default::default(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } let mut vec: Vec = Vec::default(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } @@ -45,13 +50,16 @@ fn main() { // test when both calls are enclosed in the same unsafe block unsafe { let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini vec.set_len(200); vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini vec.set_len(200); } let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { // test the case where there are other statements in the following unsafe block vec.set_len(200); @@ -61,11 +69,13 @@ fn main() { // handle vec stored in the field of a struct let mut my_vec = MyVec::default(); my_vec.vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { my_vec.vec.set_len(200); } my_vec.vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { my_vec.vec.set_len(200); } @@ -120,6 +130,7 @@ fn main() { fn polymorphic() { // We are conservative around polymorphic types. let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini unsafe { vec.set_len(10); } diff --git a/tests/ui/uninit_vec.stderr b/tests/ui/uninit_vec.stderr index 9cdf0c95ad9f1..1ffea9f8730de 100644 --- a/tests/ui/uninit_vec.stderr +++ b/tests/ui/uninit_vec.stderr @@ -3,7 +3,7 @@ error: calling `set_len()` immediately after reserving a buffer creates uninitia | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | @@ -11,45 +11,45 @@ LL | vec.set_len(200); = note: `-D clippy::uninit-vec` implied by `-D warnings` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:23:5 + --> $DIR/uninit_vec.rs:24:5 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:29:5 + --> $DIR/uninit_vec.rs:31:5 | LL | let mut vec: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:35:5 + --> $DIR/uninit_vec.rs:38:5 | LL | let mut vec: Vec = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:40:5 + --> $DIR/uninit_vec.rs:44:5 | LL | let mut vec: Vec = Vec::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:54:5 + --> $DIR/uninit_vec.rs:61:5 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,53 +60,55 @@ LL | vec.set_len(200); = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:63:5 + --> $DIR/uninit_vec.rs:71:5 | LL | my_vec.vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | my_vec.vec.set_len(200); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:68:5 + --> $DIR/uninit_vec.rs:77:5 | LL | my_vec.vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | my_vec.vec.set_len(200); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:47:9 + --> $DIR/uninit_vec.rs:52:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:50:9 + --> $DIR/uninit_vec.rs:56:9 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:122:9 + --> $DIR/uninit_vec.rs:132:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(10); | ^^^^^^^^^^^^^^^ | diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index fc75f548a1bcc..cea89026da6f1 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -15,18 +15,22 @@ fn main() { // this warns if { + //~^ ERROR: ==-comparison of unit values detected. This will always be true + //~| NOTE: `-D clippy::unit-cmp` implied by `-D warnings` true; } == { false; } {} if { + //~^ ERROR: >-comparison of unit values detected. This will always be false true; } > { false; } {} assert_eq!( + //~^ ERROR: `assert_eq` of unit values detected. This will always succeed { true; }, @@ -35,6 +39,7 @@ fn main() { } ); debug_assert_eq!( + //~^ ERROR: `debug_assert_eq` of unit values detected. This will always succeed { true; }, @@ -44,6 +49,7 @@ fn main() { ); assert_ne!( + //~^ ERROR: `assert_ne` of unit values detected. This will always fail { true; }, @@ -52,6 +58,7 @@ fn main() { } ); debug_assert_ne!( + //~^ ERROR: `debug_assert_ne` of unit values detected. This will always fail { true; }, diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 79c890d644cd4..38618c59180c1 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -3,6 +3,8 @@ error: ==-comparison of unit values detected. This will always be true | LL | if { | ________^ +LL | | +LL | | LL | | true; LL | | } == { LL | | false; @@ -12,10 +14,11 @@ LL | | } {} = note: `-D clippy::unit-cmp` implied by `-D warnings` error: >-comparison of unit values detected. This will always be false - --> $DIR/unit_cmp.rs:23:8 + --> $DIR/unit_cmp.rs:25:8 | LL | if { | ________^ +LL | | LL | | true; LL | | } > { LL | | false; @@ -23,48 +26,48 @@ LL | | } {} | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:29:5 + --> $DIR/unit_cmp.rs:32:5 | LL | / assert_eq!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `debug_assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:37:5 + --> $DIR/unit_cmp.rs:41:5 | LL | / debug_assert_eq!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:46:5 + --> $DIR/unit_cmp.rs:51:5 | LL | / assert_ne!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `debug_assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:54:5 + --> $DIR/unit_cmp.rs:60:5 | LL | / debug_assert_ne!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); diff --git a/tests/ui/unit_hash.fixed b/tests/ui/unit_hash.fixed index 18d39dc3fc531..ed0facf1b9635 100644 --- a/tests/ui/unit_hash.fixed +++ b/tests/ui/unit_hash.fixed @@ -17,12 +17,18 @@ fn main() { match my_enum { Foo::Empty => 0_u8.hash(&mut state), + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op Foo::WithValue(x) => x.hash(&mut state), } let res = (); 0_u8.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op #[allow(clippy::unit_arg)] 0_u8.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op } diff --git a/tests/ui/unit_hash.rs b/tests/ui/unit_hash.rs index 43eb54eff477b..f3636d1644da9 100644 --- a/tests/ui/unit_hash.rs +++ b/tests/ui/unit_hash.rs @@ -17,12 +17,18 @@ fn main() { match my_enum { Foo::Empty => ().hash(&mut state), + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op Foo::WithValue(x) => x.hash(&mut state), } let res = (); res.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op #[allow(clippy::unit_arg)] do_nothing().hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op } diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index 089d1212dd17a..eeb48cf7f37fb 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -8,7 +8,7 @@ LL | Foo::Empty => ().hash(&mut state), = note: `-D clippy::unit-hash` implied by `-D warnings` error: this call to `hash` on the unit type will do nothing - --> $DIR/unit_hash.rs:24:5 + --> $DIR/unit_hash.rs:26:5 | LL | res.hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -16,7 +16,7 @@ LL | res.hash(&mut state); = note: the implementation of `Hash` for `()` is a no-op error: this call to `hash` on the unit type will do nothing - --> $DIR/unit_hash.rs:27:5 + --> $DIR/unit_hash.rs:31:5 | LL | do_nothing().hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` diff --git a/tests/ui/unit_return_expecting_ord.rs b/tests/ui/unit_return_expecting_ord.rs index f2a9694f99e5b..59b2f7e355b34 100644 --- a/tests/ui/unit_return_expecting_ord.rs +++ b/tests/ui/unit_return_expecting_ord.rs @@ -17,13 +17,16 @@ fn unit(_i: isize) {} fn main() { let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }]; structs.sort_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements Ord double(s.field); }); structs.sort_by_key(|s| double(s.field)); structs.is_sorted_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements PartialOrd double(s.field); }); structs.is_sorted_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements PartialOrd if s.field > 0 { () } else { @@ -34,4 +37,5 @@ fn main() { return double(s.field); }); structs.sort_by_key(|s| unit(s.field)); + //~^ ERROR: this closure returns the unit type which also implements Ord } diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr index 3a295af55eac9..74e6d6b126297 100644 --- a/tests/ui/unit_return_expecting_ord.stderr +++ b/tests/ui/unit_return_expecting_ord.stderr @@ -5,32 +5,32 @@ LL | structs.sort_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:20:24 + --> $DIR/unit_return_expecting_ord.rs:21:24 | LL | double(s.field); | ^ = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:23:30 + --> $DIR/unit_return_expecting_ord.rs:24:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:24:24 + --> $DIR/unit_return_expecting_ord.rs:26:24 | LL | double(s.field); | ^ error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:26:30 + --> $DIR/unit_return_expecting_ord.rs:28:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ error: this closure returns the unit type which also implements Ord - --> $DIR/unit_return_expecting_ord.rs:36:25 + --> $DIR/unit_return_expecting_ord.rs:39:25 | LL | structs.sort_by_key(|s| unit(s.field)); | ^^^ diff --git a/tests/ui/unknown_attribute.rs b/tests/ui/unknown_attribute.rs index e993e63f8ed86..932f284d5b713 100644 --- a/tests/ui/unknown_attribute.rs +++ b/tests/ui/unknown_attribute.rs @@ -1,3 +1,4 @@ #[clippy::unknown] +//~^ ERROR: usage of unknown attribute #[clippy::cognitive_complexity = "1"] fn main() {} diff --git a/tests/ui/unnecessary_box_returns.rs b/tests/ui/unnecessary_box_returns.rs index bbe52d3735464..bcdaca33b6449 100644 --- a/tests/ui/unnecessary_box_returns.rs +++ b/tests/ui/unnecessary_box_returns.rs @@ -3,6 +3,7 @@ trait Bar { // lint fn baz(&self) -> Box; + //~^ ERROR: boxed return of the sized type `usize` } pub struct Foo {} @@ -16,6 +17,7 @@ impl Bar for Foo { impl Foo { fn baz(&self) -> Box { + //~^ ERROR: boxed return of the sized type `usize` // lint Box::new(13) } @@ -23,11 +25,13 @@ impl Foo { // lint fn bxed_usize() -> Box { + //~^ ERROR: boxed return of the sized type `usize` Box::new(5) } // lint fn _bxed_foo() -> Box { + //~^ ERROR: boxed return of the sized type `Foo` Box::new(Foo {}) } diff --git a/tests/ui/unnecessary_box_returns.stderr b/tests/ui/unnecessary_box_returns.stderr index b17512c10a177..8909dbcdd9855 100644 --- a/tests/ui/unnecessary_box_returns.stderr +++ b/tests/ui/unnecessary_box_returns.stderr @@ -8,7 +8,7 @@ LL | fn baz(&self) -> Box; = note: `-D clippy::unnecessary-box-returns` implied by `-D warnings` error: boxed return of the sized type `usize` - --> $DIR/unnecessary_box_returns.rs:18:22 + --> $DIR/unnecessary_box_returns.rs:19:22 | LL | fn baz(&self) -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -16,7 +16,7 @@ LL | fn baz(&self) -> Box { = help: changing this also requires a change to the return expressions in this function error: boxed return of the sized type `usize` - --> $DIR/unnecessary_box_returns.rs:25:20 + --> $DIR/unnecessary_box_returns.rs:27:20 | LL | fn bxed_usize() -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -24,7 +24,7 @@ LL | fn bxed_usize() -> Box { = help: changing this also requires a change to the return expressions in this function error: boxed return of the sized type `Foo` - --> $DIR/unnecessary_box_returns.rs:30:19 + --> $DIR/unnecessary_box_returns.rs:33:19 | LL | fn _bxed_foo() -> Box { | ^^^^^^^^ help: try: `Foo` diff --git a/tests/ui/unnecessary_cast_unfixable.rs b/tests/ui/unnecessary_cast_unfixable.rs index 89a50314fbcbf..36adf19c91ca7 100644 --- a/tests/ui/unnecessary_cast_unfixable.rs +++ b/tests/ui/unnecessary_cast_unfixable.rs @@ -2,6 +2,8 @@ //@no-rustfix fn main() { let _ = std::ptr::null() as *const u8; + //~^ ERROR: casting raw pointers to the same type and constness is unnecessary (`*cons + //~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings` } mod issue11113 { @@ -17,6 +19,7 @@ mod issue11113 { impl TearOff { unsafe fn query(&self) { ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() + //~^ ERROR: casting raw pointers to the same type and constness is unnecessary } } } diff --git a/tests/ui/unnecessary_cast_unfixable.stderr b/tests/ui/unnecessary_cast_unfixable.stderr index eecf245686a84..ef3632db9f1d4 100644 --- a/tests/ui/unnecessary_cast_unfixable.stderr +++ b/tests/ui/unnecessary_cast_unfixable.stderr @@ -7,7 +7,7 @@ LL | let _ = std::ptr::null() as *const u8; = note: `-D clippy::unnecessary-cast` implied by `-D warnings` error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) - --> $DIR/unnecessary_cast_unfixable.rs:19:16 + --> $DIR/unnecessary_cast_unfixable.rs:21:16 | LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)` diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 90dd65a1d42fb..12ac96aa64caa 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -21,25 +21,34 @@ fn clone_on_ref_ptr() { let arc_weak = Arc::downgrade(&arc); rc.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer + //~| NOTE: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` Rc::clone(&rc); arc.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer Arc::clone(&arc); rcweak.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer rc::Weak::clone(&rcweak); arc_weak.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer sync::Weak::clone(&arc_weak); let x = Arc::new(SomeImpl); let _: Arc = x.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer } fn clone_on_copy_generic(t: T) { t.clone(); + //~^ ERROR: using `clone` on type `T` which implements the `Copy` trait + //~| NOTE: `-D clippy::clone-on-copy` implied by `-D warnings` Some(t).clone(); + //~^ ERROR: using `clone` on type `Option` which implements the `Copy` trait } mod many_derefs { @@ -74,6 +83,7 @@ mod many_derefs { fn go1() { let a = A; let _: E = a.clone(); + //~^ ERROR: using `clone` on type `E` which implements the `Copy` trait let _: E = *****a; } } @@ -93,5 +103,6 @@ mod issue2076 { fn func() -> Option> { let rc = Rc::new(42); Some(try_opt!(Some(rc)).clone()) + //~^ ERROR: using `.clone()` on a ref-counted pointer } } diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 23639f6d41a04..da387e8bb7c3c 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -7,31 +7,31 @@ LL | rc.clone(); = note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:26:5 + --> $DIR/unnecessary_clone.rs:28:5 | LL | arc.clone(); | ^^^^^^^^^^^ help: try: `Arc::::clone(&arc)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:29:5 + --> $DIR/unnecessary_clone.rs:32:5 | LL | rcweak.clone(); | ^^^^^^^^^^^^^^ help: try: `Weak::::clone(&rcweak)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:32:5 + --> $DIR/unnecessary_clone.rs:36:5 | LL | arc_weak.clone(); | ^^^^^^^^^^^^^^^^ help: try: `Weak::::clone(&arc_weak)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:36:33 + --> $DIR/unnecessary_clone.rs:41:33 | LL | let _: Arc = x.clone(); | ^^^^^^^^^ help: try: `Arc::::clone(&x)` error: using `clone` on type `T` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:40:5 + --> $DIR/unnecessary_clone.rs:46:5 | LL | t.clone(); | ^^^^^^^^^ help: try removing the `clone` call: `t` @@ -39,19 +39,19 @@ LL | t.clone(); = note: `-D clippy::clone-on-copy` implied by `-D warnings` error: using `clone` on type `Option` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:42:5 + --> $DIR/unnecessary_clone.rs:50:5 | LL | Some(t).clone(); | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` error: using `clone` on type `E` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:76:20 + --> $DIR/unnecessary_clone.rs:85:20 | LL | let _: E = a.clone(); | ^^^^^^^^^ help: try dereferencing it: `*****a` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:95:14 + --> $DIR/unnecessary_clone.rs:105:14 | LL | Some(try_opt!(Some(rc)).clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc::::clone(&try_opt!(Some(rc)))` diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index 3c8c6ec94c1b6..1e0d7d12965c2 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -2,18 +2,23 @@ fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` + //~| NOTE: `-D clippy::unnecessary-filter-map` implied by `-D warnings` let _ = (0..4).filter_map(|x| { + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` if x > 1 { return Some(x); }; None }); let _ = (0..4).filter_map(|x| match x { + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` 0 | 1 => None, _ => Some(x), }); let _ = (0..4).filter_map(|x| Some(x + 1)); + //~^ ERROR: this `.filter_map` can be written more simply using `.map` let _ = (0..4).filter_map(i32::checked_abs); } diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr index 2d5403ce39444..f34acdc8d7e62 100644 --- a/tests/ui/unnecessary_filter_map.stderr +++ b/tests/ui/unnecessary_filter_map.stderr @@ -7,10 +7,11 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); = note: `-D clippy::unnecessary-filter-map` implied by `-D warnings` error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:5:13 + --> $DIR/unnecessary_filter_map.rs:7:13 | LL | let _ = (0..4).filter_map(|x| { | _____________^ +LL | | LL | | if x > 1 { LL | | return Some(x); LL | | }; @@ -19,23 +20,24 @@ LL | | }); | |______^ error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:11:13 + --> $DIR/unnecessary_filter_map.rs:14:13 | LL | let _ = (0..4).filter_map(|x| match x { | _____________^ +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ error: this `.filter_map` can be written more simply using `.map` - --> $DIR/unnecessary_filter_map.rs:16:13 + --> $DIR/unnecessary_filter_map.rs:20:13 | LL | let _ = (0..4).filter_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:155:14 + --> $DIR/unnecessary_filter_map.rs:160:14 | LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_find_map.rs b/tests/ui/unnecessary_find_map.rs index 2c228fbbc9597..9972b68092abf 100644 --- a/tests/ui/unnecessary_find_map.rs +++ b/tests/ui/unnecessary_find_map.rs @@ -2,18 +2,23 @@ fn main() { let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); + //~^ ERROR: this `.find_map` can be written more simply using `.find` + //~| NOTE: `-D clippy::unnecessary-find-map` implied by `-D warnings` let _ = (0..4).find_map(|x| { + //~^ ERROR: this `.find_map` can be written more simply using `.find` if x > 1 { return Some(x); }; None }); let _ = (0..4).find_map(|x| match x { + //~^ ERROR: this `.find_map` can be written more simply using `.find` 0 | 1 => None, _ => Some(x), }); let _ = (0..4).find_map(|x| Some(x + 1)); + //~^ ERROR: this `.find_map` can be written more simply using `.map(..).next()` let _ = (0..4).find_map(i32::checked_abs); } diff --git a/tests/ui/unnecessary_find_map.stderr b/tests/ui/unnecessary_find_map.stderr index 3a995b41b179e..9acbd6650024a 100644 --- a/tests/ui/unnecessary_find_map.stderr +++ b/tests/ui/unnecessary_find_map.stderr @@ -7,10 +7,11 @@ LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); = note: `-D clippy::unnecessary-find-map` implied by `-D warnings` error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:5:13 + --> $DIR/unnecessary_find_map.rs:7:13 | LL | let _ = (0..4).find_map(|x| { | _____________^ +LL | | LL | | if x > 1 { LL | | return Some(x); LL | | }; @@ -19,23 +20,24 @@ LL | | }); | |______^ error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:11:13 + --> $DIR/unnecessary_find_map.rs:14:13 | LL | let _ = (0..4).find_map(|x| match x { | _____________^ +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ error: this `.find_map` can be written more simply using `.map(..).next()` - --> $DIR/unnecessary_find_map.rs:16:13 + --> $DIR/unnecessary_find_map.rs:20:13 | LL | let _ = (0..4).find_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:27:14 + --> $DIR/unnecessary_find_map.rs:32:14 | LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index d529cd3109cfe..33685bfb738b0 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -11,11 +11,15 @@ struct SomeStruct { fn main() { // fix will break type inference let _ = Ok(1).unwrap_or_else(|()| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` + //~| NOTE: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` mod e { pub struct E; } let _ = Ok(1).unwrap_or_else(|e::E| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` // Fix #6343 let arr = [(Some(1),)]; diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 7f353ba06982a..8bff2a6377935 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -9,7 +9,7 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2); = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13 + --> $DIR/unnecessary_lazy_eval_unfixable.rs:19:13 | LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | ^^^^^^------------------------ @@ -17,7 +17,7 @@ LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:18:13 + --> $DIR/unnecessary_lazy_eval_unfixable.rs:21:13 | LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ^^^^^^------------------------------------- diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs index 2671ecf678124..61058b7988a2d 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -5,102 +5,154 @@ fn unwrap_option_some() { let val = Some(1); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value } fn unwrap_option_some_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value } fn unwrap_option_none() { let val = None::<()>; let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `None` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `None` value let _val3: u8 = None.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `None` value None::<()>.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `None` value } fn unwrap_result_ok() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val2 = val.expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value } fn unwrap_result_ok_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val2 = val.expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value } fn unwrap_result_err() { let val = Err::<(), _>(1); let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val2 = val.expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value } fn unwrap_result_err_context() { let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value let val = Err::<(), usize>([1, 2, 3].iter().sum()); let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val2 = val.expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value } fn unwrap_methods_option() { let val = Some(1); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val2 = val.unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value } fn unwrap_methods_option_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val2 = val.unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value } fn unwrap_methods_result() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val2 = val.unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value } fn unwrap_methods_result_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val2 = val.unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index 2d1270d47174f..2a60896c0a3c7 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -12,7 +12,7 @@ LL | let val = Some(1); = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings` error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:8:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:9:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,589 +24,589 @@ LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:20:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:17:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:28:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:23:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:24:21 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:21 | LL | let _val3: u8 = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:25:5 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:5 | LL | None::<()>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:33:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:46:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:55:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:55:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:45:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:46:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:52:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:75:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:54:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:86:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:86:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:64:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:66:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:106:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:108:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:74:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:110:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:117:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:117:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:123:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:125:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:85:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:127:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:133:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:91:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:135:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:92:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:137:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:142:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:142:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:150:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:102:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:152:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:103:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:154:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index d858701ae8ac5..d9a7ad8e56c57 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -4,14 +4,19 @@ mod unsafe_items_invalid_comment { // SAFETY: const CONST: u32 = 0; + //~^ ERROR: constant item has unnecessary safety comment // SAFETY: static STATIC: u32 = 0; + //~^ ERROR: static item has unnecessary safety comment // SAFETY: struct Struct; + //~^ ERROR: struct has unnecessary safety comment // SAFETY: enum Enum {} + //~^ ERROR: enum has unnecessary safety comment // SAFETY: mod module {} + //~^ ERROR: module has unnecessary safety comment } mod unnecessary_from_macro { @@ -40,12 +45,15 @@ mod unnecessary_from_macro { fn unnecessary_on_stmt_and_expr() -> u32 { // SAFETY: unnecessary let num = 42; + //~^ ERROR: statement has unnecessary safety comment // SAFETY: unnecessary if num > 24 {} + //~^ ERROR: statement has unnecessary safety comment // SAFETY: unnecessary 24 + //~^ ERROR: expression has unnecessary safety comment } mod issue_10084 { diff --git a/tests/ui/unnecessary_safety_comment.stderr b/tests/ui/unnecessary_safety_comment.stderr index 7b2af67d64c7b..d97048e270367 100644 --- a/tests/ui/unnecessary_safety_comment.stderr +++ b/tests/ui/unnecessary_safety_comment.stderr @@ -12,55 +12,55 @@ LL | // SAFETY: = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` error: static item has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:8:5 + --> $DIR/unnecessary_safety_comment.rs:9:5 | LL | static STATIC: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:7:5 + --> $DIR/unnecessary_safety_comment.rs:8:5 | LL | // SAFETY: | ^^^^^^^^^^ error: struct has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:10:5 + --> $DIR/unnecessary_safety_comment.rs:12:5 | LL | struct Struct; | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:9:5 + --> $DIR/unnecessary_safety_comment.rs:11:5 | LL | // SAFETY: | ^^^^^^^^^^ error: enum has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:12:5 + --> $DIR/unnecessary_safety_comment.rs:15:5 | LL | enum Enum {} | ^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:11:5 + --> $DIR/unnecessary_safety_comment.rs:14:5 | LL | // SAFETY: | ^^^^^^^^^^ error: module has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:14:5 + --> $DIR/unnecessary_safety_comment.rs:18:5 | LL | mod module {} | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:13:5 + --> $DIR/unnecessary_safety_comment.rs:17:5 | LL | // SAFETY: | ^^^^^^^^^^ error: impl has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:33:13 + --> $DIR/unnecessary_safety_comment.rs:38:13 | LL | impl T for $t {} | ^^^^^^^^^^^^^^^^ @@ -69,44 +69,44 @@ LL | with_safety_comment!(i32); | ------------------------- in this macro invocation | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:32:13 + --> $DIR/unnecessary_safety_comment.rs:37:13 | LL | // Safety: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `with_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: expression has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:48:5 + --> $DIR/unnecessary_safety_comment.rs:55:5 | LL | 24 | ^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:47:5 + --> $DIR/unnecessary_safety_comment.rs:54:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:42:5 + --> $DIR/unnecessary_safety_comment.rs:47:5 | LL | let num = 42; | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:41:5 + --> $DIR/unnecessary_safety_comment.rs:46:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:45:5 + --> $DIR/unnecessary_safety_comment.rs:51:5 | LL | if num > 24 {} | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:44:5 + --> $DIR/unnecessary_safety_comment.rs:50:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index fa92143e980dd..200aefff1bbf4 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -7,6 +7,8 @@ // should be linted fn func1(a: bool, b: bool) -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` + //~| NOTE: `-D clippy::unnecessary-wraps` implied by `-D warnings` if a && b { return Some(42); } @@ -20,6 +22,7 @@ fn func1(a: bool, b: bool) -> Option { // should be linted fn func2(a: bool, b: bool) -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` if a && b { return Some(10); } @@ -38,6 +41,7 @@ fn func4(a: bool) -> Option { // should be linted fn func5() -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` Some(1) } @@ -48,6 +52,7 @@ fn func6() -> Option { // should be linted fn func7() -> Result { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Result` Ok(1) } @@ -76,6 +81,7 @@ impl A { // should be linted fn func12() -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` Some(1) } } @@ -103,6 +109,7 @@ fn issue_6384(s: &str) -> Option<&str> { // should be linted fn issue_6640_1(a: bool, b: bool) -> Option<()> { + //~^ ERROR: this function's return value is unnecessary if a && b { return Some(()); } @@ -116,6 +123,7 @@ fn issue_6640_1(a: bool, b: bool) -> Option<()> { // should be linted fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { + //~^ ERROR: this function's return value is unnecessary if a && b { return Ok(()); } diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index d29235165359d..01340a0abddf4 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -2,9 +2,9 @@ error: this function's return value is unnecessarily wrapped by `Option` --> $DIR/unnecessary_wraps.rs:9:1 | LL | / fn func1(a: bool, b: bool) -> Option { +LL | | +LL | | LL | | if a && b { -LL | | return Some(42); -LL | | } ... | LL | | } LL | | } @@ -27,9 +27,10 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:22:1 + --> $DIR/unnecessary_wraps.rs:24:1 | LL | / fn func2(a: bool, b: bool) -> Option { +LL | | LL | | if a && b { LL | | return Some(10); LL | | } @@ -49,9 +50,10 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:40:1 + --> $DIR/unnecessary_wraps.rs:43:1 | LL | / fn func5() -> Option { +LL | | LL | | Some(1) LL | | } | |_^ @@ -66,9 +68,10 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> $DIR/unnecessary_wraps.rs:50:1 + --> $DIR/unnecessary_wraps.rs:54:1 | LL | / fn func7() -> Result { +LL | | LL | | Ok(1) LL | | } | |_^ @@ -83,9 +86,10 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:78:5 + --> $DIR/unnecessary_wraps.rs:83:5 | LL | / fn func12() -> Option { +LL | | LL | | Some(1) LL | | } | |_____^ @@ -100,12 +104,12 @@ LL | 1 | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:105:1 + --> $DIR/unnecessary_wraps.rs:111:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { +LL | | LL | | if a && b { LL | | return Some(()); -LL | | } ... | LL | | } LL | | } @@ -127,12 +131,12 @@ LL ~ return ; | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:118:1 + --> $DIR/unnecessary_wraps.rs:125:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { +LL | | LL | | if a && b { LL | | return Ok(()); -LL | | } ... | LL | | } LL | | } diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs index bafca91917aa4..70dcaa3afa455 100644 --- a/tests/ui/unsafe_derive_deserialize.rs +++ b/tests/ui/unsafe_derive_deserialize.rs @@ -6,6 +6,7 @@ extern crate serde; use serde::Deserialize; #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct A; impl A { pub unsafe fn new(_a: i32, _b: i32) -> Self { @@ -14,12 +15,14 @@ impl A { } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct B; impl B { pub unsafe fn unsafe_method(&self) {} } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct C; impl C { pub fn unsafe_block(&self) { @@ -28,6 +31,7 @@ impl C { } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct D; impl D { pub fn inner_unsafe_fn(&self) { diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr index 8aaae2d7fff48..7b96500fd115a 100644 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ b/tests/ui/unsafe_derive_deserialize.stderr @@ -9,7 +9,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:16:10 + --> $DIR/unsafe_derive_deserialize.rs:17:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:22:10 + --> $DIR/unsafe_derive_deserialize.rs:24:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:30:10 + --> $DIR/unsafe_derive_deserialize.rs:33:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index 04f6ef29a9a15..e0e0ded140fc0 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -3,8 +3,11 @@ #![warn(clippy::unsafe_removed_from_name)] use std::cell::UnsafeCell as TotallySafeCell; +//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCell` +//~| NOTE: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` use std::cell::UnsafeCell as TotallySafeCellAgain; +//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain // Shouldn't error use std::cell::RefCell as ProbablyNotUnsafe; @@ -23,9 +26,12 @@ mod mod_with_some_unsafe_things { } use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; +//~^ ERROR: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` // merged imports use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; +//~^ ERROR: removed `unsafe` from the name of `Unsafe` in use as `A` +//~| ERROR: removed `unsafe` from the name of `Unsafe` in use as `B` // Shouldn't error use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime; diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr index 090d917bd3846..5daa69e1fb4d1 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -7,25 +7,25 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; = note: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> $DIR/unsafe_removed_from_name.rs:7:1 + --> $DIR/unsafe_removed_from_name.rs:9:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> $DIR/unsafe_removed_from_name.rs:25:1 + --> $DIR/unsafe_removed_from_name.rs:28:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `A` - --> $DIR/unsafe_removed_from_name.rs:28:1 + --> $DIR/unsafe_removed_from_name.rs:32:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `B` - --> $DIR/unsafe_removed_from_name.rs:28:1 + --> $DIR/unsafe_removed_from_name.rs:32:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index 1d188025e418d..71722e9afd0b8 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -11,6 +11,7 @@ mod issue10800 { use std::future::ready; async fn async_block_await() { + //~^ ERROR: unused `async` for function with no await statements async { ready(()).await; }; @@ -43,6 +44,7 @@ mod issue9695 { async fn f() {} async fn f2() {} async fn f3() {} + //~^ ERROR: unused `async` for function with no await statements fn needs_async_fn>(_: fn() -> F) {} @@ -55,6 +57,7 @@ mod issue9695 { } async fn foo() -> i32 { + //~^ ERROR: unused `async` for function with no await statements 4 } @@ -66,6 +69,7 @@ struct S; impl S { async fn unused(&self) -> i32 { + //~^ ERROR: unused `async` for function with no await statements 1 } diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 8d9b72c4886c2..06944f8f8d8d6 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -2,6 +2,7 @@ error: unused `async` for function with no await statements --> $DIR/unused_async.rs:13:5 | LL | / async fn async_block_await() { +LL | | LL | | async { LL | | ready(()).await; LL | | }; @@ -10,14 +11,14 @@ LL | | } | = help: consider removing the `async` from this function note: `await` used in an async block, which does not require the enclosing function to be `async` - --> $DIR/unused_async.rs:15:23 + --> $DIR/unused_async.rs:16:23 | LL | ready(()).await; | ^^^^^ = note: `-D clippy::unused-async` implied by `-D warnings` error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:45:5 + --> $DIR/unused_async.rs:46:5 | LL | async fn f3() {} | ^^^^^^^^^^^^^^^^ @@ -25,9 +26,10 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:57:1 + --> $DIR/unused_async.rs:59:1 | LL | / async fn foo() -> i32 { +LL | | LL | | 4 LL | | } | |_^ @@ -35,9 +37,10 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:68:5 + --> $DIR/unused_async.rs:71:5 | LL | / async fn unused(&self) -> i32 { +LL | | LL | | 1 LL | | } | |_____^ diff --git a/tests/ui/unused_format_specs_unfixable.rs b/tests/ui/unused_format_specs_unfixable.rs index c10cff1b55e6a..be991935366fe 100644 --- a/tests/ui/unused_format_specs_unfixable.rs +++ b/tests/ui/unused_format_specs_unfixable.rs @@ -10,13 +10,18 @@ macro_rules! format_args_from_macro { fn main() { // prints `.`, not ` .` println!("{:5}.", format_args!("")); + //~^ ERROR: format specifiers have no effect on `format_args!()` + //~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings` //prints `abcde`, not `abc` println!("{:.3}", format_args!("abcde")); + //~^ ERROR: format specifiers have no effect on `format_args!()` println!("{:5}.", format_args_from_macro!()); + //~^ ERROR: format specifiers have no effect on `format_args!()` let args = format_args!(""); println!("{args:5}"); + //~^ ERROR: format specifiers have no effect on `format_args!()` } fn should_not_lint() { diff --git a/tests/ui/unused_format_specs_unfixable.stderr b/tests/ui/unused_format_specs_unfixable.stderr index cb7156b6baf0d..e9145ff382a73 100644 --- a/tests/ui/unused_format_specs_unfixable.stderr +++ b/tests/ui/unused_format_specs_unfixable.stderr @@ -16,7 +16,7 @@ LL + println!("{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:14:15 + --> $DIR/unused_format_specs_unfixable.rs:16:15 | LL | println!("{:.3}", format_args!("abcde")); | ^^^^^ @@ -32,7 +32,7 @@ LL + println!("{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:16:15 + --> $DIR/unused_format_specs_unfixable.rs:19:15 | LL | println!("{:5}.", format_args_from_macro!()); | ^^^^ @@ -45,7 +45,7 @@ LL + println!("{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:19:15 + --> $DIR/unused_format_specs_unfixable.rs:23:15 | LL | println!("{args:5}"); | ^^^^^^^^ diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index e9d1eeb31612c..62aec6e9eafca 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -7,20 +7,26 @@ use std::io::{self, Read}; fn question_mark(s: &mut T) -> io::Result<()> { s.write(b"test")?; + //~^ ERROR: written amount is not handled let mut buf = [0u8; 4]; s.read(&mut buf)?; + //~^ ERROR: read amount is not handled Ok(()) } fn unwrap(s: &mut T) { s.write(b"test").unwrap(); + //~^ ERROR: written amount is not handled let mut buf = [0u8; 4]; s.read(&mut buf).unwrap(); + //~^ ERROR: read amount is not handled } fn vectored(s: &mut T) -> io::Result<()> { s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; + //~^ ERROR: read amount is not handled s.write_vectored(&[io::IoSlice::new(&[])])?; + //~^ ERROR: written amount is not handled Ok(()) } @@ -28,6 +34,7 @@ fn ok(file: &str) -> Option<()> { let mut reader = std::fs::File::open(file).ok()?; let mut result = [0u8; 0]; reader.read(&mut result).ok()?; + //~^ ERROR: read amount is not handled Some(()) } @@ -37,6 +44,7 @@ fn or_else(file: &str) -> io::Result<()> { let mut reader = std::fs::File::open(file)?; let mut result = [0u8; 0]; reader.read(&mut result).or_else(|err| Err(err))?; + //~^ ERROR: read amount is not handled Ok(()) } @@ -49,6 +57,7 @@ fn or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader.read(&mut result).or(Err(Error::Kind))?; + //~^ ERROR: read amount is not handled Ok(()) } @@ -56,6 +65,7 @@ fn combine_or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader + //~^ ERROR: read amount is not handled .read(&mut result) .or(Err(Error::Kind)) .or(Err(Error::Kind)) @@ -65,19 +75,25 @@ fn combine_or(file: &str) -> Result<(), Error> { fn is_ok_err(s: &mut T) { s.write(b"ok").is_ok(); + //~^ ERROR: written amount is not handled s.write(b"err").is_err(); + //~^ ERROR: written amount is not handled let mut buf = [0u8; 0]; s.read(&mut buf).is_ok(); + //~^ ERROR: read amount is not handled s.read(&mut buf).is_err(); + //~^ ERROR: read amount is not handled } async fn bad_async_write(w: &mut W) { w.write(b"hello world").await.unwrap(); + //~^ ERROR: written amount is not handled } async fn bad_async_read(r: &mut R) { let mut buf = [0u8; 0]; r.read(&mut buf[..]).await.unwrap(); + //~^ ERROR: read amount is not handled } async fn io_not_ignored_async_write(mut w: W) { @@ -91,6 +107,7 @@ fn bad_async_write_closure(w: W) -> impl future let mut w = w; async move { w.write(b"hello world").await?; + //~^ ERROR: written amount is not handled Ok(()) } } @@ -99,6 +116,7 @@ async fn async_read_nested_or(r: &mut R, do_it: bool) -> R let mut buf = [0u8; 1]; if do_it { r.read(&mut buf[..]).await.or(Err(Error::Kind))?; + //~^ ERROR: read amount is not handled } Ok(buf) } @@ -107,11 +125,13 @@ use tokio::io::{AsyncRead as TokioAsyncRead, AsyncReadExt as _, AsyncWrite as To async fn bad_async_write_tokio(w: &mut W) { w.write(b"hello world").await.unwrap(); + //~^ ERROR: written amount is not handled } async fn bad_async_read_tokio(r: &mut R) { let mut buf = [0u8; 0]; r.read(&mut buf[..]).await.unwrap(); + //~^ ERROR: read amount is not handled } async fn undetected_bad_async_write(w: &mut W) { diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 0865c5213f687..c729a0b90166d 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -8,7 +8,7 @@ LL | s.write(b"test")?; = note: `-D clippy::unused-io-amount` implied by `-D warnings` error: read amount is not handled - --> $DIR/unused_io_amount.rs:11:5 + --> $DIR/unused_io_amount.rs:12:5 | LL | s.read(&mut buf)?; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | s.read(&mut buf)?; = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:16:5 + --> $DIR/unused_io_amount.rs:18:5 | LL | s.write(b"test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | s.write(b"test").unwrap(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:18:5 + --> $DIR/unused_io_amount.rs:21:5 | LL | s.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,19 +32,19 @@ LL | s.read(&mut buf).unwrap(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:22:5 + --> $DIR/unused_io_amount.rs:26:5 | LL | s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: written amount is not handled - --> $DIR/unused_io_amount.rs:23:5 + --> $DIR/unused_io_amount.rs:28:5 | LL | s.write_vectored(&[io::IoSlice::new(&[])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: read amount is not handled - --> $DIR/unused_io_amount.rs:30:5 + --> $DIR/unused_io_amount.rs:36:5 | LL | reader.read(&mut result).ok()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | reader.read(&mut result).ok()?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:39:5 + --> $DIR/unused_io_amount.rs:46:5 | LL | reader.read(&mut result).or_else(|err| Err(err))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | reader.read(&mut result).or_else(|err| Err(err))?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:51:5 + --> $DIR/unused_io_amount.rs:59:5 | LL | reader.read(&mut result).or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,9 +68,10 @@ LL | reader.read(&mut result).or(Err(Error::Kind))?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:58:5 + --> $DIR/unused_io_amount.rs:67:5 | LL | / reader +LL | | LL | | .read(&mut result) LL | | .or(Err(Error::Kind)) LL | | .or(Err(Error::Kind)) @@ -80,7 +81,7 @@ LL | | .expect("error"); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:67:5 + --> $DIR/unused_io_amount.rs:77:5 | LL | s.write(b"ok").is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | s.write(b"ok").is_ok(); = help: use `Write::write_all` instead, or handle partial writes error: written amount is not handled - --> $DIR/unused_io_amount.rs:68:5 + --> $DIR/unused_io_amount.rs:79:5 | LL | s.write(b"err").is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | s.write(b"err").is_err(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:70:5 + --> $DIR/unused_io_amount.rs:82:5 | LL | s.read(&mut buf).is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL | s.read(&mut buf).is_ok(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:71:5 + --> $DIR/unused_io_amount.rs:84:5 | LL | s.read(&mut buf).is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | s.read(&mut buf).is_err(); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:75:5 + --> $DIR/unused_io_amount.rs:89:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:80:5 + --> $DIR/unused_io_amount.rs:95:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -128,7 +129,7 @@ LL | r.read(&mut buf[..]).await.unwrap(); = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:93:9 + --> $DIR/unused_io_amount.rs:109:9 | LL | w.write(b"hello world").await?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +137,7 @@ LL | w.write(b"hello world").await?; = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:101:9 + --> $DIR/unused_io_amount.rs:118:9 | LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +145,7 @@ LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:109:5 + --> $DIR/unused_io_amount.rs:127:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -152,7 +153,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:114:5 + --> $DIR/unused_io_amount.rs:133:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_peekable.rs b/tests/ui/unused_peekable.rs index b227f8660f53c..131b51e01b6f0 100644 --- a/tests/ui/unused_peekable.rs +++ b/tests/ui/unused_peekable.rs @@ -11,14 +11,17 @@ fn main() { #[allow(clippy::unused_unit)] fn invalid() { let peekable = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator // Only lint `new_local` let old_local = std::iter::empty::().peekable(); let new_local = old_local; + //~^ ERROR: `peek` never called on `Peekable` iterator // Behind mut ref let mut by_mut_ref_test = std::iter::empty::().peekable(); let by_mut_ref = &mut by_mut_ref_test; + //~^ ERROR: `peek` never called on `Peekable` iterator // Explicitly returns `Peekable` fn returns_peekable() -> Peekable> { @@ -26,21 +29,26 @@ fn invalid() { } let peekable_from_fn = returns_peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator // Using a method not exclusive to `Peekable` let mut peekable_using_iterator_method = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator peekable_using_iterator_method.next(); // Passed by ref to another function fn takes_ref(_peek: &Peekable>) {} let passed_along_ref = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator takes_ref(&passed_along_ref); // `by_ref` without `peek` let mut by_ref_test = std::iter::empty::().peekable(); let _by_ref = by_ref_test.by_ref(); + //~^ ERROR: `peek` never called on `Peekable` iterator let mut peekable_in_for_loop = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator for x in peekable_in_for_loop {} } diff --git a/tests/ui/unused_peekable.stderr b/tests/ui/unused_peekable.stderr index d969232fdf3b1..896ca49d710c9 100644 --- a/tests/ui/unused_peekable.stderr +++ b/tests/ui/unused_peekable.stderr @@ -8,7 +8,7 @@ LL | let peekable = std::iter::empty::().peekable(); = note: `-D clippy::unused-peekable` implied by `-D warnings` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:17:9 + --> $DIR/unused_peekable.rs:18:9 | LL | let new_local = old_local; | ^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let new_local = old_local; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:21:9 + --> $DIR/unused_peekable.rs:23:9 | LL | let by_mut_ref = &mut by_mut_ref_test; | ^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let by_mut_ref = &mut by_mut_ref_test; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:28:9 + --> $DIR/unused_peekable.rs:31:9 | LL | let peekable_from_fn = returns_peekable(); | ^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let peekable_from_fn = returns_peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:31:13 + --> $DIR/unused_peekable.rs:35:13 | LL | let mut peekable_using_iterator_method = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let mut peekable_using_iterator_method = std::iter::empty::().peek = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:36:9 + --> $DIR/unused_peekable.rs:41:9 | LL | let passed_along_ref = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let passed_along_ref = std::iter::empty::().peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:41:9 + --> $DIR/unused_peekable.rs:47:9 | LL | let _by_ref = by_ref_test.by_ref(); | ^^^^^^^ @@ -56,7 +56,7 @@ LL | let _by_ref = by_ref_test.by_ref(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:43:13 + --> $DIR/unused_peekable.rs:50:13 | LL | let mut peekable_in_for_loop = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_self.rs b/tests/ui/unused_self.rs index 55bd5607185c6..d3d06037cb494 100644 --- a/tests/ui/unused_self.rs +++ b/tests/ui/unused_self.rs @@ -9,16 +9,25 @@ mod unused_self { impl A { fn unused_self_move(self) {} + //~^ ERROR: unused `self` argument fn unused_self_ref(&self) {} + //~^ ERROR: unused `self` argument fn unused_self_mut_ref(&mut self) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_ref(self: Pin<&Self>) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_nested(self: Pin>) {} + //~^ ERROR: unused `self` argument fn unused_self_box(self: Box) {} + //~^ ERROR: unused `self` argument fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { + //~^ ERROR: unused `self` argument x + y } fn unused_self_class_method(&self) { + //~^ ERROR: unused `self` argument Self::static_method(); } diff --git a/tests/ui/unused_self.stderr b/tests/ui/unused_self.stderr index 919f9b6efdab8..5cf15c00b1b6f 100644 --- a/tests/ui/unused_self.stderr +++ b/tests/ui/unused_self.stderr @@ -8,7 +8,7 @@ LL | fn unused_self_move(self) {} = note: `-D clippy::unused-self` implied by `-D warnings` error: unused `self` argument - --> $DIR/unused_self.rs:12:28 + --> $DIR/unused_self.rs:13:28 | LL | fn unused_self_ref(&self) {} | ^^^^^ @@ -16,7 +16,7 @@ LL | fn unused_self_ref(&self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:13:32 + --> $DIR/unused_self.rs:15:32 | LL | fn unused_self_mut_ref(&mut self) {} | ^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn unused_self_mut_ref(&mut self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:14:32 + --> $DIR/unused_self.rs:17:32 | LL | fn unused_self_pin_ref(self: Pin<&Self>) {} | ^^^^ @@ -32,7 +32,7 @@ LL | fn unused_self_pin_ref(self: Pin<&Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:15:36 + --> $DIR/unused_self.rs:19:36 | LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} | ^^^^ @@ -40,7 +40,7 @@ LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:16:35 + --> $DIR/unused_self.rs:21:35 | LL | fn unused_self_pin_nested(self: Pin>) {} | ^^^^ @@ -48,7 +48,7 @@ LL | fn unused_self_pin_nested(self: Pin>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:17:28 + --> $DIR/unused_self.rs:23:28 | LL | fn unused_self_box(self: Box) {} | ^^^^ @@ -56,7 +56,7 @@ LL | fn unused_self_box(self: Box) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:18:40 + --> $DIR/unused_self.rs:25:40 | LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { | ^^^^^ @@ -64,7 +64,7 @@ LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:21:37 + --> $DIR/unused_self.rs:29:37 | LL | fn unused_self_class_method(&self) { | ^^^^^ diff --git a/tests/ui/unwrap.rs b/tests/ui/unwrap.rs index 64d6437834e6b..8ad7e98503bfc 100644 --- a/tests/ui/unwrap.rs +++ b/tests/ui/unwrap.rs @@ -4,12 +4,15 @@ fn unwrap_option() { let opt = Some(0); let _ = opt.unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value } fn unwrap_result() { let res: Result = Ok(0); let _ = res.unwrap(); + //~^ ERROR: used `unwrap()` on a `Result` value let _ = res.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on a `Result` value } fn main() { diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index 41db819f6fb75..38904858a3239 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -9,7 +9,7 @@ LL | let _ = opt.unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap.rs:11:13 + --> $DIR/unwrap.rs:12:13 | LL | let _ = res.unwrap(); | ^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = res.unwrap(); = help: consider using `expect()` to provide a better panic message error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap.rs:12:13 + --> $DIR/unwrap.rs:14:13 | LL | let _ = res.unwrap_err(); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs index 26f92ccdefaa3..96368a0705361 100644 --- a/tests/ui/unwrap_expect_used.rs +++ b/tests/ui/unwrap_expect_used.rs @@ -25,7 +25,9 @@ impl OptionExt for Option { fn main() { Some(3).unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value Some(3).expect("Hello world!"); + //~^ ERROR: used `expect()` on an `Option` value // Don't trigger on unwrap_err on an option Some(3).unwrap_err(); @@ -41,7 +43,11 @@ fn main() { let a: Result = Ok(3); a.unwrap(); + //~^ ERROR: used `unwrap()` on a `Result` value a.expect("Hello world!"); + //~^ ERROR: used `expect()` on a `Result` value a.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on a `Result` value a.expect_err("Hello error!"); + //~^ ERROR: used `expect_err()` on a `Result` value } diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index f66e47612add4..0b43f5727455f 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -8,7 +8,7 @@ LL | Some(3).unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `expect()` on an `Option` value - --> $DIR/unwrap_expect_used.rs:28:5 + --> $DIR/unwrap_expect_used.rs:29:5 | LL | Some(3).expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | Some(3).expect("Hello world!"); = note: `-D clippy::expect-used` implied by `-D warnings` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:43:5 + --> $DIR/unwrap_expect_used.rs:45:5 | LL | a.unwrap(); | ^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | a.unwrap(); = note: if this value is an `Err`, it will panic error: used `expect()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:44:5 + --> $DIR/unwrap_expect_used.rs:47:5 | LL | a.expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | a.expect("Hello world!"); = note: if this value is an `Err`, it will panic error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:45:5 + --> $DIR/unwrap_expect_used.rs:49:5 | LL | a.unwrap_err(); | ^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | a.unwrap_err(); = note: if this value is an `Ok`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:46:5 + --> $DIR/unwrap_expect_used.rs:51:5 | LL | a.expect_err("Hello error!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_in_result.rs b/tests/ui/unwrap_in_result.rs index 2aa842adc8560..a19db46c667d0 100644 --- a/tests/ui/unwrap_in_result.rs +++ b/tests/ui/unwrap_in_result.rs @@ -20,6 +20,7 @@ impl A { // should be detected fn bad_divisible_by_3(i_str: String) -> Result { + //~^ ERROR: used unwrap or expect in a function that returns result or option // checks whether a string represents a number divisible by 3 let i = i_str.parse::().unwrap(); if i % 3 == 0 { @@ -30,6 +31,7 @@ impl A { } fn example_option_expect(i_str: String) -> Option { + //~^ ERROR: used unwrap or expect in a function that returns result or option let i = i_str.parse::().expect("not a number"); if i % 3 == 0 { return Some(true); diff --git a/tests/ui/unwrap_in_result.stderr b/tests/ui/unwrap_in_result.stderr index 40e6bfe087e7d..a394da272a869 100644 --- a/tests/ui/unwrap_in_result.stderr +++ b/tests/ui/unwrap_in_result.stderr @@ -2,9 +2,9 @@ error: used unwrap or expect in a function that returns result or option --> $DIR/unwrap_in_result.rs:22:5 | LL | / fn bad_divisible_by_3(i_str: String) -> Result { +LL | | LL | | // checks whether a string represents a number divisible by 3 LL | | let i = i_str.parse::().unwrap(); -LL | | if i % 3 == 0 { ... | LL | | } LL | | } @@ -12,27 +12,27 @@ LL | | } | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:24:17 + --> $DIR/unwrap_in_result.rs:25:17 | LL | let i = i_str.parse::().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::unwrap-in-result` implied by `-D warnings` error: used unwrap or expect in a function that returns result or option - --> $DIR/unwrap_in_result.rs:32:5 + --> $DIR/unwrap_in_result.rs:33:5 | LL | / fn example_option_expect(i_str: String) -> Option { +LL | | LL | | let i = i_str.parse::().expect("not a number"); LL | | if i % 3 == 0 { -LL | | return Some(true); -LL | | } +... | LL | | None LL | | } | |_____^ | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:33:17 + --> $DIR/unwrap_in_result.rs:35:17 | LL | let i = i_str.parse::().expect("not a number"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed index cc0a4fa05beb7..e1a47fc7bd940 100644 --- a/tests/ui/unwrap_or.fixed +++ b/tests/ui/unwrap_or.fixed @@ -3,8 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call + //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call } diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index 5bea85e669249..914bfb939b888 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -3,8 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call + //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call } diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index e384bbbb01557..8992092bc58fb 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -7,7 +7,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) = note: `-D clippy::or-fun-call` implied by `-D warnings` error: use of `unwrap_or` followed by a function call - --> $DIR/unwrap_or.rs:9:47 + --> $DIR/unwrap_or.rs:11:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())` diff --git a/tests/ui/upper_case_acronyms.fixed b/tests/ui/upper_case_acronyms.fixed index f416e7f25ba78..460567b097e53 100644 --- a/tests/ui/upper_case_acronyms.fixed +++ b/tests/ui/upper_case_acronyms.fixed @@ -7,13 +7,22 @@ struct CString; // not linted enum Flags { NS, // not linted Cwr, + //~^ ERROR: name `CWR` contains a capitalized acronym + //~| NOTE: `-D clippy::upper-case-acronyms` implied by `-D warnings` Ece, + //~^ ERROR: name `ECE` contains a capitalized acronym Urg, + //~^ ERROR: name `URG` contains a capitalized acronym Ack, + //~^ ERROR: name `ACK` contains a capitalized acronym Psh, + //~^ ERROR: name `PSH` contains a capitalized acronym Rst, + //~^ ERROR: name `RST` contains a capitalized acronym Syn, + //~^ ERROR: name `SYN` contains a capitalized acronym Fin, + //~^ ERROR: name `FIN` contains a capitalized acronym } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -34,15 +43,18 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { Wasd(u8), + //~^ ERROR: name `WASD` contains a capitalized acronym Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct Json; +//~^ ERROR: name `JSON` contains a capitalized acronym // do lint here enum Yaml { + //~^ ERROR: name `YAML` contains a capitalized acronym Num(u32), Str(String), } diff --git a/tests/ui/upper_case_acronyms.rs b/tests/ui/upper_case_acronyms.rs index 9b7c2f28e1cfc..6a20aee62dce7 100644 --- a/tests/ui/upper_case_acronyms.rs +++ b/tests/ui/upper_case_acronyms.rs @@ -7,13 +7,22 @@ struct CString; // not linted enum Flags { NS, // not linted CWR, + //~^ ERROR: name `CWR` contains a capitalized acronym + //~| NOTE: `-D clippy::upper-case-acronyms` implied by `-D warnings` ECE, + //~^ ERROR: name `ECE` contains a capitalized acronym URG, + //~^ ERROR: name `URG` contains a capitalized acronym ACK, + //~^ ERROR: name `ACK` contains a capitalized acronym PSH, + //~^ ERROR: name `PSH` contains a capitalized acronym RST, + //~^ ERROR: name `RST` contains a capitalized acronym SYN, + //~^ ERROR: name `SYN` contains a capitalized acronym FIN, + //~^ ERROR: name `FIN` contains a capitalized acronym } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -34,15 +43,18 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { WASD(u8), + //~^ ERROR: name `WASD` contains a capitalized acronym Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct JSON; +//~^ ERROR: name `JSON` contains a capitalized acronym // do lint here enum YAML { + //~^ ERROR: name `YAML` contains a capitalized acronym Num(u32), Str(String), } diff --git a/tests/ui/upper_case_acronyms.stderr b/tests/ui/upper_case_acronyms.stderr index 74082ec16dd45..9be1bb304eced 100644 --- a/tests/ui/upper_case_acronyms.stderr +++ b/tests/ui/upper_case_acronyms.stderr @@ -7,61 +7,61 @@ LL | CWR, = note: `-D clippy::upper-case-acronyms` implied by `-D warnings` error: name `ECE` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:10:5 + --> $DIR/upper_case_acronyms.rs:12:5 | LL | ECE, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece` error: name `URG` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:11:5 + --> $DIR/upper_case_acronyms.rs:14:5 | LL | URG, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg` error: name `ACK` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:12:5 + --> $DIR/upper_case_acronyms.rs:16:5 | LL | ACK, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack` error: name `PSH` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:13:5 + --> $DIR/upper_case_acronyms.rs:18:5 | LL | PSH, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh` error: name `RST` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:14:5 + --> $DIR/upper_case_acronyms.rs:20:5 | LL | RST, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst` error: name `SYN` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:15:5 + --> $DIR/upper_case_acronyms.rs:22:5 | LL | SYN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn` error: name `FIN` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:16:5 + --> $DIR/upper_case_acronyms.rs:24:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `WASD` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:36:5 + --> $DIR/upper_case_acronyms.rs:45:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `JSON` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:42:8 + --> $DIR/upper_case_acronyms.rs:52:8 | LL | struct JSON; | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Json` error: name `YAML` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:45:6 + --> $DIR/upper_case_acronyms.rs:56:6 | LL | enum YAML { | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Yaml` diff --git a/tests/ui/useless_conversion_try.rs b/tests/ui/useless_conversion_try.rs index ec0512ce210b6..a5feefbe0f099 100644 --- a/tests/ui/useless_conversion_try.rs +++ b/tests/ui/useless_conversion_try.rs @@ -3,7 +3,9 @@ fn test_generic(val: T) -> T { let _ = T::try_from(val).unwrap(); + //~^ ERROR: useless conversion to the same type: `T` val.try_into().unwrap() + //~^ ERROR: useless conversion to the same type: `T` } fn test_generic2 + Into, U: From>(val: T) { @@ -26,12 +28,19 @@ fn main() { let _: String = "foo".try_into().unwrap(); } let _: String = "foo".to_string().try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = TryFrom::try_from("foo".to_string()).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from("foo".to_string()).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = format!("Hello {}", "world").try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = String::new().try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = match String::from("_").try_into() { + //~^ ERROR: useless conversion to the same type: `std::string::String` Ok(a) => a, Err(_) => String::new(), }; diff --git a/tests/ui/useless_conversion_try.stderr b/tests/ui/useless_conversion_try.stderr index 54189f8d28606..938bfb5237bba 100644 --- a/tests/ui/useless_conversion_try.stderr +++ b/tests/ui/useless_conversion_try.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion_try.rs:6:5 + --> $DIR/useless_conversion_try.rs:7:5 | LL | val.try_into().unwrap() | ^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | val.try_into().unwrap() = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:28:21 + --> $DIR/useless_conversion_try.rs:30:21 | LL | let _: String = "foo".to_string().try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | let _: String = "foo".to_string().try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:29:21 + --> $DIR/useless_conversion_try.rs:32:21 | LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); = help: consider removing `TryFrom::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:30:13 + --> $DIR/useless_conversion_try.rs:34:13 | LL | let _ = String::try_from("foo".to_string()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | let _ = String::try_from("foo".to_string()).unwrap(); = help: consider removing `String::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:31:13 + --> $DIR/useless_conversion_try.rs:36:13 | LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); = help: consider removing `String::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:32:21 + --> $DIR/useless_conversion_try.rs:38:21 | LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:33:21 + --> $DIR/useless_conversion_try.rs:40:21 | LL | let _: String = String::new().try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | let _: String = String::new().try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:34:27 + --> $DIR/useless_conversion_try.rs:42:27 | LL | let _: String = match String::from("_").try_into() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/vec_init_then_push.rs b/tests/ui/vec_init_then_push.rs index edca17eef14b1..1c60a75c56ae0 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -3,12 +3,16 @@ //@no-rustfix fn main() { let mut def_err: Vec = Default::default(); + //~^ ERROR: calls to `push` immediately after creation + //~| NOTE: `-D clippy::vec-init-then-push` implied by `-D warnings` def_err.push(0); let mut new_err = Vec::::new(); + //~^ ERROR: calls to `push` immediately after creation new_err.push(1); let mut cap_err = Vec::with_capacity(2); + //~^ ERROR: calls to `push` immediately after creation cap_err.push(0); cap_err.push(1); cap_err.push(2); @@ -21,6 +25,7 @@ fn main() { cap_ok.push(0); new_err = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation new_err.push(0); let mut vec = Vec::new(); @@ -71,6 +76,7 @@ fn _cond_push(x: bool) -> Vec { fn _push_then_edit(x: u32) -> Vec { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push(x); v.push(1); v[0] = v[1] + 5; @@ -79,6 +85,7 @@ fn _push_then_edit(x: u32) -> Vec { fn _cond_push_with_large_start(x: bool) -> Vec { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push(0); v.push(1); v.push(0); @@ -92,6 +99,7 @@ fn _cond_push_with_large_start(x: bool) -> Vec { } let mut v2 = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v2.push(0); v2.push(1); v2.push(0); @@ -107,6 +115,7 @@ fn _cond_push_with_large_start(x: bool) -> Vec { fn f() { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push((0i32, 0i32)); let y = v[0].0.abs(); } diff --git a/tests/ui/vec_init_then_push.stderr b/tests/ui/vec_init_then_push.stderr index a9da1c520197d..9ad793d979b77 100644 --- a/tests/ui/vec_init_then_push.stderr +++ b/tests/ui/vec_init_then_push.stderr @@ -2,70 +2,77 @@ error: calls to `push` immediately after creation --> $DIR/vec_init_then_push.rs:5:5 | LL | / let mut def_err: Vec = Default::default(); +LL | | +LL | | LL | | def_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `let def_err: Vec = vec![..];` | = note: `-D clippy::vec-init-then-push` implied by `-D warnings` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:8:5 + --> $DIR/vec_init_then_push.rs:10:5 | LL | / let mut new_err = Vec::::new(); +LL | | LL | | new_err.push(1); | |____________________^ help: consider using the `vec![]` macro: `let mut new_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:11:5 + --> $DIR/vec_init_then_push.rs:14:5 | LL | / let mut cap_err = Vec::with_capacity(2); +LL | | LL | | cap_err.push(0); LL | | cap_err.push(1); LL | | cap_err.push(2); | |____________________^ help: consider using the `vec![]` macro: `let mut cap_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:23:5 + --> $DIR/vec_init_then_push.rs:27:5 | LL | / new_err = Vec::new(); +LL | | LL | | new_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `new_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:73:5 + --> $DIR/vec_init_then_push.rs:78:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push(x); LL | | v.push(1); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:81:5 + --> $DIR/vec_init_then_push.rs:87:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push(0); LL | | v.push(1); -LL | | v.push(0); ... | LL | | v.push(1); LL | | v.push(0); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:94:5 + --> $DIR/vec_init_then_push.rs:101:5 | LL | / let mut v2 = Vec::new(); +LL | | LL | | v2.push(0); LL | | v2.push(1); -LL | | v2.push(0); ... | LL | | v2.push(1); LL | | v2.push(0); | |_______________^ help: consider using the `vec![]` macro: `let mut v2 = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:109:5 + --> $DIR/vec_init_then_push.rs:117:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push((0i32, 0i32)); | |_________________________^ help: consider using the `vec![]` macro: `let v = vec![..];` diff --git a/tests/ui/vec_resize_to_zero.fixed b/tests/ui/vec_resize_to_zero.fixed index 2c12c5a9a915f..b4c2d8209e763 100644 --- a/tests/ui/vec_resize_to_zero.fixed +++ b/tests/ui/vec_resize_to_zero.fixed @@ -5,6 +5,7 @@ fn main() { // applicable here v.clear(); + //~^ ERROR: emptying a vector with `resize` // not applicable v.resize(2, 5); diff --git a/tests/ui/vec_resize_to_zero.rs b/tests/ui/vec_resize_to_zero.rs index a8307e741cf17..5b11c940f21a7 100644 --- a/tests/ui/vec_resize_to_zero.rs +++ b/tests/ui/vec_resize_to_zero.rs @@ -5,6 +5,7 @@ fn main() { // applicable here v.resize(0, 5); + //~^ ERROR: emptying a vector with `resize` // not applicable v.resize(2, 5); diff --git a/tests/ui/verbose_file_reads.rs b/tests/ui/verbose_file_reads.rs index df267e9872a0a..9dd4f4e1d9bef 100644 --- a/tests/ui/verbose_file_reads.rs +++ b/tests/ui/verbose_file_reads.rs @@ -21,8 +21,10 @@ fn main() -> std::io::Result<()> { let mut f = File::open(path)?; let mut buffer = Vec::new(); f.read_to_end(&mut buffer)?; + //~^ ERROR: use of `File::read_to_end` // ...and this let mut string_buffer = String::new(); f.read_to_string(&mut string_buffer)?; + //~^ ERROR: use of `File::read_to_string` Ok(()) } diff --git a/tests/ui/verbose_file_reads.stderr b/tests/ui/verbose_file_reads.stderr index 44266c7c01f39..592a7984305d4 100644 --- a/tests/ui/verbose_file_reads.stderr +++ b/tests/ui/verbose_file_reads.stderr @@ -8,7 +8,7 @@ LL | f.read_to_end(&mut buffer)?; = note: `-D clippy::verbose-file-reads` implied by `-D warnings` error: use of `File::read_to_string` - --> $DIR/verbose_file_reads.rs:26:5 + --> $DIR/verbose_file_reads.rs:27:5 | LL | f.read_to_string(&mut string_buffer)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/vtable_address_comparisons.rs b/tests/ui/vtable_address_comparisons.rs index 99c3f468f04a7..75647c027e146 100644 --- a/tests/ui/vtable_address_comparisons.rs +++ b/tests/ui/vtable_address_comparisons.rs @@ -12,16 +12,24 @@ fn main() { // These should fail: let _ = a == b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a != b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a < b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a <= b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a > b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a >= b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address ptr::eq(a, b); + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let a = &1 as &dyn Debug; let b = &1 as &dyn Debug; ptr::eq(a, b); + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address // These should be fine: let a = &1; diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr index 7b866d274d586..91490afce3626 100644 --- a/tests/ui/vtable_address_comparisons.stderr +++ b/tests/ui/vtable_address_comparisons.stderr @@ -8,7 +8,7 @@ LL | let _ = a == b; = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:15:13 + --> $DIR/vtable_address_comparisons.rs:16:13 | LL | let _ = a != b; | ^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = a != b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:16:13 + --> $DIR/vtable_address_comparisons.rs:18:13 | LL | let _ = a < b; | ^^^^^ @@ -24,7 +24,7 @@ LL | let _ = a < b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:17:13 + --> $DIR/vtable_address_comparisons.rs:20:13 | LL | let _ = a <= b; | ^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = a <= b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:18:13 + --> $DIR/vtable_address_comparisons.rs:22:13 | LL | let _ = a > b; | ^^^^^ @@ -40,7 +40,7 @@ LL | let _ = a > b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:19:13 + --> $DIR/vtable_address_comparisons.rs:24:13 | LL | let _ = a >= b; | ^^^^^^ @@ -48,7 +48,7 @@ LL | let _ = a >= b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:20:5 + --> $DIR/vtable_address_comparisons.rs:26:5 | LL | ptr::eq(a, b); | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | ptr::eq(a, b); = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:24:5 + --> $DIR/vtable_address_comparisons.rs:31:5 | LL | ptr::eq(a, b); | ^^^^^^^^^^^^^ diff --git a/tests/ui/while_let_loop.rs b/tests/ui/while_let_loop.rs index c563a142919d3..fa5325bebffaf 100644 --- a/tests/ui/while_let_loop.rs +++ b/tests/ui/while_let_loop.rs @@ -4,6 +4,8 @@ fn main() { let y = Some(true); loop { + //~^ ERROR: this loop could be written as a `while let` loop + //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` if let Some(_x) = y { let _v = 1; } else { @@ -21,6 +23,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop match y { Some(_x) => true, None => break, @@ -28,6 +31,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop let x = match y { Some(x) => x, None => break, @@ -37,6 +41,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop let x = match y { Some(x) => x, None => break, @@ -67,6 +72,7 @@ fn main() { // #675, this used to have a wrong suggestion loop { + //~^ ERROR: this loop could be written as a `while let` loop let (e, l) = match "".split_whitespace().next() { Some(word) => (word.is_empty(), word.len()), None => break, diff --git a/tests/ui/while_let_loop.stderr b/tests/ui/while_let_loop.stderr index 04808c0b3adaf..00411172141c3 100644 --- a/tests/ui/while_let_loop.stderr +++ b/tests/ui/while_let_loop.stderr @@ -2,10 +2,10 @@ error: this loop could be written as a `while let` loop --> $DIR/while_let_loop.rs:6:5 | LL | / loop { +LL | | +LL | | LL | | if let Some(_x) = y { -LL | | let _v = 1; -LL | | } else { -LL | | break; +... | LL | | } LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` @@ -13,9 +13,10 @@ LL | | } = note: `-D clippy::while-let-loop` implied by `-D warnings` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:23:5 + --> $DIR/while_let_loop.rs:25:5 | LL | / loop { +LL | | LL | | match y { LL | | Some(_x) => true, LL | | None => break, @@ -24,36 +25,36 @@ LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:30:5 + --> $DIR/while_let_loop.rs:33:5 | LL | / loop { +LL | | LL | | let x = match y { LL | | Some(x) => x, -LL | | None => break, ... | LL | | let _str = "foo"; LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:39:5 + --> $DIR/while_let_loop.rs:43:5 | LL | / loop { +LL | | LL | | let x = match y { LL | | Some(x) => x, -LL | | None => break, ... | LL | | } LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:69:5 + --> $DIR/while_let_loop.rs:74:5 | LL | / loop { +LL | | LL | | let (e, l) = match "".split_whitespace().next() { LL | | Some(word) => (word.is_empty(), word.len()), -LL | | None => break, ... | LL | | let _ = (e, l); LL | | } diff --git a/tests/ui/wild_in_or_pats.rs b/tests/ui/wild_in_or_pats.rs index ad600f125772f..f8bb31b83c48b 100644 --- a/tests/ui/wild_in_or_pats.rs +++ b/tests/ui/wild_in_or_pats.rs @@ -6,6 +6,7 @@ fn main() { dbg!("matched a"); }, "bar" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; @@ -14,6 +15,7 @@ fn main() { dbg!("matched a"); }, "bar" | "bar2" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or bar2 or) wild"); }, }; @@ -22,6 +24,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; @@ -30,6 +33,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr index bd5860f45ca68..5d9ab78bbb4d8 100644 --- a/tests/ui/wild_in_or_pats.stderr +++ b/tests/ui/wild_in_or_pats.stderr @@ -8,7 +8,7 @@ LL | "bar" | _ => { = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:16:9 + --> $DIR/wild_in_or_pats.rs:17:9 | LL | "bar" | "bar2" | _ => { | ^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | "bar" | "bar2" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:24:9 + --> $DIR/wild_in_or_pats.rs:26:9 | LL | _ | "bar" | _ => { | ^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | _ | "bar" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:32:9 + --> $DIR/wild_in_or_pats.rs:35:9 | LL | _ | "bar" => { | ^^^^^^^^^ diff --git a/tests/ui/write_literal.fixed b/tests/ui/write_literal.fixed index b6708453bdeb9..ee577574d2898 100644 --- a/tests/ui/write_literal.fixed +++ b/tests/ui/write_literal.fixed @@ -29,17 +29,30 @@ fn main() { // these should throw warnings write!(v, "Hello world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, "Hello {} world", world); + //~^ ERROR: literal with an empty format string writeln!(v, "Hello world"); + //~^ ERROR: literal with an empty format string writeln!(v, "a literal {:.4}", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning writeln!(v, "hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either writeln!(v, "hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string } diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs index 218385ea12966..588e8fd413a48 100644 --- a/tests/ui/write_literal.rs +++ b/tests/ui/write_literal.rs @@ -29,17 +29,30 @@ fn main() { // these should throw warnings write!(v, "Hello {}", "world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, "Hello {} {}", world, "world"); + //~^ ERROR: literal with an empty format string writeln!(v, "Hello {}", "world"); + //~^ ERROR: literal with an empty format string writeln!(v, "{} {:.4}", "a literal", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning writeln!(v, "{0} {1}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "{1} {0}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string } diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 8b72c8bd28231..f0a09074bc654 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -12,7 +12,7 @@ LL + write!(v, "Hello world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:32:39 + --> $DIR/write_literal.rs:34:39 | LL | writeln!(v, "Hello {} {}", world, "world"); | ^^^^^^^ @@ -24,7 +24,7 @@ LL + writeln!(v, "Hello {} world", world); | error: literal with an empty format string - --> $DIR/write_literal.rs:33:29 + --> $DIR/write_literal.rs:36:29 | LL | writeln!(v, "Hello {}", "world"); | ^^^^^^^ @@ -36,7 +36,7 @@ LL + writeln!(v, "Hello world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:34:29 + --> $DIR/write_literal.rs:38:29 | LL | writeln!(v, "{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + writeln!(v, "a literal {:.4}", 5); | error: literal with an empty format string - --> $DIR/write_literal.rs:39:28 + --> $DIR/write_literal.rs:44:28 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^ @@ -60,7 +60,7 @@ LL + writeln!(v, "hello {1}", "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:39:37 + --> $DIR/write_literal.rs:44:37 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^ @@ -72,7 +72,7 @@ LL + writeln!(v, "{0} world", "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:40:37 + --> $DIR/write_literal.rs:47:37 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^ @@ -84,7 +84,7 @@ LL + writeln!(v, "world {0}", "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:40:28 + --> $DIR/write_literal.rs:47:28 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^ @@ -96,7 +96,7 @@ LL + writeln!(v, "{1} hello", "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:43:38 + --> $DIR/write_literal.rs:52:38 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -108,7 +108,7 @@ LL + writeln!(v, "hello {bar}", bar = "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:43:53 + --> $DIR/write_literal.rs:52:53 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -120,7 +120,7 @@ LL + writeln!(v, "{foo} world", foo = "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:44:53 + --> $DIR/write_literal.rs:55:53 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -132,7 +132,7 @@ LL + writeln!(v, "world {foo}", foo = "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:44:38 + --> $DIR/write_literal.rs:55:38 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index c71a4cb6f7a7f..aa0c13c134080 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -8,30 +8,50 @@ fn main() { let mut v = Vec::new(); writeln!(v, "{}", "{hello}"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, r"{}", r"{hello}"); + //~^ ERROR: unnecessary raw string literal + //~| NOTE: `-D clippy::needless-raw-strings` implied by `-D warnings` + //~| ERROR: literal with an empty format string writeln!(v, "{}", '\''); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", '"'); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", '"'); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", '\''); + //~^ ERROR: literal with an empty format string writeln!( v, "some {}", "hello \ + //~^ ERROR: literal with an empty format string world!" ); writeln!( v, "some {}\ {} \\ {}", - "1", "2", "3", + "1", + "2", + "3", + //~^ ERROR: literal with an empty format string ); writeln!(v, "{}", "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, r#"{}"#, "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", r"\"); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", "\r"); + //~^ ERROR: literal with an empty format string // hard mode writeln!(v, r#"{}{}"#, '#', '"'); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // should not lint writeln!(v, r"{}", "\r"); } diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index c78a92f56eeff..84b302d8d3b4e 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -1,5 +1,5 @@ error: unnecessary raw string literal - --> $DIR/write_literal_2.rs:11:24 + --> $DIR/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ help: try: `"{hello}"` @@ -20,7 +20,7 @@ LL + writeln!(v, "{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:11:24 + --> $DIR/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL + writeln!(v, r"{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:12:23 + --> $DIR/write_literal_2.rs:17:23 | LL | writeln!(v, "{}", '\''); | ^^^^ @@ -44,7 +44,7 @@ LL + writeln!(v, "'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:13:23 + --> $DIR/write_literal_2.rs:19:23 | LL | writeln!(v, "{}", '"'); | ^^^ @@ -56,13 +56,13 @@ LL + writeln!(v, "\""); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:14:24 + --> $DIR/write_literal_2.rs:21:24 | LL | writeln!(v, r"{}", '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:15:24 + --> $DIR/write_literal_2.rs:23:24 | LL | writeln!(v, r"{}", '\''); | ^^^^ @@ -74,56 +74,59 @@ LL + writeln!(v, r"'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:19:9 + --> $DIR/write_literal_2.rs:28:9 | LL | / "hello \ +LL | | LL | | world!" | |_______________^ | help: try | LL ~ "some hello \ +LL + LL ~ world!" | error: literal with an empty format string - --> $DIR/write_literal_2.rs:26:9 + --> $DIR/write_literal_2.rs:36:9 | -LL | "1", "2", "3", +LL | "1", | ^^^ | help: try | LL ~ "some 1\ -LL ~ {} \\ {}", "2", "3", +LL ~ {} \\ {}", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:26:14 + --> $DIR/write_literal_2.rs:37:9 | -LL | "1", "2", "3", - | ^^^ +LL | "2", + | ^^^ | help: try | LL ~ 2 \\ {}", -LL ~ "1", "3", +LL ~ "1", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:26:19 + --> $DIR/write_literal_2.rs:38:9 | -LL | "1", "2", "3", - | ^^^ +LL | "3", + | ^^^ | help: try | LL ~ {} \\ 3", -LL ~ "1", "2", +LL | "1", +LL ~ "2", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:28:23 + --> $DIR/write_literal_2.rs:41:23 | LL | writeln!(v, "{}", "\\"); | ^^^^ @@ -135,7 +138,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:29:24 + --> $DIR/write_literal_2.rs:43:24 | LL | writeln!(v, r"{}", "\\"); | ^^^^ @@ -147,7 +150,7 @@ LL + writeln!(v, r"\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:30:26 + --> $DIR/write_literal_2.rs:45:26 | LL | writeln!(v, r#"{}"#, "\\"); | ^^^^ @@ -159,7 +162,7 @@ LL + writeln!(v, r#"\"#); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:31:23 + --> $DIR/write_literal_2.rs:47:23 | LL | writeln!(v, "{}", r"\"); | ^^^^ @@ -171,7 +174,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:23 + --> $DIR/write_literal_2.rs:49:23 | LL | writeln!(v, "{}", "\r"); | ^^^^ @@ -183,13 +186,13 @@ LL + writeln!(v, "\r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:34:28 + --> $DIR/write_literal_2.rs:52:28 | LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:34:33 + --> $DIR/write_literal_2.rs:52:33 | LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index c0e6c2a826405..82afff5c81f54 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -10,10 +10,16 @@ fn main() { // These should fail writeln!(v, "Hello"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` writeln!(v, "Hello {}", "world"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v, "Hello {} {}", "world", "#2"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v, "{}", 1265); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v); + //~^ ERROR: using `write!()` with a format string that ends in a single newline // These should be fine write!(v, ""); @@ -36,6 +42,7 @@ fn main() { // #3514 write!(v, "\\n"); writeln!(v, "\\"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\\\\n"); // Raw strings @@ -44,9 +51,11 @@ fn main() { // Literal newlines should also fail writeln!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v ); writeln!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v ); @@ -54,6 +63,7 @@ fn main() { write!(v, "\r\n"); write!(v, "foo\r\n"); writeln!(v, "\\r"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index bacafdc8ad4ea..96e4bf0fbc4bd 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -10,10 +10,16 @@ fn main() { // These should fail write!(v, "Hello\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` write!(v, "Hello {}\n", "world"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "{}\n", 1265); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline // These should be fine write!(v, ""); @@ -36,6 +42,7 @@ fn main() { // #3514 write!(v, "\\n"); write!(v, "\\\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\\\\n"); // Raw strings @@ -44,11 +51,13 @@ fn main() { // Literal newlines should also fail write!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v, " " ); write!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v, r" " @@ -58,6 +67,7 @@ fn main() { write!(v, "\r\n"); write!(v, "foo\r\n"); write!(v, "\\r\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index 4ab6919b6b214..d84d57d84f5b5 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -12,7 +12,7 @@ LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:13:5 + --> $DIR/write_with_newline.rs:15:5 | LL | write!(v, "Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:14:5 + --> $DIR/write_with_newline.rs:17:5 | LL | write!(v, "Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:15:5 + --> $DIR/write_with_newline.rs:19:5 | LL | write!(v, "{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:16:5 + --> $DIR/write_with_newline.rs:21:5 | LL | write!(v, "\n"); | ^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:38:5 + --> $DIR/write_with_newline.rs:44:5 | LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:46:5 + --> $DIR/write_with_newline.rs:53:5 | LL | / write!( +LL | | LL | | v, LL | | " LL | | " @@ -84,13 +85,15 @@ LL | | ); help: use `writeln!` instead | LL ~ writeln!( +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:51:5 + --> $DIR/write_with_newline.rs:59:5 | LL | / write!( +LL | | LL | | v, LL | | r" LL | | " @@ -100,11 +103,12 @@ LL | | ); help: use `writeln!` instead | LL ~ writeln!( +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:60:5 + --> $DIR/write_with_newline.rs:69:5 | LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index e3cc90ee222ad..d7ed883b767c3 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -14,12 +14,14 @@ impl Foo { fn is_u32(&self) {} fn to_i32(self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` pub fn as_i64(self) {} pub fn into_i64(self) {} pub fn is_i64(self) {} pub fn to_i64(self) {} pub fn from_i64(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] pub fn from_cake(self) {} @@ -32,20 +34,30 @@ struct Bar; impl Bar { fn as_i32(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl fn as_u32(&self) {} fn into_i32(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self) {} fn is_i32(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b fn is_u32(&self) {} fn to_i32(self) {} + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not fn to_u32(&self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` pub fn as_i64(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl pub fn into_i64(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value pub fn is_i64(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b pub fn to_i64(self) {} + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not pub fn from_i64(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // test for false positives fn as_(self) {} @@ -91,15 +103,19 @@ mod issue4037 { mod issue6307 { trait T: Sized { fn as_i32(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu fn as_u32(&self) {} fn into_i32(self) {} fn into_i32_ref(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self) {} fn is_i32(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel fn is_u32(&self) {} fn to_i32(self) {} fn to_u32(&self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self) {} @@ -115,15 +131,19 @@ mod issue6307 { trait U { fn as_i32(self); + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self); fn is_i32(self); + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -142,12 +162,14 @@ mod issue6307 { fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self); fn is_i32(self); fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -172,6 +194,7 @@ mod issue6727 { } // trigger lint fn to_u64_v2(&self) -> u64 { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is 1 } } @@ -181,6 +204,7 @@ mod issue6727 { impl FooNoCopy { // trigger lint fn to_u64(self) -> u64 { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is 2 } fn to_u64_v2(&self) -> u64 { diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index d002e55c57086..2d52b64c81274 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -8,7 +8,7 @@ LL | fn from_i32(self) {} = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:22:21 + --> $DIR/wrong_self_convention.rs:23:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -16,7 +16,7 @@ LL | pub fn from_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:34:15 + --> $DIR/wrong_self_convention.rs:36:15 | LL | fn as_i32(self) {} | ^^^^ @@ -24,7 +24,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:36:17 + --> $DIR/wrong_self_convention.rs:39:17 | LL | fn into_i32(&self) {} | ^^^^^ @@ -32,7 +32,7 @@ LL | fn into_i32(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:38:15 + --> $DIR/wrong_self_convention.rs:42:15 | LL | fn is_i32(self) {} | ^^^^ @@ -40,7 +40,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:40:15 + --> $DIR/wrong_self_convention.rs:45:15 | LL | fn to_i32(self) {} | ^^^^ @@ -48,7 +48,7 @@ LL | fn to_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:42:17 + --> $DIR/wrong_self_convention.rs:48:17 | LL | fn from_i32(self) {} | ^^^^ @@ -56,7 +56,7 @@ LL | fn from_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:44:19 + --> $DIR/wrong_self_convention.rs:51:19 | LL | pub fn as_i64(self) {} | ^^^^ @@ -64,7 +64,7 @@ LL | pub fn as_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:45:21 + --> $DIR/wrong_self_convention.rs:53:21 | LL | pub fn into_i64(&self) {} | ^^^^^ @@ -72,7 +72,7 @@ LL | pub fn into_i64(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:46:19 + --> $DIR/wrong_self_convention.rs:55:19 | LL | pub fn is_i64(self) {} | ^^^^ @@ -80,7 +80,7 @@ LL | pub fn is_i64(self) {} = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:47:19 + --> $DIR/wrong_self_convention.rs:57:19 | LL | pub fn to_i64(self) {} | ^^^^ @@ -88,7 +88,7 @@ LL | pub fn to_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:48:21 + --> $DIR/wrong_self_convention.rs:59:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -96,7 +96,7 @@ LL | pub fn from_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:93:19 + --> $DIR/wrong_self_convention.rs:105:19 | LL | fn as_i32(self) {} | ^^^^ @@ -104,7 +104,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:96:25 + --> $DIR/wrong_self_convention.rs:109:25 | LL | fn into_i32_ref(&self) {} | ^^^^^ @@ -112,7 +112,7 @@ LL | fn into_i32_ref(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:98:19 + --> $DIR/wrong_self_convention.rs:112:19 | LL | fn is_i32(self) {} | ^^^^ @@ -120,7 +120,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:102:21 + --> $DIR/wrong_self_convention.rs:117:21 | LL | fn from_i32(self) {} | ^^^^ @@ -128,7 +128,7 @@ LL | fn from_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:117:19 + --> $DIR/wrong_self_convention.rs:133:19 | LL | fn as_i32(self); | ^^^^ @@ -136,7 +136,7 @@ LL | fn as_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:120:25 + --> $DIR/wrong_self_convention.rs:137:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -144,7 +144,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:122:19 + --> $DIR/wrong_self_convention.rs:140:19 | LL | fn is_i32(self); | ^^^^ @@ -152,7 +152,7 @@ LL | fn is_i32(self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:126:21 + --> $DIR/wrong_self_convention.rs:145:21 | LL | fn from_i32(self); | ^^^^ @@ -160,7 +160,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:144:25 + --> $DIR/wrong_self_convention.rs:164:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -168,7 +168,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:150:21 + --> $DIR/wrong_self_convention.rs:171:21 | LL | fn from_i32(self); | ^^^^ @@ -176,7 +176,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value - --> $DIR/wrong_self_convention.rs:174:22 + --> $DIR/wrong_self_convention.rs:196:22 | LL | fn to_u64_v2(&self) -> u64 { | ^^^^^ @@ -184,7 +184,7 @@ LL | fn to_u64_v2(&self) -> u64 { = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:183:19 + --> $DIR/wrong_self_convention.rs:206:19 | LL | fn to_u64(self) -> u64 { | ^^^^ diff --git a/tests/ui/wrong_self_convention2.rs b/tests/ui/wrong_self_convention2.rs index 0dcf4743e8b8d..44b70f877be4d 100644 --- a/tests/ui/wrong_self_convention2.rs +++ b/tests/ui/wrong_self_convention2.rs @@ -52,6 +52,7 @@ mod issue7179 { // lint pub fn from_be_self(self) -> Self { + //~^ ERROR: methods called `from_*` usually take no `self` S(i32::from_be(self.0)) } } @@ -61,6 +62,7 @@ mod issue7179 { fn from_be(s: Self) -> Self; // lint fn from_be_self(self) -> Self; + //~^ ERROR: methods called `from_*` usually take no `self` } trait Foo: Sized { diff --git a/tests/ui/wrong_self_convention2.stderr b/tests/ui/wrong_self_convention2.stderr index 8de10e7be69c0..0069059203bf9 100644 --- a/tests/ui/wrong_self_convention2.stderr +++ b/tests/ui/wrong_self_convention2.stderr @@ -8,7 +8,7 @@ LL | pub fn from_be_self(self) -> Self { = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention2.rs:63:25 + --> $DIR/wrong_self_convention2.rs:64:25 | LL | fn from_be_self(self) -> Self; | ^^^^ diff --git a/tests/ui/wrong_self_conventions_mut.rs b/tests/ui/wrong_self_conventions_mut.rs index 5bb2116bd339a..9169fc6d71f6a 100644 --- a/tests/ui/wrong_self_conventions_mut.rs +++ b/tests/ui/wrong_self_conventions_mut.rs @@ -12,6 +12,7 @@ mod issue6758 { impl Test { // If a method starts with `to_` and not ends with `_mut` it should expect `&self` pub fn to_many(&mut self) -> Option<&mut [T]> { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is match self { Self::Many(data) => Some(data), _ => None, @@ -20,6 +21,7 @@ mod issue6758 { // If a method starts with `to_` and ends with `_mut` it should expect `&mut self` pub fn to_many_mut(&self) -> Option<&[T]> { + //~^ ERROR: methods with the following characteristics: (`to_*` and `*_mut`) usual match self { Self::Many(data) => Some(data), _ => None, diff --git a/tests/ui/wrong_self_conventions_mut.stderr b/tests/ui/wrong_self_conventions_mut.stderr index 3d009083cee3e..cd7a9aae144e2 100644 --- a/tests/ui/wrong_self_conventions_mut.stderr +++ b/tests/ui/wrong_self_conventions_mut.stderr @@ -8,7 +8,7 @@ LL | pub fn to_many(&mut self) -> Option<&mut [T]> { = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference - --> $DIR/wrong_self_conventions_mut.rs:22:28 + --> $DIR/wrong_self_conventions_mut.rs:23:28 | LL | pub fn to_many_mut(&self) -> Option<&[T]> { | ^^^^^ diff --git a/tests/ui/zero_div_zero.rs b/tests/ui/zero_div_zero.rs index 968c58f40aefa..340ed5ef1339d 100644 --- a/tests/ui/zero_div_zero.rs +++ b/tests/ui/zero_div_zero.rs @@ -2,9 +2,13 @@ #[warn(clippy::zero_divided_by_zero)] fn main() { let nan = 0.0 / 0.0; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let f64_nan = 0.0 / 0.0f64; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let other_f64_nan = 0.0f64 / 0.0; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let one_more_f64_nan = 0.0f64 / 0.0f64; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let zero = 0.0; let other_zero = 0.0; let other_nan = zero / other_zero; // fine - this lint doesn't propagate constants. diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index 2793d16064459..cde6bc907c683 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -8,7 +8,7 @@ LL | let nan = 0.0 / 0.0; = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:5:19 + --> $DIR/zero_div_zero.rs:6:19 | LL | let f64_nan = 0.0 / 0.0f64; | ^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let f64_nan = 0.0 / 0.0f64; = help: consider using `f64::NAN` if you would like a constant representing NaN error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:6:25 + --> $DIR/zero_div_zero.rs:8:25 | LL | let other_f64_nan = 0.0f64 / 0.0; | ^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let other_f64_nan = 0.0f64 / 0.0; = help: consider using `f64::NAN` if you would like a constant representing NaN error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:7:28 + --> $DIR/zero_div_zero.rs:10:28 | LL | let one_more_f64_nan = 0.0f64 / 0.0f64; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_offset.rs b/tests/ui/zero_offset.rs index fd9ac1fa7663b..c7a69dee4b2de 100644 --- a/tests/ui/zero_offset.rs +++ b/tests/ui/zero_offset.rs @@ -3,15 +3,24 @@ fn main() { unsafe { let m = &mut () as *mut (); m.offset(0); + //~^ ERROR: offset calculation on zero-sized value + //~| NOTE: `#[deny(clippy::zst_offset)]` on by default m.wrapping_add(0); + //~^ ERROR: offset calculation on zero-sized value m.sub(0); + //~^ ERROR: offset calculation on zero-sized value m.wrapping_sub(0); + //~^ ERROR: offset calculation on zero-sized value let c = &() as *const (); c.offset(0); + //~^ ERROR: offset calculation on zero-sized value c.wrapping_add(0); + //~^ ERROR: offset calculation on zero-sized value c.sub(0); + //~^ ERROR: offset calculation on zero-sized value c.wrapping_sub(0); + //~^ ERROR: offset calculation on zero-sized value let sized = &1 as *const i32; sized.offset(0); diff --git a/tests/ui/zero_offset.stderr b/tests/ui/zero_offset.stderr index 481a446571ab0..bb616f456ae14 100644 --- a/tests/ui/zero_offset.stderr +++ b/tests/ui/zero_offset.stderr @@ -7,43 +7,43 @@ LL | m.offset(0); = note: `#[deny(clippy::zst_offset)]` on by default error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:6:9 + --> $DIR/zero_offset.rs:8:9 | LL | m.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:7:9 + --> $DIR/zero_offset.rs:10:9 | LL | m.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:8:9 + --> $DIR/zero_offset.rs:12:9 | LL | m.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:11:9 + --> $DIR/zero_offset.rs:16:9 | LL | c.offset(0); | ^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:12:9 + --> $DIR/zero_offset.rs:18:9 | LL | c.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:13:9 + --> $DIR/zero_offset.rs:20:9 | LL | c.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:14:9 + --> $DIR/zero_offset.rs:22:9 | LL | c.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_sized_btreemap_values.rs b/tests/ui/zero_sized_btreemap_values.rs index 5cd254787d834..565f639201ff7 100644 --- a/tests/ui/zero_sized_btreemap_values.rs +++ b/tests/ui/zero_sized_btreemap_values.rs @@ -3,23 +3,28 @@ use std::collections::BTreeMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type type OkMap = BTreeMap; type NotOkMap = BTreeMap; +//~^ ERROR: map with zero-sized value type enum TestEnum { Ok(BTreeMap), NotOk(BTreeMap), + //~^ ERROR: map with zero-sized value type } struct Test { ok: BTreeMap, not_ok: BTreeMap, - + //~^ ERROR: map with zero-sized value type also_not_ok: Vec>, + //~^ ERROR: map with zero-sized value type } trait TestTrait { @@ -28,6 +33,7 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: BTreeMap); + //~^ ERROR: map with zero-sized value type } impl Test { @@ -36,6 +42,7 @@ impl Test { } fn not_ok(&self) -> BTreeMap { + //~^ ERROR: map with zero-sized value type todo!() } } @@ -53,6 +60,8 @@ impl TestTrait for Test { } fn test(map: BTreeMap, key: &str) -> BTreeMap { + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type todo!(); } @@ -62,7 +71,10 @@ fn test2(map: BTreeMap, key: &str) -> BTreeMap { fn main() { let _: BTreeMap = BTreeMap::new(); + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type let _: BTreeMap = BTreeMap::new(); let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); + //~^ ERROR: map with zero-sized value type } diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index c6ba6fa76f057..de122473fd26d 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -8,7 +8,7 @@ LL | const CONST_NOT_OK: Option> = None; = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:8:30 + --> $DIR/zero_sized_btreemap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:11:17 + --> $DIR/zero_sized_btreemap_values.rs:13:17 | LL | type NotOkMap = BTreeMap; | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type NotOkMap = BTreeMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:15:11 + --> $DIR/zero_sized_btreemap_values.rs:18:11 | LL | NotOk(BTreeMap), | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | NotOk(BTreeMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:20:13 + --> $DIR/zero_sized_btreemap_values.rs:24:13 | LL | not_ok: BTreeMap, | ^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | not_ok: BTreeMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:22:22 + --> $DIR/zero_sized_btreemap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:30:30 + --> $DIR/zero_sized_btreemap_values.rs:35:30 | LL | fn weird_map(&self, map: BTreeMap); | ^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn weird_map(&self, map: BTreeMap); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:38:25 + --> $DIR/zero_sized_btreemap_values.rs:44:25 | LL | fn not_ok(&self) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn not_ok(&self) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:14 + --> $DIR/zero_sized_btreemap_values.rs:62:14 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:50 + --> $DIR/zero_sized_btreemap_values.rs:62:50 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:35 + --> $DIR/zero_sized_btreemap_values.rs:73:35 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^ @@ -88,7 +88,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:12 + --> $DIR/zero_sized_btreemap_values.rs:73:12 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:67:12 + --> $DIR/zero_sized_btreemap_values.rs:78:12 | LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_sized_hashmap_values.rs b/tests/ui/zero_sized_hashmap_values.rs index a1608d863fb52..5498261ee95a0 100644 --- a/tests/ui/zero_sized_hashmap_values.rs +++ b/tests/ui/zero_sized_hashmap_values.rs @@ -3,23 +3,28 @@ use std::collections::HashMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type type OkMap = HashMap; type NotOkMap = HashMap; +//~^ ERROR: map with zero-sized value type enum TestEnum { Ok(HashMap), NotOk(HashMap), + //~^ ERROR: map with zero-sized value type } struct Test { ok: HashMap, not_ok: HashMap, - + //~^ ERROR: map with zero-sized value type also_not_ok: Vec>, + //~^ ERROR: map with zero-sized value type } trait TestTrait { @@ -28,6 +33,7 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: HashMap); + //~^ ERROR: map with zero-sized value type } impl Test { @@ -36,6 +42,7 @@ impl Test { } fn not_ok(&self) -> HashMap { + //~^ ERROR: map with zero-sized value type todo!() } } @@ -53,6 +60,8 @@ impl TestTrait for Test { } fn test(map: HashMap, key: &str) -> HashMap { + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type todo!(); } @@ -62,7 +71,10 @@ fn test2(map: HashMap, key: &str) -> HashMap { fn main() { let _: HashMap = HashMap::new(); + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type let _: HashMap = HashMap::new(); let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); + //~^ ERROR: map with zero-sized value type } diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 75bdeb42ec0d4..0d489f45aca16 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -8,7 +8,7 @@ LL | const CONST_NOT_OK: Option> = None; = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:8:30 + --> $DIR/zero_sized_hashmap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:11:17 + --> $DIR/zero_sized_hashmap_values.rs:13:17 | LL | type NotOkMap = HashMap; | ^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type NotOkMap = HashMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:15:11 + --> $DIR/zero_sized_hashmap_values.rs:18:11 | LL | NotOk(HashMap), | ^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | NotOk(HashMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:20:13 + --> $DIR/zero_sized_hashmap_values.rs:24:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | not_ok: HashMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:22:22 + --> $DIR/zero_sized_hashmap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:30:30 + --> $DIR/zero_sized_hashmap_values.rs:35:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn weird_map(&self, map: HashMap); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:38:25 + --> $DIR/zero_sized_hashmap_values.rs:44:25 | LL | fn not_ok(&self) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn not_ok(&self) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:14 + --> $DIR/zero_sized_hashmap_values.rs:62:14 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:49 + --> $DIR/zero_sized_hashmap_values.rs:62:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:34 + --> $DIR/zero_sized_hashmap_values.rs:73:34 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^ @@ -88,7 +88,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:12 + --> $DIR/zero_sized_hashmap_values.rs:73:12 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:67:12 + --> $DIR/zero_sized_hashmap_values.rs:78:12 | LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^ From f4670121d54bb8eb40a69cc75ce96194d4af4b98 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Aug 2023 13:53:23 +0200 Subject: [PATCH 4/4] Move code comments to prevent having weird clippy fmt issues --- tests/ui/const_comparisons.rs | 39 +++++++++----- tests/ui/const_comparisons.stderr | 86 +++++++++++++++---------------- 2 files changed, 69 insertions(+), 56 deletions(-) diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs index c0403758f1bb9..0898b4ebd4657 100644 --- a/tests/ui/const_comparisons.rs +++ b/tests/ui/const_comparisons.rs @@ -40,7 +40,8 @@ fn main() { let status_code = 500; // Value doesn't matter for the lint let status = Status { code: status_code }; - status_code >= 400 && status_code < 500; // Correct + // Correct + status_code >= 400 && status_code < 500; status_code <= 400 && status_code > 500; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st @@ -80,22 +81,30 @@ fn main() { //~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER // Yoda conditions - 500 <= status_code && 600 > status_code; // Correct - 500 <= status_code && status_code <= 600; // Correct - 500 >= status_code && 600 < status_code; // Incorrect + // Correct + 500 <= status_code && 600 > status_code; + // Correct + 500 <= status_code && status_code <= 600; + // Incorrect + 500 >= status_code && 600 < status_code; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st - 500 >= status_code && status_code > 600; // Incorrect + // Incorrect + 500 >= status_code && status_code > 600; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Yoda conditions, comparing two different types - 500 <= status && 600 > status; // Correct - 500 <= status && status <= 600; // Correct - 500 >= status && 600 < status; // Incorrect + // Correct + 500 <= status && 600 > status; + // Correct + 500 <= status && status <= 600; + // Incorrect + 500 >= status && 600 < status; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st - 500 >= status && status > 600; // Incorrect + // Incorrect + 500 >= status && status > 600; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st @@ -105,13 +114,17 @@ fn main() { status_code > 200 && status_code >= 299; //~^ ERROR: left-hand side of `&&` operator has no effect - status_code >= 500 && status_code > 500; // Useless left + // Useless left + status_code >= 500 && status_code > 500; //~^ ERROR: left-hand side of `&&` operator has no effect - status_code > 500 && status_code >= 500; // Useless right + // Useless right + status_code > 500 && status_code >= 500; //~^ ERROR: right-hand side of `&&` operator has no effect - status_code <= 500 && status_code < 500; // Useless left + // Useless left + status_code <= 500 && status_code < 500; //~^ ERROR: left-hand side of `&&` operator has no effect - status_code < 500 && status_code <= 500; // Useless right + // Useless right + status_code < 500 && status_code <= 500; //~^ ERROR: right-hand side of `&&` operator has no effect // Other types diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index e319ce8d17b89..8c920d36896d6 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -1,5 +1,5 @@ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:44:5 + --> $DIR/const_comparisons.rs:45:5 | LL | status_code <= 400 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | status_code <= 400 && status_code > 500; = note: `-D clippy::impossible-comparisons` implied by `-D warnings` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:47:5 + --> $DIR/const_comparisons.rs:48:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | status_code > 500 && status_code < 400; = note: since `500` > `400`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:50:5 + --> $DIR/const_comparisons.rs:51:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | status_code < 500 && status_code > 500; = note: `status_code` cannot simultaneously be greater than and less than `500` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:55:5 + --> $DIR/const_comparisons.rs:56:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | status_code < { 400 } && status_code > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:58:5 + --> $DIR/const_comparisons.rs:59:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:61:5 + --> $DIR/const_comparisons.rs:62:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:64:5 + --> $DIR/const_comparisons.rs:65:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:69:5 + --> $DIR/const_comparisons.rs:70:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | status < { 400 } && status > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:72:5 + --> $DIR/const_comparisons.rs:73:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:75:5 + --> $DIR/const_comparisons.rs:76:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:79:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,112 +88,112 @@ LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:85:5 + --> $DIR/const_comparisons.rs:89:5 | -LL | 500 >= status_code && 600 < status_code; // Incorrect +LL | 500 >= status_code && 600 < status_code; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:88:5 + --> $DIR/const_comparisons.rs:93:5 | -LL | 500 >= status_code && status_code > 600; // Incorrect +LL | 500 >= status_code && status_code > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:95:5 + --> $DIR/const_comparisons.rs:103:5 | -LL | 500 >= status && 600 < status; // Incorrect +LL | 500 >= status && 600 < status; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:98:5 + --> $DIR/const_comparisons.rs:107:5 | -LL | 500 >= status && status > 600; // Incorrect +LL | 500 >= status && status > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:103:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well - --> $DIR/const_comparisons.rs:103:23 + --> $DIR/const_comparisons.rs:112:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-comparisons` implied by `-D warnings` error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:105:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well - --> $DIR/const_comparisons.rs:105:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:108:5 + --> $DIR/const_comparisons.rs:118:5 | -LL | status_code >= 500 && status_code > 500; // Useless left +LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:108:5 + --> $DIR/const_comparisons.rs:118:5 | -LL | status_code >= 500 && status_code > 500; // Useless left +LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:110:5 + --> $DIR/const_comparisons.rs:121:5 | -LL | status_code > 500 && status_code >= 500; // Useless right +LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:110:23 + --> $DIR/const_comparisons.rs:121:23 | -LL | status_code > 500 && status_code >= 500; // Useless right +LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:112:5 + --> $DIR/const_comparisons.rs:124:5 | -LL | status_code <= 500 && status_code < 500; // Useless left +LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:112:5 + --> $DIR/const_comparisons.rs:124:5 | -LL | status_code <= 500 && status_code < 500; // Useless left +LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:114:5 + --> $DIR/const_comparisons.rs:127:5 | -LL | status_code < 500 && status_code <= 500; // Useless right +LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:114:23 + --> $DIR/const_comparisons.rs:127:23 | -LL | status_code < 500 && status_code <= 500; // Useless right +LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:119:5 + --> $DIR/const_comparisons.rs:132:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +201,7 @@ LL | name < "Jennifer" && name > "Shannon"; = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:124:5 + --> $DIR/const_comparisons.rs:137:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | numbers < [3, 4] && numbers > [5, 6]; = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:129:5 + --> $DIR/const_comparisons.rs:142:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | letter < 'b' && letter > 'c'; = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:134:5 + --> $DIR/const_comparisons.rs:147:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^