diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 4d168bfeab93..ca63253c5744 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -4,23 +4,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 68d838c1f828..8a1a75dae390 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:7:13 + --> $DIR/bytecount.rs:8: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:9:13 + --> $DIR/bytecount.rs:11: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:21:13 + --> $DIR/bytecount.rs:28: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 60a0eabf55b0..396cfbed0cc5 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -41,14 +41,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; @@ -120,7 +128,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; @@ -132,7 +141,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 { @@ -142,7 +152,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; } } @@ -155,8 +166,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; } } @@ -168,7 +181,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; } } @@ -179,7 +193,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; } } @@ -192,8 +207,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; } } @@ -206,9 +223,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; } } @@ -221,8 +241,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; } } @@ -236,7 +258,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; } } @@ -248,8 +271,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; } } @@ -262,8 +287,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 de29af78ef30..a4e05107e87a 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:44:5 + --> $DIR/cast.rs:45: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:45:5 + --> $DIR/cast.rs:47: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:45:5 + --> $DIR/cast.rs:47: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:46:5 + --> $DIR/cast.rs:49: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:46:5 + --> $DIR/cast.rs:49: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:47:5 + --> $DIR/cast.rs:51: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:49:5 + --> $DIR/cast.rs:55: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:50:5 + --> $DIR/cast.rs:57: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:51:5 + --> $DIR/cast.rs:59: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:51:5 + --> $DIR/cast.rs:59: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:54:5 + --> $DIR/cast.rs:62:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:56:5 + --> $DIR/cast.rs:64:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:123:5 + --> $DIR/cast.rs:132: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:135:5 + --> $DIR/cast.rs:145: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:156:21 + --> $DIR/cast.rs:167: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:157:21 + --> $DIR/cast.rs:168: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:193:21 + --> $DIR/cast.rs:208: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:194:21 + --> $DIR/cast.rs:209:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:208:21 + --> $DIR/cast.rs:225: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:223:21 + --> $DIR/cast.rs:243: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:264:21 + --> $DIR/cast.rs:289: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:272:13 + --> $DIR/cast.rs:299: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:275:13 + --> $DIR/cast.rs:302: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 0a53a3d6490a..e724c456b888 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 39fc9d6dda67..da3e5c5e52b1 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 16e54a7d969e..9e618350b198 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 c395c5ba06f2..f342815ac76b 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 e417cf833cbb..4e15933e537b 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 049a69d93bfe..bf7c6750ccfd 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 61042bb90d27..be5a984006ba 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -9,7 +9,8 @@ macro_rules! m { ($a:expr) => { if $a.is_some() { - $a.unwrap(); // unnecessary + // unnecessary + $a.unwrap(); } }; } @@ -41,37 +42,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(()); @@ -87,20 +107,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 93809f6551ad..caf74628b632 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:44:9 + --> $DIR/simple_conditionals.rs:46: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:45:9 + --> $DIR/simple_conditionals.rs:48: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:47:9 + --> $DIR/simple_conditionals.rs:51: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:48:9 + --> $DIR/simple_conditionals.rs:53: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:51:9 + --> $DIR/simple_conditionals.rs:57: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:53:9 + --> $DIR/simple_conditionals.rs:60: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:12:13 + --> $DIR/simple_conditionals.rs:13: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:61:9 + --> $DIR/simple_conditionals.rs:72: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:62:9 + --> $DIR/simple_conditionals.rs:74: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:63:9 + --> $DIR/simple_conditionals.rs:76: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:65:9 + --> $DIR/simple_conditionals.rs:79: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:66:9 + --> $DIR/simple_conditionals.rs:81: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:67:9 + --> $DIR/simple_conditionals.rs:83: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:70:9 + --> $DIR/simple_conditionals.rs:87: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:71:9 + --> $DIR/simple_conditionals.rs:89: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:73:9 + --> $DIR/simple_conditionals.rs:92: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:74:9 + --> $DIR/simple_conditionals.rs:94: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 e02c1c57230a..f7ba68fd8948 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 982cb445534a..32ba6b9bc273 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 cfdda35971fb..6fc6f9988ebe 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 cc84dc1d43c5..7b91d8c426b2 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.rs b/tests/ui/eprint_with_newline.rs index 8389806c838e..9446d5d651a1 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 0a6bdf15df8e..7d0e937f0603 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 16f9e47e8532..f7f7ea410353 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 f4357c1d592d..1db2eb1397cd 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 939b6ac36bde..ea111a48b29f 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 dc54bd41365d..6a75d5745379 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 622644f675d3..7821dd44812d 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 b911163f715e..39d2fcc71aa6 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 07f8e3888c99..c5cf97d3cd65 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 40b92b7647bf..73f876c1d1a3 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 adff08e5d1e8..656b0b5cedcc 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 83a76f81d4e7..0793e6386930 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 7fdeb27ed988..2c0d71ef0dd1 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 b679b7a0aaf8..6183135fc9c1 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 c891c9de3aec..12e6c7deb9c2 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 d99989b54fc2..7f9f644643f9 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 edd2123d48a5..a5605cc14d48 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 516c1df40be0..8a09688a90ce 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.rs b/tests/ui/print_with_newline.rs index d9c7acc27480..cdd4eb936cc2 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -23,16 +23,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!( @@ -47,7 +51,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 b97711e777dd..28ea37dc1198 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:31:5 + --> $DIR/print_with_newline.rs:34: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:38:5 + --> $DIR/print_with_newline.rs:42: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:42:5 + --> $DIR/print_with_newline.rs:46: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:50:5 + --> $DIR/print_with_newline.rs:55: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.rs b/tests/ui/trailing_zeros.rs index fbdc977b769a..888f0587fe34 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 798551118309..7c44f139c095 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 5aad0b44270a..6afb1915e7e5 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 e50a773290e1..220bcb5b528d 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 903c240bfcab..c9585e519883 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 805127e27500..84dae74e9789 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -29,6 +29,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 c30ec385b35a..5f39a2e572c7 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:32:28 + --> $DIR/write_literal_2.rs:33:28 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:33 + --> $DIR/write_literal_2.rs:33: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.rs b/tests/ui/write_with_newline.rs index 35bd9e7f3a07..5211adea4a12 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -28,16 +28,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 03a18a4dc3f3..bbb78f73b684 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:36:5 + --> $DIR/write_with_newline.rs:39: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:43:5 + --> $DIR/write_with_newline.rs:47: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:48:5 + --> $DIR/write_with_newline.rs:52: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:57:5 + --> $DIR/write_with_newline.rs:61:5 | LL | write!(v, "//r/n"); | ^^^^^^^^^^^^^^^^^^