Merge remote-tracking branch 'upstream/master' into rustup
This commit is contained in:
commit
d2b08432db
158 changed files with 3894 additions and 1449 deletions
|
|
@ -1,5 +1,5 @@
|
|||
error: casting `isize` to `i8` may truncate the value
|
||||
--> $DIR/cast_size_32bit.rs:12:5
|
||||
--> $DIR/cast_size.rs:15:5
|
||||
|
|
||||
LL | 1isize as i8;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -12,7 +12,7 @@ LL | i8::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size_32bit.rs:15:5
|
||||
--> $DIR/cast_size.rs:18:5
|
||||
|
|
||||
LL | x0 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -20,25 +20,25 @@ LL | x0 as f64;
|
|||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size_32bit.rs:16:5
|
||||
--> $DIR/cast_size.rs:19:5
|
||||
|
|
||||
LL | x1 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size_32bit.rs:17:5
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
|
|
||||
LL | x0 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size_32bit.rs:18:5
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
|
|
||||
LL | x1 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:19:5
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
|
|
||||
LL | 1isize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -50,7 +50,7 @@ LL | i32::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:20:5
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
|
|
||||
LL | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -62,7 +62,7 @@ LL | u32::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:21:5
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
|
|
||||
LL | 1usize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -74,7 +74,7 @@ LL | u32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:22:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -86,7 +86,7 @@ LL | i32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:22:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -94,7 +94,7 @@ LL | 1usize as i32;
|
|||
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
|
||||
error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:24:5
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
|
|
||||
LL | 1i64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -106,7 +106,7 @@ LL | isize::try_from(1i64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:25:5
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
|
|
||||
LL | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -118,7 +118,7 @@ LL | usize::try_from(1i64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:26:5
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -130,13 +130,13 @@ LL | isize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:26:5
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:27:5
|
||||
--> $DIR/cast_size.rs:29:5
|
||||
|
|
||||
LL | 1u64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -148,24 +148,31 @@ LL | usize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:28:5
|
||||
--> $DIR/cast_size.rs:30:5
|
||||
|
|
||||
LL | 1u32 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size_32bit.rs:33:5
|
||||
--> $DIR/cast_size.rs:35:5
|
||||
|
|
||||
LL | 999_999_999 as f32;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting integer literal to `f64` is unnecessary
|
||||
--> $DIR/cast_size_32bit.rs:34:5
|
||||
error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:36:5
|
||||
|
|
||||
LL | 3_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `3_999_999_999_f64`
|
||||
LL | 9_999_999_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: literal out of range for `usize`
|
||||
--> $DIR/cast_size.rs:36:5
|
||||
|
|
||||
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
|
||||
LL | 9_999_999_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the literal `9_999_999_999_999_999usize` does not fit into the type `usize` whose range is `0..=4294967295`
|
||||
= note: `#[deny(overflowing_literals)]` on by default
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error: casting `isize` to `i8` may truncate the value
|
||||
--> $DIR/cast_size.rs:12:5
|
||||
--> $DIR/cast_size.rs:15:5
|
||||
|
|
||||
LL | 1isize as i8;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -13,7 +13,7 @@ LL | i8::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:16:5
|
||||
--> $DIR/cast_size.rs:18:5
|
||||
|
|
||||
LL | x0 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -28,19 +28,19 @@ LL | x1 as f64;
|
|||
| ^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
|
|
||||
LL | x0 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
|
|
||||
LL | x1 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
|
|
||||
LL | 1isize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -52,7 +52,7 @@ LL | i32::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
|
|
||||
LL | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -64,7 +64,7 @@ LL | u32::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:29:5
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
|
|
||||
LL | 1usize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -76,7 +76,7 @@ LL | u32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -88,7 +88,7 @@ LL | i32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -97,7 +97,7 @@ LL | 1usize as i32;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]`
|
||||
|
||||
error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:36:5
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
|
|
||||
LL | 1i64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -109,7 +109,7 @@ LL | isize::try_from(1i64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:38:5
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
|
|
||||
LL | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -121,7 +121,7 @@ LL | usize::try_from(1i64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:40:5
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -133,13 +133,13 @@ LL | isize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:40:5
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:43:5
|
||||
--> $DIR/cast_size.rs:29:5
|
||||
|
|
||||
LL | 1u64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -151,19 +151,19 @@ LL | usize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:45:5
|
||||
--> $DIR/cast_size.rs:30:5
|
||||
|
|
||||
LL | 1u32 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:51:5
|
||||
--> $DIR/cast_size.rs:35:5
|
||||
|
|
||||
LL | 999_999_999 as f32;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:53:5
|
||||
--> $DIR/cast_size.rs:36:5
|
||||
|
|
||||
LL | 9_999_999_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -1,56 +1,37 @@
|
|||
//@ignore-32bit
|
||||
#[warn(
|
||||
//@stderr-per-bitwidth
|
||||
//@no-rustfix
|
||||
|
||||
#![warn(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_sign_loss,
|
||||
clippy::cast_possible_wrap,
|
||||
clippy::cast_lossless
|
||||
)]
|
||||
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
#![allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
|
||||
fn main() {
|
||||
// Casting from *size
|
||||
1isize as i8;
|
||||
//~^ ERROR: casting `isize` to `i8` may truncate the value
|
||||
let x0 = 1isize;
|
||||
let x1 = 1usize;
|
||||
x0 as f64;
|
||||
//~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
//~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
x1 as f64;
|
||||
//~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
x0 as f32;
|
||||
//~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b
|
||||
x1 as f32;
|
||||
//~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b
|
||||
1isize as i32;
|
||||
//~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
1isize as u32;
|
||||
//~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as u32;
|
||||
//~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as i32;
|
||||
//~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
//~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit
|
||||
//~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
// Casting to *size
|
||||
1i64 as isize;
|
||||
//~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
1i64 as usize;
|
||||
//~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u64 as isize;
|
||||
//~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
//~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit
|
||||
1u64 as usize;
|
||||
//~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u32 as isize;
|
||||
//~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit
|
||||
1u32 as usize; // Should not trigger any lint
|
||||
1i32 as isize; // Neither should this
|
||||
1i32 as usize;
|
||||
// Big integer literal to float
|
||||
999_999_999 as f32;
|
||||
//~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide,
|
||||
9_999_999_999_999_999usize as f64;
|
||||
//~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
}
|
||||
//@no-rustfix
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
//@ignore-64bit
|
||||
#[warn(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_sign_loss,
|
||||
clippy::cast_possible_wrap,
|
||||
clippy::cast_lossless
|
||||
)]
|
||||
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
fn main() {
|
||||
// Casting from *size
|
||||
1isize as i8;
|
||||
//~^ ERROR: casting `isize` to `i8` may truncate the value
|
||||
let x0 = 1isize;
|
||||
let x1 = 1usize;
|
||||
x0 as f64;
|
||||
//~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
//~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
x1 as f64;
|
||||
//~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
x0 as f32;
|
||||
//~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b
|
||||
x1 as f32;
|
||||
//~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b
|
||||
1isize as i32;
|
||||
//~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
1isize as u32;
|
||||
//~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as u32;
|
||||
//~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as i32;
|
||||
//~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
//~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit
|
||||
//~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
// Casting to *size
|
||||
1i64 as isize;
|
||||
//~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
1i64 as usize;
|
||||
//~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u64 as isize;
|
||||
//~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
//~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit
|
||||
1u64 as usize;
|
||||
//~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u32 as isize;
|
||||
//~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit
|
||||
1u32 as usize; // Should not trigger any lint
|
||||
1i32 as isize; // Neither should this
|
||||
1i32 as usize;
|
||||
// Big integer literal to float
|
||||
999_999_999 as f32;
|
||||
//~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide,
|
||||
3_999_999_999usize as f64;
|
||||
//~^ ERROR: casting integer literal to `f64` is unnecessary
|
||||
//~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings`
|
||||
}
|
||||
|
|
@ -128,6 +128,57 @@ fn main() {
|
|||
assert!(x.is_ok(), "{:?}", x.unwrap_err());
|
||||
}
|
||||
|
||||
fn issue11371() {
|
||||
let option = Some(());
|
||||
|
||||
if option.is_some() {
|
||||
option.as_ref().unwrap();
|
||||
//~^ ERROR: called `unwrap` on `option` after checking its variant with `is_some`
|
||||
} else {
|
||||
option.as_ref().unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
}
|
||||
|
||||
let result = Ok::<(), ()>(());
|
||||
|
||||
if result.is_ok() {
|
||||
result.as_ref().unwrap();
|
||||
//~^ ERROR: called `unwrap` on `result` after checking its variant with `is_ok`
|
||||
} else {
|
||||
result.as_ref().unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
}
|
||||
|
||||
let mut option = Some(());
|
||||
if option.is_some() {
|
||||
option.as_mut().unwrap();
|
||||
//~^ ERROR: called `unwrap` on `option` after checking its variant with `is_some`
|
||||
} else {
|
||||
option.as_mut().unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
}
|
||||
|
||||
let mut result = Ok::<(), ()>(());
|
||||
if result.is_ok() {
|
||||
result.as_mut().unwrap();
|
||||
//~^ ERROR: called `unwrap` on `result` after checking its variant with `is_ok`
|
||||
} else {
|
||||
result.as_mut().unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
}
|
||||
|
||||
// This should not lint. Statics are, at the time of writing, not linted on anyway,
|
||||
// but if at some point they are supported by this lint, it should correctly see that
|
||||
// `X` is being mutated and not suggest `if let Some(..) = X {}`
|
||||
static mut X: Option<i32> = Some(123);
|
||||
unsafe {
|
||||
if X.is_some() {
|
||||
X = None;
|
||||
X.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_expect() {
|
||||
let x = Some(());
|
||||
if x.is_some() {
|
||||
|
|
|
|||
|
|
@ -168,5 +168,73 @@ LL | if x.is_err() {
|
|||
LL | x.unwrap_err();
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
error: called `unwrap` on `option` after checking its variant with `is_some`
|
||||
--> $DIR/simple_conditionals.rs:135:9
|
||||
|
|
||||
LL | if option.is_some() {
|
||||
| ------------------- help: try: `if let Some(..) = &option`
|
||||
LL | option.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:138:9
|
||||
|
|
||||
LL | if option.is_some() {
|
||||
| ---------------- because of this check
|
||||
...
|
||||
LL | option.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `result` after checking its variant with `is_ok`
|
||||
--> $DIR/simple_conditionals.rs:145:9
|
||||
|
|
||||
LL | if result.is_ok() {
|
||||
| ----------------- help: try: `if let Ok(..) = &result`
|
||||
LL | result.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:148:9
|
||||
|
|
||||
LL | if result.is_ok() {
|
||||
| -------------- because of this check
|
||||
...
|
||||
LL | result.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `option` after checking its variant with `is_some`
|
||||
--> $DIR/simple_conditionals.rs:154:9
|
||||
|
|
||||
LL | if option.is_some() {
|
||||
| ------------------- help: try: `if let Some(..) = &mut option`
|
||||
LL | option.as_mut().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:157:9
|
||||
|
|
||||
LL | if option.is_some() {
|
||||
| ---------------- because of this check
|
||||
...
|
||||
LL | option.as_mut().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `result` after checking its variant with `is_ok`
|
||||
--> $DIR/simple_conditionals.rs:163:9
|
||||
|
|
||||
LL | if result.is_ok() {
|
||||
| ----------------- help: try: `if let Ok(..) = &mut result`
|
||||
LL | result.as_mut().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:166:9
|
||||
|
|
||||
LL | if result.is_ok() {
|
||||
| -------------- because of this check
|
||||
...
|
||||
LL | result.as_mut().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 25 previous errors
|
||||
|
||||
|
|
|
|||
9
tests/ui/crashes/ice-11337.rs
Normal file
9
tests/ui/crashes/ice-11337.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#![feature(trait_alias)]
|
||||
|
||||
trait Confusing<F> = Fn(i32) where F: Fn(u32);
|
||||
|
||||
fn alias<T: Confusing<F>, F>(_: T, _: F) {}
|
||||
|
||||
fn main() {
|
||||
alias(|_| {}, |_| {});
|
||||
}
|
||||
25
tests/ui/crashes/ice-11422.fixed
Normal file
25
tests/ui/crashes/ice-11422.fixed
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#![warn(clippy::implied_bounds_in_impls)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::ops::*;
|
||||
|
||||
fn gen() -> impl PartialOrd + Debug {}
|
||||
|
||||
struct Bar {}
|
||||
trait Foo<T = Self> {}
|
||||
trait FooNested<T = Option<Self>> {}
|
||||
impl Foo for Bar {}
|
||||
impl FooNested for Bar {}
|
||||
|
||||
fn foo() -> impl Foo + FooNested {
|
||||
Bar {}
|
||||
}
|
||||
|
||||
fn test_impl_ops() -> impl Add + Sub + Mul + Div {
|
||||
1
|
||||
}
|
||||
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign {
|
||||
1
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
25
tests/ui/crashes/ice-11422.rs
Normal file
25
tests/ui/crashes/ice-11422.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#![warn(clippy::implied_bounds_in_impls)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::ops::*;
|
||||
|
||||
fn gen() -> impl PartialOrd + PartialEq + Debug {}
|
||||
|
||||
struct Bar {}
|
||||
trait Foo<T = Self> {}
|
||||
trait FooNested<T = Option<Self>> {}
|
||||
impl Foo for Bar {}
|
||||
impl FooNested for Bar {}
|
||||
|
||||
fn foo() -> impl Foo + FooNested {
|
||||
Bar {}
|
||||
}
|
||||
|
||||
fn test_impl_ops() -> impl Add + Sub + Mul + Div {
|
||||
1
|
||||
}
|
||||
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign {
|
||||
1
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
16
tests/ui/crashes/ice-11422.stderr
Normal file
16
tests/ui/crashes/ice-11422.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error: this bound is already specified as the supertrait of `PartialOrd`
|
||||
--> $DIR/ice-11422.rs:6:31
|
||||
|
|
||||
LL | fn gen() -> impl PartialOrd + PartialEq + Debug {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::implied_bounds_in_impls)]`
|
||||
help: try removing this bound
|
||||
|
|
||||
LL - fn gen() -> impl PartialOrd + PartialEq + Debug {}
|
||||
LL + fn gen() -> impl PartialOrd + Debug {}
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -3,7 +3,8 @@ fn main() {}
|
|||
fn no_panic<T>(slice: &[T]) {
|
||||
let mut iter = slice.iter();
|
||||
loop {
|
||||
//~^ ERROR: this loop could be written as a `while let` loop
|
||||
//~^ ERROR: this loop never actually loops
|
||||
//~| ERROR: this loop could be written as a `while let` loop
|
||||
//~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings`
|
||||
let _ = match iter.next() {
|
||||
Some(ele) => ele,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,24 @@
|
|||
error: this loop never actually loops
|
||||
--> $DIR/ice-360.rs:5:5
|
||||
|
|
||||
LL | / loop {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `#[deny(clippy::never_loop)]` on by default
|
||||
|
||||
error: this loop could be written as a `while let` loop
|
||||
--> $DIR/ice-360.rs:5:5
|
||||
|
|
||||
LL | / loop {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | let _ = match iter.next() {
|
||||
LL | |
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
|
|
@ -14,7 +28,7 @@ LL | | }
|
|||
= help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]`
|
||||
|
||||
error: empty `loop {}` wastes CPU cycles
|
||||
--> $DIR/ice-360.rs:12:9
|
||||
--> $DIR/ice-360.rs:13:9
|
||||
|
|
||||
LL | loop {}
|
||||
| ^^^^^^^
|
||||
|
|
@ -23,5 +37,5 @@ LL | loop {}
|
|||
= note: `-D clippy::empty-loop` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::empty_loop)]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -287,4 +287,17 @@ mod issue10158 {
|
|||
}
|
||||
}
|
||||
|
||||
mod issue11368 {
|
||||
pub struct A {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
impl Default for A {
|
||||
#[track_caller]
|
||||
fn default() -> Self {
|
||||
Self { a: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -323,4 +323,17 @@ mod issue10158 {
|
|||
}
|
||||
}
|
||||
|
||||
mod issue11368 {
|
||||
pub struct A {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
impl Default for A {
|
||||
#[track_caller]
|
||||
fn default() -> Self {
|
||||
Self { a: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
)]
|
||||
#![warn(clippy::expl_impl_clone_on_copy)]
|
||||
|
||||
|
||||
#[derive(Copy)]
|
||||
struct Qux;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:12:1
|
||||
--> $DIR/derive.rs:11:1
|
||||
|
|
||||
LL | / impl Clone for Qux {
|
||||
LL | |
|
||||
|
|
@ -10,7 +10,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:12:1
|
||||
--> $DIR/derive.rs:11:1
|
||||
|
|
||||
LL | / impl Clone for Qux {
|
||||
LL | |
|
||||
|
|
@ -23,7 +23,7 @@ LL | | }
|
|||
= help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]`
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:37:1
|
||||
--> $DIR/derive.rs:36:1
|
||||
|
|
||||
LL | / impl<'a> Clone for Lt<'a> {
|
||||
LL | |
|
||||
|
|
@ -34,7 +34,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:37:1
|
||||
--> $DIR/derive.rs:36:1
|
||||
|
|
||||
LL | / impl<'a> Clone for Lt<'a> {
|
||||
LL | |
|
||||
|
|
@ -45,7 +45,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:49:1
|
||||
--> $DIR/derive.rs:48:1
|
||||
|
|
||||
LL | / impl Clone for BigArray {
|
||||
LL | |
|
||||
|
|
@ -56,7 +56,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:49:1
|
||||
--> $DIR/derive.rs:48:1
|
||||
|
|
||||
LL | / impl Clone for BigArray {
|
||||
LL | |
|
||||
|
|
@ -67,7 +67,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:61:1
|
||||
--> $DIR/derive.rs:60:1
|
||||
|
|
||||
LL | / impl Clone for FnPtr {
|
||||
LL | |
|
||||
|
|
@ -78,7 +78,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:61:1
|
||||
--> $DIR/derive.rs:60:1
|
||||
|
|
||||
LL | / impl Clone for FnPtr {
|
||||
LL | |
|
||||
|
|
@ -89,7 +89,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:82:1
|
||||
--> $DIR/derive.rs:81:1
|
||||
|
|
||||
LL | / impl<T: Clone> Clone for Generic2<T> {
|
||||
LL | |
|
||||
|
|
@ -100,7 +100,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:82:1
|
||||
--> $DIR/derive.rs:81:1
|
||||
|
|
||||
LL | / impl<T: Clone> Clone for Generic2<T> {
|
||||
LL | |
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ use proc_macros::{external, inline_macros};
|
|||
|
||||
fn should_trigger() {
|
||||
loop {}
|
||||
#[allow(clippy::never_loop)]
|
||||
loop {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
'outer: loop {
|
||||
'inner: loop {}
|
||||
}
|
||||
|
|
@ -18,6 +20,7 @@ fn should_trigger() {
|
|||
|
||||
#[inline_macros]
|
||||
fn should_not_trigger() {
|
||||
#[allow(clippy::never_loop)]
|
||||
loop {
|
||||
panic!("This is fine")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ LL | loop {}
|
|||
= help: to override `-D warnings` add `#[allow(clippy::empty_loop)]`
|
||||
|
||||
error: empty `loop {}` wastes CPU cycles
|
||||
--> $DIR/empty_loop.rs:11:9
|
||||
--> $DIR/empty_loop.rs:12:9
|
||||
|
|
||||
LL | loop {}
|
||||
| ^^^^^^^
|
||||
|
|
@ -17,7 +17,7 @@ LL | loop {}
|
|||
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
|
||||
|
||||
error: empty `loop {}` wastes CPU cycles
|
||||
--> $DIR/empty_loop.rs:15:9
|
||||
--> $DIR/empty_loop.rs:17:9
|
||||
|
|
||||
LL | 'inner: loop {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//@ignore-target-x86
|
||||
//@ignore-32bit
|
||||
|
||||
#![warn(clippy::enum_clike_unportable_variant)]
|
||||
#![allow(unused, non_upper_case_globals)]
|
||||
|
|
|
|||
|
|
@ -5,51 +5,52 @@ LL | X = 0x1_0000_0000,
|
|||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::enum_clike_unportable_variant)]`
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:15:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:17:5
|
||||
|
|
||||
LL | X = 0x1_0000_0000,
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:18:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:21:5
|
||||
|
|
||||
LL | A = 0xFFFF_FFFF,
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:25:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:29:5
|
||||
|
|
||||
LL | Z = 0xFFFF_FFFF,
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:26:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:31:5
|
||||
|
|
||||
LL | A = 0x1_0000_0000,
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:28:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:34:5
|
||||
|
|
||||
LL | C = (i32::MIN as isize) - 1,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:34:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:41:5
|
||||
|
|
||||
LL | Z = 0xFFFF_FFFF,
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:35:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:43:5
|
||||
|
|
||||
LL | A = 0x1_0000_0000,
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: C-like enum variant discriminant is not portable to 32-bit targets
|
||||
--> $DIR/enum_clike_unportable_variant.rs:40:5
|
||||
--> $DIR/enum_clike_unportable_variant.rs:49:5
|
||||
|
|
||||
LL | X = <usize as Trait>::Number,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ mod rustc_ok {
|
|||
|
||||
#[expect(illegal_floating_point_literal_pattern)]
|
||||
match x {
|
||||
5.0 => {}
|
||||
6.0 => {}
|
||||
_ => {}
|
||||
5.0 => {},
|
||||
6.0 => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,9 +41,9 @@ mod rustc_warn {
|
|||
#[expect(illegal_floating_point_literal_pattern)]
|
||||
//~^ ERROR: this lint expectation is unfulfilled
|
||||
match x {
|
||||
5 => {}
|
||||
6 => {}
|
||||
_ => {}
|
||||
5 => {},
|
||||
6 => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
f_str(&&ref_str); // `needless_borrow` will suggest removing both references
|
||||
f_str(&ref_str); // `needless_borrow` will suggest removing both references
|
||||
f_str(&ref_str); // `needless_borrow` will suggest removing only one reference
|
||||
|
||||
let x = &&40;
|
||||
|
|
@ -293,4 +293,10 @@ fn main() {
|
|||
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
|
||||
*x
|
||||
}
|
||||
|
||||
// Issue #11366
|
||||
let _: &mut u32 = match &mut Some(&mut 0u32) {
|
||||
Some(x) => x,
|
||||
None => panic!(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,4 +293,10 @@ fn main() {
|
|||
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
|
||||
*x
|
||||
}
|
||||
|
||||
// Issue #11366
|
||||
let _: &mut u32 = match &mut Some(&mut 0u32) {
|
||||
Some(x) => &mut *x,
|
||||
None => panic!(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,10 +194,10 @@ LL | let _ = f_str(**ref_ref_str);
|
|||
| ^^^^^^^^^^^^^ help: try: `ref_ref_str`
|
||||
|
||||
error: deref which would be done by auto-deref
|
||||
--> $DIR/explicit_auto_deref.rs:208:13
|
||||
--> $DIR/explicit_auto_deref.rs:208:12
|
||||
|
|
||||
LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references
|
||||
| ^^^^^^^^ help: try: `ref_str`
|
||||
| ^^^^^^^^^ help: try: `ref_str`
|
||||
|
||||
error: deref which would be done by auto-deref
|
||||
--> $DIR/explicit_auto_deref.rs:209:12
|
||||
|
|
@ -235,5 +235,11 @@ error: deref which would be done by auto-deref
|
|||
LL | *x
|
||||
| ^^ help: try: `x`
|
||||
|
||||
error: aborting due to 39 previous errors
|
||||
error: deref which would be done by auto-deref
|
||||
--> $DIR/explicit_auto_deref.rs:299:20
|
||||
|
|
||||
LL | Some(x) => &mut *x,
|
||||
| ^^^^^^^ help: try: `x`
|
||||
|
||||
error: aborting due to 40 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
clippy::similar_names,
|
||||
clippy::needless_borrow,
|
||||
clippy::deref_addrof,
|
||||
clippy::unnecessary_mut_passed,
|
||||
dead_code
|
||||
)]
|
||||
|
||||
|
|
@ -20,15 +21,15 @@ fn main() {
|
|||
for _ in rvec {}
|
||||
|
||||
let rmvec = &mut vec;
|
||||
for _ in &*rmvec {}
|
||||
for _ in &mut *rmvec {}
|
||||
for _ in rmvec.iter() {}
|
||||
for _ in rmvec.iter_mut() {}
|
||||
|
||||
for _ in &vec {} // these are fine
|
||||
for _ in &mut vec {} // these are fine
|
||||
|
||||
for _ in &[1, 2, 3] {}
|
||||
|
||||
for _ in &*(&mut [1, 2, 3]) {}
|
||||
for _ in (&mut [1, 2, 3]).iter() {}
|
||||
|
||||
for _ in &[0; 32] {}
|
||||
for _ in &[0; 33] {}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
clippy::similar_names,
|
||||
clippy::needless_borrow,
|
||||
clippy::deref_addrof,
|
||||
clippy::unnecessary_mut_passed,
|
||||
dead_code
|
||||
)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:16:14
|
||||
--> $DIR/explicit_iter_loop.rs:17:14
|
||||
|
|
||||
LL | for _ in vec.iter() {}
|
||||
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
|
||||
|
|
@ -11,133 +11,106 @@ LL | #![deny(clippy::explicit_iter_loop)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:17:14
|
||||
--> $DIR/explicit_iter_loop.rs:18:14
|
||||
|
|
||||
LL | for _ in vec.iter_mut() {}
|
||||
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:20:14
|
||||
--> $DIR/explicit_iter_loop.rs:21:14
|
||||
|
|
||||
LL | for _ in rvec.iter() {}
|
||||
| ^^^^^^^^^^^ help: to write this more concisely, try: `rvec`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:23:14
|
||||
|
|
||||
LL | for _ in rmvec.iter() {}
|
||||
| ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:24:14
|
||||
|
|
||||
LL | for _ in rmvec.iter_mut() {}
|
||||
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:29:14
|
||||
--> $DIR/explicit_iter_loop.rs:30:14
|
||||
|
|
||||
LL | for _ in [1, 2, 3].iter() {}
|
||||
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:31:14
|
||||
|
|
||||
LL | for _ in (&mut [1, 2, 3]).iter() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*(&mut [1, 2, 3])`
|
||||
|
||||
error: the method `iter` doesn't need a mutable reference
|
||||
--> $DIR/explicit_iter_loop.rs:31:14
|
||||
|
|
||||
LL | for _ in (&mut [1, 2, 3]).iter() {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:33:14
|
||||
--> $DIR/explicit_iter_loop.rs:34:14
|
||||
|
|
||||
LL | for _ in [0; 32].iter() {}
|
||||
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:34:14
|
||||
--> $DIR/explicit_iter_loop.rs:35:14
|
||||
|
|
||||
LL | for _ in [0; 33].iter() {}
|
||||
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 33]`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:37:14
|
||||
--> $DIR/explicit_iter_loop.rs:38:14
|
||||
|
|
||||
LL | for _ in ll.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:39:14
|
||||
--> $DIR/explicit_iter_loop.rs:40:14
|
||||
|
|
||||
LL | for _ in rll.iter() {}
|
||||
| ^^^^^^^^^^ help: to write this more concisely, try: `rll`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:42:14
|
||||
--> $DIR/explicit_iter_loop.rs:43:14
|
||||
|
|
||||
LL | for _ in vd.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:44:14
|
||||
--> $DIR/explicit_iter_loop.rs:45:14
|
||||
|
|
||||
LL | for _ in rvd.iter() {}
|
||||
| ^^^^^^^^^^ help: to write this more concisely, try: `rvd`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:47:14
|
||||
--> $DIR/explicit_iter_loop.rs:48:14
|
||||
|
|
||||
LL | for _ in bh.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:50:14
|
||||
--> $DIR/explicit_iter_loop.rs:51:14
|
||||
|
|
||||
LL | for _ in hm.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:53:14
|
||||
--> $DIR/explicit_iter_loop.rs:54:14
|
||||
|
|
||||
LL | for _ in bt.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:56:14
|
||||
--> $DIR/explicit_iter_loop.rs:57:14
|
||||
|
|
||||
LL | for _ in hs.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:59:14
|
||||
--> $DIR/explicit_iter_loop.rs:60:14
|
||||
|
|
||||
LL | for _ in bs.iter() {}
|
||||
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:148:14
|
||||
--> $DIR/explicit_iter_loop.rs:149:14
|
||||
|
|
||||
LL | for _ in x.iter() {}
|
||||
| ^^^^^^^^ help: to write this more concisely, try: `&x`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:149:14
|
||||
--> $DIR/explicit_iter_loop.rs:150:14
|
||||
|
|
||||
LL | for _ in x.iter_mut() {}
|
||||
| ^^^^^^^^^^^^ help: to write this more concisely, try: `&mut x`
|
||||
|
||||
error: it is more concise to loop over references to containers instead of using explicit iteration methods
|
||||
--> $DIR/explicit_iter_loop.rs:152:14
|
||||
--> $DIR/explicit_iter_loop.rs:153:14
|
||||
|
|
||||
LL | for _ in r.iter() {}
|
||||
| ^^^^^^^^ help: to write this more concisely, try: `r`
|
||||
|
||||
error: aborting due to 22 previous errors
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,16 @@ impl PartialEq for X {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq<f32> for X {
|
||||
fn eq(&self, o: &f32) -> bool {
|
||||
if self.val.is_nan() {
|
||||
o.is_nan()
|
||||
} else {
|
||||
self.val == *o // no error, inside "eq" fn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
ZERO == 0f32; //no error, comparison with zero is ok
|
||||
1.0f32 != f32::INFINITY; // also comparison with infinity
|
||||
|
|
@ -48,6 +58,9 @@ fn main() {
|
|||
ZERO == 0.0; //no error, comparison with zero is ok
|
||||
ZERO + ZERO != 1.0; //no error, comparison with zero is ok
|
||||
|
||||
let x = X { val: 1.0 };
|
||||
x == 1.0; // no error, custom type that implement PartialOrder for float is not checked
|
||||
|
||||
ONE == 1f32;
|
||||
ONE == 1.0 + 0.0;
|
||||
ONE + ONE == ZERO + ONE + ONE;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:57:5
|
||||
--> $DIR/float_cmp.rs:70:5
|
||||
|
|
||||
LL | ONE as f64 != 2.0;
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin`
|
||||
|
|
@ -9,7 +9,7 @@ LL | ONE as f64 != 2.0;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::float_cmp)]`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:64:5
|
||||
--> $DIR/float_cmp.rs:77:5
|
||||
|
|
||||
LL | x == 1.0;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin`
|
||||
|
|
@ -17,7 +17,7 @@ LL | x == 1.0;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:69:5
|
||||
--> $DIR/float_cmp.rs:82:5
|
||||
|
|
||||
LL | twice(x) != twice(ONE as f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin`
|
||||
|
|
@ -25,7 +25,7 @@ LL | twice(x) != twice(ONE as f64);
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:91:5
|
||||
--> $DIR/float_cmp.rs:104:5
|
||||
|
|
||||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin`
|
||||
|
|
@ -33,7 +33,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` arrays
|
||||
--> $DIR/float_cmp.rs:98:5
|
||||
--> $DIR/float_cmp.rs:111:5
|
||||
|
|
||||
LL | a1 == a2;
|
||||
| ^^^^^^^^
|
||||
|
|
@ -41,7 +41,7 @@ LL | a1 == a2;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:101:5
|
||||
--> $DIR/float_cmp.rs:114:5
|
||||
|
|
||||
LL | a1[0] == a2[0];
|
||||
| ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: casting function pointer `foo` to `i8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:10:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:11:13
|
||||
|
|
||||
LL | let _ = foo as i8;
|
||||
| ^^^^^^^^^ help: try: `foo as usize`
|
||||
|
|
@ -7,135 +7,135 @@ LL | let _ = foo as i8;
|
|||
= note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings`
|
||||
|
||||
error: casting function pointer `foo` to `i16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:11:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:12:13
|
||||
|
|
||||
LL | let _ = foo as i16;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `i32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:12:13
|
||||
error: casting function pointer `foo` to `i32`
|
||||
--> $DIR/fn_to_numeric_cast.rs:13:13
|
||||
|
|
||||
LL | let _ = foo as i32;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `i64`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:13:13
|
||||
|
|
||||
LL | let _ = foo as i64;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
|
||||
= note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings`
|
||||
|
||||
error: casting function pointer `foo` to `i64`
|
||||
--> $DIR/fn_to_numeric_cast.rs:14:13
|
||||
|
|
||||
LL | let _ = foo as i64;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `i128`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:14:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:15:13
|
||||
|
|
||||
LL | let _ = foo as i128;
|
||||
| ^^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `isize`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:15:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:16:13
|
||||
|
|
||||
LL | let _ = foo as isize;
|
||||
| ^^^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:17:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:18:13
|
||||
|
|
||||
LL | let _ = foo as u8;
|
||||
| ^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:18:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:19:13
|
||||
|
|
||||
LL | let _ = foo as u16;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:19:13
|
||||
error: casting function pointer `foo` to `u32`
|
||||
--> $DIR/fn_to_numeric_cast.rs:20:13
|
||||
|
|
||||
LL | let _ = foo as u32;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u64`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:20:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:21:13
|
||||
|
|
||||
LL | let _ = foo as u64;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u128`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:21:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:22:13
|
||||
|
|
||||
LL | let _ = foo as u128;
|
||||
| ^^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:34:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:35:13
|
||||
|
|
||||
LL | let _ = abc as i8;
|
||||
| ^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:35:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:36:13
|
||||
|
|
||||
LL | let _ = abc as i16;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:36:13
|
||||
error: casting function pointer `abc` to `i32`
|
||||
--> $DIR/fn_to_numeric_cast.rs:37:13
|
||||
|
|
||||
LL | let _ = abc as i32;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i64`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:37:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:38:13
|
||||
|
|
||||
LL | let _ = abc as i64;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i128`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:38:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:39:13
|
||||
|
|
||||
LL | let _ = abc as i128;
|
||||
| ^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `isize`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:39:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:40:13
|
||||
|
|
||||
LL | let _ = abc as isize;
|
||||
| ^^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:41:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:42:13
|
||||
|
|
||||
LL | let _ = abc as u8;
|
||||
| ^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:42:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:43:13
|
||||
|
|
||||
LL | let _ = abc as u16;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:43:13
|
||||
error: casting function pointer `abc` to `u32`
|
||||
--> $DIR/fn_to_numeric_cast.rs:44:13
|
||||
|
|
||||
LL | let _ = abc as u32;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u64`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:44:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:45:13
|
||||
|
|
||||
LL | let _ = abc as u64;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u128`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:45:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:46:13
|
||||
|
|
||||
LL | let _ = abc as u128;
|
||||
| ^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `f` to `i32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:52:5
|
||||
error: casting function pointer `f` to `i32`
|
||||
--> $DIR/fn_to_numeric_cast.rs:53:5
|
||||
|
|
||||
LL | f as i32
|
||||
| ^^^^^^^^ help: try: `f as usize`
|
||||
|
|
@ -8,19 +8,19 @@ LL | let _ = foo as i8;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]`
|
||||
|
||||
error: casting function pointer `foo` to `i16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:13:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:11:13
|
||||
|
|
||||
LL | let _ = foo as i16;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `i32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:15:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:12:13
|
||||
|
|
||||
LL | let _ = foo as i32;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `i64`
|
||||
--> $DIR/fn_to_numeric_cast.rs:17:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:13:13
|
||||
|
|
||||
LL | let _ = foo as i64;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
|
@ -29,115 +29,115 @@ LL | let _ = foo as i64;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]`
|
||||
|
||||
error: casting function pointer `foo` to `i128`
|
||||
--> $DIR/fn_to_numeric_cast.rs:20:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:14:13
|
||||
|
|
||||
LL | let _ = foo as i128;
|
||||
| ^^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `isize`
|
||||
--> $DIR/fn_to_numeric_cast.rs:22:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:15:13
|
||||
|
|
||||
LL | let _ = foo as isize;
|
||||
| ^^^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:25:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:17:13
|
||||
|
|
||||
LL | let _ = foo as u8;
|
||||
| ^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:27:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:18:13
|
||||
|
|
||||
LL | let _ = foo as u16;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:29:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:19:13
|
||||
|
|
||||
LL | let _ = foo as u32;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u64`
|
||||
--> $DIR/fn_to_numeric_cast.rs:31:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:20:13
|
||||
|
|
||||
LL | let _ = foo as u64;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u128`
|
||||
--> $DIR/fn_to_numeric_cast.rs:33:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:21:13
|
||||
|
|
||||
LL | let _ = foo as u128;
|
||||
| ^^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:47:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:34:13
|
||||
|
|
||||
LL | let _ = abc as i8;
|
||||
| ^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:49:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:35:13
|
||||
|
|
||||
LL | let _ = abc as i16;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:51:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:36:13
|
||||
|
|
||||
LL | let _ = abc as i32;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i64`
|
||||
--> $DIR/fn_to_numeric_cast.rs:53:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:37:13
|
||||
|
|
||||
LL | let _ = abc as i64;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i128`
|
||||
--> $DIR/fn_to_numeric_cast.rs:55:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:38:13
|
||||
|
|
||||
LL | let _ = abc as i128;
|
||||
| ^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `isize`
|
||||
--> $DIR/fn_to_numeric_cast.rs:57:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:39:13
|
||||
|
|
||||
LL | let _ = abc as isize;
|
||||
| ^^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:60:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:41:13
|
||||
|
|
||||
LL | let _ = abc as u8;
|
||||
| ^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u16`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:62:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:42:13
|
||||
|
|
||||
LL | let _ = abc as u16;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:64:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:43:13
|
||||
|
|
||||
LL | let _ = abc as u32;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u64`
|
||||
--> $DIR/fn_to_numeric_cast.rs:66:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:44:13
|
||||
|
|
||||
LL | let _ = abc as u64;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u128`
|
||||
--> $DIR/fn_to_numeric_cast.rs:68:13
|
||||
--> $DIR/fn_to_numeric_cast.rs:45:13
|
||||
|
|
||||
LL | let _ = abc as u128;
|
||||
| ^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `f` to `i32`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast.rs:76:5
|
||||
--> $DIR/fn_to_numeric_cast.rs:52:5
|
||||
|
|
||||
LL | f as i32
|
||||
| ^^^^^^^^ help: try: `f as usize`
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//@ignore-32bit
|
||||
//@stderr-per-bitwidth
|
||||
//@no-rustfix
|
||||
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
|
||||
|
||||
|
|
@ -8,30 +8,17 @@ fn foo() -> String {
|
|||
|
||||
fn test_function_to_numeric_cast() {
|
||||
let _ = foo as i8;
|
||||
//~^ ERROR: casting function pointer `foo` to `i8`, which truncates the value
|
||||
//~| NOTE: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings`
|
||||
let _ = foo as i16;
|
||||
//~^ ERROR: casting function pointer `foo` to `i16`, which truncates the value
|
||||
let _ = foo as i32;
|
||||
//~^ ERROR: casting function pointer `foo` to `i32`, which truncates the value
|
||||
let _ = foo as i64;
|
||||
//~^ ERROR: casting function pointer `foo` to `i64`
|
||||
//~| NOTE: `-D clippy::fn-to-numeric-cast` implied by `-D warnings`
|
||||
let _ = foo as i128;
|
||||
//~^ ERROR: casting function pointer `foo` to `i128`
|
||||
let _ = foo as isize;
|
||||
//~^ ERROR: casting function pointer `foo` to `isize`
|
||||
|
||||
let _ = foo as u8;
|
||||
//~^ ERROR: casting function pointer `foo` to `u8`, which truncates the value
|
||||
let _ = foo as u16;
|
||||
//~^ ERROR: casting function pointer `foo` to `u16`, which truncates the value
|
||||
let _ = foo as u32;
|
||||
//~^ ERROR: casting function pointer `foo` to `u32`, which truncates the value
|
||||
let _ = foo as u64;
|
||||
//~^ ERROR: casting function pointer `foo` to `u64`
|
||||
let _ = foo as u128;
|
||||
//~^ ERROR: casting function pointer `foo` to `u128`
|
||||
|
||||
// Casting to usize is OK and should not warn
|
||||
let _ = foo as usize;
|
||||
|
|
@ -45,28 +32,17 @@ fn test_function_var_to_numeric_cast() {
|
|||
let abc: fn() -> String = foo;
|
||||
|
||||
let _ = abc as i8;
|
||||
//~^ ERROR: casting function pointer `abc` to `i8`, which truncates the value
|
||||
let _ = abc as i16;
|
||||
//~^ ERROR: casting function pointer `abc` to `i16`, which truncates the value
|
||||
let _ = abc as i32;
|
||||
//~^ ERROR: casting function pointer `abc` to `i32`, which truncates the value
|
||||
let _ = abc as i64;
|
||||
//~^ ERROR: casting function pointer `abc` to `i64`
|
||||
let _ = abc as i128;
|
||||
//~^ ERROR: casting function pointer `abc` to `i128`
|
||||
let _ = abc as isize;
|
||||
//~^ ERROR: casting function pointer `abc` to `isize`
|
||||
|
||||
let _ = abc as u8;
|
||||
//~^ ERROR: casting function pointer `abc` to `u8`, which truncates the value
|
||||
let _ = abc as u16;
|
||||
//~^ ERROR: casting function pointer `abc` to `u16`, which truncates the value
|
||||
let _ = abc as u32;
|
||||
//~^ ERROR: casting function pointer `abc` to `u32`, which truncates the value
|
||||
let _ = abc as u64;
|
||||
//~^ ERROR: casting function pointer `abc` to `u64`
|
||||
let _ = abc as u128;
|
||||
//~^ ERROR: casting function pointer `abc` to `u128`
|
||||
|
||||
// Casting to usize is OK and should not warn
|
||||
let _ = abc as usize;
|
||||
|
|
@ -74,7 +50,6 @@ fn test_function_var_to_numeric_cast() {
|
|||
|
||||
fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
|
||||
f as i32
|
||||
//~^ ERROR: casting function pointer `f` to `i32`, which truncates the value
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
//@ignore-64bit
|
||||
|
||||
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
|
||||
|
||||
fn foo() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn test_function_to_numeric_cast() {
|
||||
let _ = foo as i8;
|
||||
//~^ ERROR: casting function pointer `foo` to `i8`, which truncates the value
|
||||
//~| NOTE: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings`
|
||||
let _ = foo as i16;
|
||||
//~^ ERROR: casting function pointer `foo` to `i16`, which truncates the value
|
||||
let _ = foo as i32;
|
||||
//~^ ERROR: casting function pointer `foo` to `i32`, which truncates the value
|
||||
let _ = foo as i64;
|
||||
//~^ ERROR: casting function pointer `foo` to `i64`
|
||||
//~| NOTE: `-D clippy::fn-to-numeric-cast` implied by `-D warnings`
|
||||
let _ = foo as i128;
|
||||
//~^ ERROR: casting function pointer `foo` to `i128`
|
||||
let _ = foo as isize;
|
||||
//~^ ERROR: casting function pointer `foo` to `isize`
|
||||
|
||||
let _ = foo as u8;
|
||||
//~^ ERROR: casting function pointer `foo` to `u8`, which truncates the value
|
||||
let _ = foo as u16;
|
||||
//~^ ERROR: casting function pointer `foo` to `u16`, which truncates the value
|
||||
let _ = foo as u32;
|
||||
//~^ ERROR: casting function pointer `foo` to `u32`, which truncates the value
|
||||
let _ = foo as u64;
|
||||
//~^ ERROR: casting function pointer `foo` to `u64`
|
||||
let _ = foo as u128;
|
||||
//~^ ERROR: casting function pointer `foo` to `u128`
|
||||
|
||||
// Casting to usize is OK and should not warn
|
||||
let _ = foo as usize;
|
||||
|
||||
// Cast `f` (a `FnDef`) to `fn()` should not warn
|
||||
fn f() {}
|
||||
let _ = f as fn();
|
||||
}
|
||||
|
||||
fn test_function_var_to_numeric_cast() {
|
||||
let abc: fn() -> String = foo;
|
||||
|
||||
let _ = abc as i8;
|
||||
//~^ ERROR: casting function pointer `abc` to `i8`, which truncates the value
|
||||
let _ = abc as i16;
|
||||
//~^ ERROR: casting function pointer `abc` to `i16`, which truncates the value
|
||||
let _ = abc as i32;
|
||||
//~^ ERROR: casting function pointer `abc` to `i32`, which truncates the value
|
||||
let _ = abc as i64;
|
||||
//~^ ERROR: casting function pointer `abc` to `i64`
|
||||
let _ = abc as i128;
|
||||
//~^ ERROR: casting function pointer `abc` to `i128`
|
||||
let _ = abc as isize;
|
||||
//~^ ERROR: casting function pointer `abc` to `isize`
|
||||
|
||||
let _ = abc as u8;
|
||||
//~^ ERROR: casting function pointer `abc` to `u8`, which truncates the value
|
||||
let _ = abc as u16;
|
||||
//~^ ERROR: casting function pointer `abc` to `u16`, which truncates the value
|
||||
let _ = abc as u32;
|
||||
//~^ ERROR: casting function pointer `abc` to `u32`, which truncates the value
|
||||
let _ = abc as u64;
|
||||
//~^ ERROR: casting function pointer `abc` to `u64`
|
||||
let _ = abc as u128;
|
||||
//~^ ERROR: casting function pointer `abc` to `u128`
|
||||
|
||||
// Casting to usize is OK and should not warn
|
||||
let _ = abc as usize;
|
||||
}
|
||||
|
||||
fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
|
||||
f as i32
|
||||
//~^ ERROR: casting function pointer `f` to `i32`, which truncates the value
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -117,3 +117,15 @@ fn f(b: bool, v: Option<()>) -> Option<()> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> {
|
||||
let x = if b {
|
||||
#[allow(clippy::let_unit_value)]
|
||||
let _ = v?;
|
||||
Some(())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#![warn(clippy::ignored_unit_patterns)]
|
||||
#![allow(clippy::redundant_pattern_matching, clippy::single_match)]
|
||||
#![allow(clippy::let_unit_value, clippy::redundant_pattern_matching, clippy::single_match)]
|
||||
|
||||
fn foo() -> Result<(), ()> {
|
||||
unimplemented!()
|
||||
|
|
@ -7,9 +7,19 @@ fn foo() -> Result<(), ()> {
|
|||
|
||||
fn main() {
|
||||
match foo() {
|
||||
Ok(()) => {},
|
||||
Err(()) => {},
|
||||
Ok(()) => {}, //~ ERROR: matching over `()` is more explicit
|
||||
Err(()) => {}, //~ ERROR: matching over `()` is more explicit
|
||||
}
|
||||
if let Ok(()) = foo() {}
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
let _ = foo().map_err(|()| todo!());
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn moo(_: ()) {
|
||||
let () = foo().unwrap();
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
let _: () = foo().unwrap();
|
||||
let _: () = ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#![warn(clippy::ignored_unit_patterns)]
|
||||
#![allow(clippy::redundant_pattern_matching, clippy::single_match)]
|
||||
#![allow(clippy::let_unit_value, clippy::redundant_pattern_matching, clippy::single_match)]
|
||||
|
||||
fn foo() -> Result<(), ()> {
|
||||
unimplemented!()
|
||||
|
|
@ -7,9 +7,19 @@ fn foo() -> Result<(), ()> {
|
|||
|
||||
fn main() {
|
||||
match foo() {
|
||||
Ok(_) => {},
|
||||
Err(_) => {},
|
||||
Ok(_) => {}, //~ ERROR: matching over `()` is more explicit
|
||||
Err(_) => {}, //~ ERROR: matching over `()` is more explicit
|
||||
}
|
||||
if let Ok(_) = foo() {}
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
let _ = foo().map_err(|_| todo!());
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn moo(_: ()) {
|
||||
let _ = foo().unwrap();
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
let _: () = foo().unwrap();
|
||||
let _: () = ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,16 @@ LL | if let Ok(_) = foo() {}
|
|||
| ^ help: use `()` instead of `_`: `()`
|
||||
|
||||
error: matching over `()` is more explicit
|
||||
--> $DIR/ignored_unit_patterns.rs:14:28
|
||||
--> $DIR/ignored_unit_patterns.rs:15:28
|
||||
|
|
||||
LL | let _ = foo().map_err(|_| todo!());
|
||||
| ^ help: use `()` instead of `_`: `()`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: matching over `()` is more explicit
|
||||
--> $DIR/ignored_unit_patterns.rs:21:9
|
||||
|
|
||||
LL | let _ = foo().unwrap();
|
||||
| ^ help: use `()` instead of `_`: `()`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -65,4 +65,22 @@ impl SomeTrait for SomeStruct {
|
|||
}
|
||||
}
|
||||
|
||||
mod issue11422 {
|
||||
use core::fmt::Debug;
|
||||
// Some additional tests that would cause ICEs:
|
||||
|
||||
// `PartialOrd` has a default generic parameter and does not need to be explicitly specified.
|
||||
// This needs special handling.
|
||||
fn default_generic_param1() -> impl PartialOrd + Debug {}
|
||||
fn default_generic_param2() -> impl PartialOrd + Debug {}
|
||||
|
||||
// Referring to `Self` in the supertrait clause needs special handling.
|
||||
trait Trait1<X: ?Sized> {}
|
||||
trait Trait2: Trait1<Self> {}
|
||||
impl Trait1<()> for () {}
|
||||
impl Trait2 for () {}
|
||||
|
||||
fn f() -> impl Trait1<()> + Trait2 {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -65,4 +65,22 @@ impl SomeTrait for SomeStruct {
|
|||
}
|
||||
}
|
||||
|
||||
mod issue11422 {
|
||||
use core::fmt::Debug;
|
||||
// Some additional tests that would cause ICEs:
|
||||
|
||||
// `PartialOrd` has a default generic parameter and does not need to be explicitly specified.
|
||||
// This needs special handling.
|
||||
fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
|
||||
fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
|
||||
|
||||
// Referring to `Self` in the supertrait clause needs special handling.
|
||||
trait Trait1<X: ?Sized> {}
|
||||
trait Trait2: Trait1<Self> {}
|
||||
impl Trait1<()> for () {}
|
||||
impl Trait2 for () {}
|
||||
|
||||
fn f() -> impl Trait1<()> + Trait2 {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -120,5 +120,29 @@ LL - fn f() -> impl Deref + DerefMut<Target = u8> {
|
|||
LL + fn f() -> impl DerefMut<Target = u8> {
|
||||
|
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: this bound is already specified as the supertrait of `PartialOrd`
|
||||
--> $DIR/implied_bounds_in_impls.rs:74:41
|
||||
|
|
||||
LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: try removing this bound
|
||||
|
|
||||
LL - fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
|
||||
LL + fn default_generic_param1() -> impl PartialOrd + Debug {}
|
||||
|
|
||||
|
||||
error: this bound is already specified as the supertrait of `PartialOrd`
|
||||
--> $DIR/implied_bounds_in_impls.rs:75:54
|
||||
|
|
||||
LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: try removing this bound
|
||||
|
|
||||
LL - fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
|
||||
LL + fn default_generic_param2() -> impl PartialOrd + Debug {}
|
||||
|
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
|||
71
tests/ui/iter_out_of_bounds.rs
Normal file
71
tests/ui/iter_out_of_bounds.rs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
//@no-rustfix
|
||||
|
||||
#![deny(clippy::iter_out_of_bounds)]
|
||||
#![allow(clippy::useless_vec)]
|
||||
|
||||
fn opaque_empty_iter() -> impl Iterator<Item = ()> {
|
||||
std::iter::empty()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[allow(clippy::never_loop)]
|
||||
for _ in [1, 2, 3].iter().skip(4) {
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
unreachable!();
|
||||
}
|
||||
for (i, _) in [1, 2, 3].iter().take(4).enumerate() {
|
||||
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
|
||||
assert!(i <= 2);
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_borrow)]
|
||||
for _ in (&&&&&&[1, 2, 3]).iter().take(4) {}
|
||||
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
|
||||
|
||||
for _ in [1, 2, 3].iter().skip(4) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
for _ in [1; 3].iter().skip(4) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
// Should not lint
|
||||
for _ in opaque_empty_iter().skip(1) {}
|
||||
|
||||
for _ in vec![1, 2, 3].iter().skip(4) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
for _ in vec![1; 3].iter().skip(4) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
let x = [1, 2, 3];
|
||||
for _ in x.iter().skip(4) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
let n = 4;
|
||||
for _ in x.iter().skip(n) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
let empty = std::iter::empty::<i8>;
|
||||
|
||||
for _ in empty().skip(1) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
for _ in empty().take(1) {}
|
||||
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
|
||||
|
||||
for _ in std::iter::once(1).skip(2) {}
|
||||
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
|
||||
|
||||
for _ in std::iter::once(1).take(2) {}
|
||||
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
|
||||
|
||||
for x in [].iter().take(1) {
|
||||
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
|
||||
let _: &i32 = x;
|
||||
}
|
||||
|
||||
// ok, not out of bounds
|
||||
for _ in [1].iter().take(1) {}
|
||||
for _ in [1, 2, 3].iter().take(2) {}
|
||||
for _ in [1, 2, 3].iter().skip(2) {}
|
||||
}
|
||||
119
tests/ui/iter_out_of_bounds.stderr
Normal file
119
tests/ui/iter_out_of_bounds.stderr
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:12:14
|
||||
|
|
||||
LL | for _ in [1, 2, 3].iter().skip(4) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
note: the lint level is defined here
|
||||
--> $DIR/iter_out_of_bounds.rs:3:9
|
||||
|
|
||||
LL | #![deny(clippy::iter_out_of_bounds)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `.take()` call takes more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:16:19
|
||||
|
|
||||
LL | for (i, _) in [1, 2, 3].iter().take(4).enumerate() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and the returned iterator will simply yield the same items
|
||||
|
||||
error: this `.take()` call takes more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:22:14
|
||||
|
|
||||
LL | for _ in (&&&&&&[1, 2, 3]).iter().take(4) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and the returned iterator will simply yield the same items
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:25:14
|
||||
|
|
||||
LL | for _ in [1, 2, 3].iter().skip(4) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:28:14
|
||||
|
|
||||
LL | for _ in [1; 3].iter().skip(4) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:34:14
|
||||
|
|
||||
LL | for _ in vec![1, 2, 3].iter().skip(4) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:37:14
|
||||
|
|
||||
LL | for _ in vec![1; 3].iter().skip(4) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:41:14
|
||||
|
|
||||
LL | for _ in x.iter().skip(4) {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:45:14
|
||||
|
|
||||
LL | for _ in x.iter().skip(n) {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:50:14
|
||||
|
|
||||
LL | for _ in empty().skip(1) {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.take()` call takes more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:53:14
|
||||
|
|
||||
LL | for _ in empty().take(1) {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and the returned iterator will simply yield the same items
|
||||
|
||||
error: this `.skip()` call skips more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:56:14
|
||||
|
|
||||
LL | for _ in std::iter::once(1).skip(2) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and will create an empty iterator
|
||||
|
||||
error: this `.take()` call takes more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:59:14
|
||||
|
|
||||
LL | for _ in std::iter::once(1).take(2) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and the returned iterator will simply yield the same items
|
||||
|
||||
error: this `.take()` call takes more items than the iterator will produce
|
||||
--> $DIR/iter_out_of_bounds.rs:62:14
|
||||
|
|
||||
LL | for x in [].iter().take(1) {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this operation is useless and the returned iterator will simply yield the same items
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
@ -63,11 +63,9 @@ fn main() {
|
|||
|
||||
let _ = vec.iter().for_each(|x| assert!(!x.is_empty()));
|
||||
|
||||
// Not implemented yet
|
||||
let _ = vec.iter().cloned().all(|x| x.len() == 1);
|
||||
let _ = vec.iter().all(|x| x.len() == 1);
|
||||
|
||||
// Not implemented yet
|
||||
let _ = vec.iter().cloned().any(|x| x.len() == 1);
|
||||
let _ = vec.iter().any(|x| x.len() == 1);
|
||||
|
||||
// Should probably stay as it is.
|
||||
let _ = [0, 1, 2, 3, 4].iter().cloned().take(10);
|
||||
|
|
|
|||
|
|
@ -64,10 +64,8 @@ fn main() {
|
|||
|
||||
let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty()));
|
||||
|
||||
// Not implemented yet
|
||||
let _ = vec.iter().cloned().all(|x| x.len() == 1);
|
||||
|
||||
// Not implemented yet
|
||||
let _ = vec.iter().cloned().any(|x| x.len() == 1);
|
||||
|
||||
// Should probably stay as it is.
|
||||
|
|
|
|||
|
|
@ -148,5 +148,21 @@ LL | let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty()));
|
|||
| |
|
||||
| help: try: `.for_each(|x| assert!(!x.is_empty()))`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
error: unneeded cloning of iterator items
|
||||
--> $DIR/iter_overeager_cloned.rs:67:13
|
||||
|
|
||||
LL | let _ = vec.iter().cloned().all(|x| x.len() == 1);
|
||||
| ^^^^^^^^^^-------------------------------
|
||||
| |
|
||||
| help: try: `.all(|x| x.len() == 1)`
|
||||
|
||||
error: unneeded cloning of iterator items
|
||||
--> $DIR/iter_overeager_cloned.rs:69:13
|
||||
|
|
||||
LL | let _ = vec.iter().cloned().any(|x| x.len() == 1);
|
||||
| ^^^^^^^^^^-------------------------------
|
||||
| |
|
||||
| help: try: `.any(|x| x.len() == 1)`
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#![allow(clippy::disallowed_names)]
|
||||
#![allow(clippy::iter_nth)]
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![allow(clippy::iter_out_of_bounds)]
|
||||
#![allow(unused_mut, dead_code)]
|
||||
|
||||
extern crate option_helpers;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#![allow(clippy::disallowed_names)]
|
||||
#![allow(clippy::iter_nth)]
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![allow(clippy::iter_out_of_bounds)]
|
||||
#![allow(unused_mut, dead_code)]
|
||||
|
||||
extern crate option_helpers;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:16:28
|
||||
--> $DIR/iter_skip_next.rs:17:28
|
||||
|
|
||||
LL | let _ = some_vec.iter().skip(42).next();
|
||||
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
|
||||
|
|
@ -8,37 +8,37 @@ LL | let _ = some_vec.iter().skip(42).next();
|
|||
= help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]`
|
||||
|
||||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:17:36
|
||||
--> $DIR/iter_skip_next.rs:18:36
|
||||
|
|
||||
LL | let _ = some_vec.iter().cycle().skip(42).next();
|
||||
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
|
||||
|
||||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:18:20
|
||||
--> $DIR/iter_skip_next.rs:19:20
|
||||
|
|
||||
LL | let _ = (1..10).skip(10).next();
|
||||
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)`
|
||||
|
||||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:19:33
|
||||
--> $DIR/iter_skip_next.rs:20:33
|
||||
|
|
||||
LL | let _ = &some_vec[..].iter().skip(3).next();
|
||||
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)`
|
||||
|
||||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:27:26
|
||||
--> $DIR/iter_skip_next.rs:28:26
|
||||
|
|
||||
LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
|
||||
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
||||
|
||||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:29:29
|
||||
--> $DIR/iter_skip_next.rs:30:29
|
||||
|
|
||||
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
|
||||
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
||||
|
||||
error: called `skip(..).next()` on an iterator
|
||||
--> $DIR/iter_skip_next.rs:35:29
|
||||
--> $DIR/iter_skip_next.rs:36:29
|
||||
|
|
||||
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
|
||||
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#![warn(clippy::iter_skip_next)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(dead_code, clippy::iter_out_of_bounds)]
|
||||
//@no-rustfix
|
||||
/// Checks implementation of `ITER_SKIP_NEXT` lint
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![allow(clippy::useless_vec, unused)]
|
||||
#![allow(clippy::useless_vec, clippy::iter_out_of_bounds, unused)]
|
||||
#![warn(clippy::iter_skip_zero)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![allow(clippy::useless_vec, unused)]
|
||||
#![allow(clippy::useless_vec, clippy::iter_out_of_bounds, unused)]
|
||||
#![warn(clippy::iter_skip_zero)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ fn main() {
|
|||
let _ = matches!(f, 1 | 2147483647);
|
||||
let _ = matches!(f, 0 | 2147483647);
|
||||
let _ = matches!(f, -2147483647 | 2147483647);
|
||||
let _ = matches!(f, 1 | (2..=4));
|
||||
let _ = matches!(f, 1 | (2..4));
|
||||
let _ = matches!(f, 1..=4);
|
||||
let _ = matches!(f, 1..4);
|
||||
let _ = matches!(f, 1..=48324729);
|
||||
let _ = matches!(f, 0..=48324730);
|
||||
let _ = matches!(f, 0..=3);
|
||||
|
|
@ -25,9 +25,20 @@ fn main() {
|
|||
};
|
||||
let _ = matches!(f, -5..=3);
|
||||
let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing
|
||||
let _ = matches!(f, -1000001..=1000001);
|
||||
let _ = matches!(f, -1_000_001..=1_000_001);
|
||||
let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002);
|
||||
|
||||
matches!(f, 0x00..=0x03);
|
||||
matches!(f, 0x00..=0x07);
|
||||
matches!(f, -0x09..=0x00);
|
||||
|
||||
matches!(f, 0..=5);
|
||||
matches!(f, 0..5);
|
||||
|
||||
matches!(f, 0..10);
|
||||
matches!(f, 0..=10);
|
||||
matches!(f, 0..=10);
|
||||
|
||||
macro_rules! mac {
|
||||
($e:expr) => {
|
||||
matches!($e, 1..=10)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,17 @@ fn main() {
|
|||
let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001);
|
||||
let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002);
|
||||
|
||||
matches!(f, 0x00 | 0x01 | 0x02 | 0x03);
|
||||
matches!(f, 0x00..=0x05 | 0x06 | 0x07);
|
||||
matches!(f, -0x09 | -0x08 | -0x07..=0x00);
|
||||
|
||||
matches!(f, 0..5 | 5);
|
||||
matches!(f, 0 | 1..5);
|
||||
|
||||
matches!(f, 0..=5 | 6..10);
|
||||
matches!(f, 0..5 | 5..=10);
|
||||
matches!(f, 5..=10 | 0..5);
|
||||
|
||||
macro_rules! mac {
|
||||
($e:expr) => {
|
||||
matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,18 @@ error: this OR pattern can be rewritten using a range
|
|||
LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:16:25
|
||||
|
|
||||
LL | let _ = matches!(f, 1 | (2..=4));
|
||||
| ^^^^^^^^^^^ help: try: `1..=4`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:17:25
|
||||
|
|
||||
LL | let _ = matches!(f, 1 | (2..4));
|
||||
| ^^^^^^^^^^ help: try: `1..4`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:18:25
|
||||
|
|
||||
|
|
@ -47,10 +59,58 @@ error: this OR pattern can be rewritten using a range
|
|||
--> $DIR/manual_range_patterns.rs:28:25
|
||||
|
|
||||
LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1000001..=1000001`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:33:26
|
||||
--> $DIR/manual_range_patterns.rs:31:17
|
||||
|
|
||||
LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:32:17
|
||||
|
|
||||
LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:33:17
|
||||
|
|
||||
LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:35:17
|
||||
|
|
||||
LL | matches!(f, 0..5 | 5);
|
||||
| ^^^^^^^^ help: try: `0..=5`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:36:17
|
||||
|
|
||||
LL | matches!(f, 0 | 1..5);
|
||||
| ^^^^^^^^ help: try: `0..5`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:38:17
|
||||
|
|
||||
LL | matches!(f, 0..=5 | 6..10);
|
||||
| ^^^^^^^^^^^^^ help: try: `0..10`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:39:17
|
||||
|
|
||||
LL | matches!(f, 0..5 | 5..=10);
|
||||
| ^^^^^^^^^^^^^ help: try: `0..=10`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:40:17
|
||||
|
|
||||
LL | matches!(f, 5..=10 | 0..5);
|
||||
| ^^^^^^^^^^^^^ help: try: `0..=10`
|
||||
|
||||
error: this OR pattern can be rewritten using a range
|
||||
--> $DIR/manual_range_patterns.rs:44:26
|
||||
|
|
||||
LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
||||
|
|
@ -60,5 +120,5 @@ LL | mac!(f);
|
|||
|
|
||||
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
|||
121
tests/ui/missing_asserts_for_indexing.fixed
Normal file
121
tests/ui/missing_asserts_for_indexing.fixed
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#![allow(unused)]
|
||||
#![warn(clippy::missing_asserts_for_indexing)]
|
||||
|
||||
// ok
|
||||
fn sum_with_assert(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn sum_with_assert_other_way(v: &[u8]) -> u8 {
|
||||
assert!(5 <= v.len());
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn sum_with_assert_ge(v: &[u8]) -> u8 {
|
||||
assert!(v.len() >= 5);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 {
|
||||
assert!(4 < v.len());
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
fn sum_with_assert_lt(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
fn sum_with_assert_le(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
// ok, don't lint for single array access
|
||||
fn single_access(v: &[u8]) -> u8 {
|
||||
v[0]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn subslice_ok(v: &[u8]) {
|
||||
assert!(v.len() > 3);
|
||||
let _ = v[0];
|
||||
let _ = v[1..4];
|
||||
}
|
||||
|
||||
fn subslice_bad(v: &[u8]) {
|
||||
assert!(v.len() > 3);
|
||||
let _ = v[0];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v[1..4];
|
||||
}
|
||||
|
||||
// ok
|
||||
fn subslice_inclusive_ok(v: &[u8]) {
|
||||
assert!(v.len() > 4);
|
||||
let _ = v[0];
|
||||
let _ = v[1..=4];
|
||||
}
|
||||
|
||||
fn subslice_inclusive_bad(v: &[u8]) {
|
||||
assert!(v.len() > 4);
|
||||
let _ = v[0];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v[1..=4];
|
||||
}
|
||||
|
||||
fn index_different_slices_ok(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() > 12);
|
||||
assert!(v2.len() > 15);
|
||||
let _ = v1[0] + v1[12];
|
||||
let _ = v2[5] + v2[15];
|
||||
}
|
||||
|
||||
fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() > 12);
|
||||
assert!(v2.len() > 15);
|
||||
let _ = v1[0] + v1[12];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v2[5] + v2[15];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() > 12);
|
||||
assert!(v2.len() > 15);
|
||||
let _ = v1[0] + v1[12];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v2[5] + v2[15];
|
||||
}
|
||||
|
||||
fn side_effect() -> &'static [u8] {
|
||||
&[]
|
||||
}
|
||||
|
||||
fn index_side_effect_expr() {
|
||||
let _ = side_effect()[0] + side_effect()[1];
|
||||
}
|
||||
|
||||
// ok, single access for different slices
|
||||
fn index_different_slice_in_same_expr(v1: &[u8], v2: &[u8]) {
|
||||
let _ = v1[0] + v2[1];
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
121
tests/ui/missing_asserts_for_indexing.rs
Normal file
121
tests/ui/missing_asserts_for_indexing.rs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#![allow(unused)]
|
||||
#![warn(clippy::missing_asserts_for_indexing)]
|
||||
|
||||
// ok
|
||||
fn sum_with_assert(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn sum_with_assert_other_way(v: &[u8]) -> u8 {
|
||||
assert!(5 <= v.len());
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn sum_with_assert_ge(v: &[u8]) -> u8 {
|
||||
assert!(v.len() >= 5);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 {
|
||||
assert!(4 < v.len());
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
}
|
||||
|
||||
fn sum_with_assert_lt(v: &[u8]) -> u8 {
|
||||
assert!(v.len() < 5);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
fn sum_with_assert_le(v: &[u8]) -> u8 {
|
||||
assert!(v.len() <= 5);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 {
|
||||
assert!(v.len() > 3);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 {
|
||||
assert!(v.len() >= 4);
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
|
||||
// ok, don't lint for single array access
|
||||
fn single_access(v: &[u8]) -> u8 {
|
||||
v[0]
|
||||
}
|
||||
|
||||
// ok
|
||||
fn subslice_ok(v: &[u8]) {
|
||||
assert!(v.len() > 3);
|
||||
let _ = v[0];
|
||||
let _ = v[1..4];
|
||||
}
|
||||
|
||||
fn subslice_bad(v: &[u8]) {
|
||||
assert!(v.len() >= 3);
|
||||
let _ = v[0];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v[1..4];
|
||||
}
|
||||
|
||||
// ok
|
||||
fn subslice_inclusive_ok(v: &[u8]) {
|
||||
assert!(v.len() > 4);
|
||||
let _ = v[0];
|
||||
let _ = v[1..=4];
|
||||
}
|
||||
|
||||
fn subslice_inclusive_bad(v: &[u8]) {
|
||||
assert!(v.len() >= 4);
|
||||
let _ = v[0];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v[1..=4];
|
||||
}
|
||||
|
||||
fn index_different_slices_ok(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() > 12);
|
||||
assert!(v2.len() > 15);
|
||||
let _ = v1[0] + v1[12];
|
||||
let _ = v2[5] + v2[15];
|
||||
}
|
||||
|
||||
fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() >= 12);
|
||||
assert!(v2.len() >= 15);
|
||||
let _ = v1[0] + v1[12];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v2[5] + v2[15];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
}
|
||||
fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() >= 12);
|
||||
assert!(v2.len() > 15);
|
||||
let _ = v1[0] + v1[12];
|
||||
//~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the
|
||||
let _ = v2[5] + v2[15];
|
||||
}
|
||||
|
||||
fn side_effect() -> &'static [u8] {
|
||||
&[]
|
||||
}
|
||||
|
||||
fn index_side_effect_expr() {
|
||||
let _ = side_effect()[0] + side_effect()[1];
|
||||
}
|
||||
|
||||
// ok, single access for different slices
|
||||
fn index_different_slice_in_same_expr(v1: &[u8], v2: &[u8]) {
|
||||
let _ = v1[0] + v2[1];
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
253
tests/ui/missing_asserts_for_indexing.stderr
Normal file
253
tests/ui/missing_asserts_for_indexing.stderr
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:30:5
|
||||
|
|
||||
LL | assert!(v.len() < 5);
|
||||
| -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:30:5
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:30:12
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:30:19
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:30:26
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:30:33
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
= note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]`
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:36:5
|
||||
|
|
||||
LL | assert!(v.len() <= 5);
|
||||
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:36:5
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:36:12
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:36:19
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:36:26
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:36:33
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:42:5
|
||||
|
|
||||
LL | assert!(v.len() > 3);
|
||||
| -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:42:5
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:42:12
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:42:19
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:42:26
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:42:33
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:48:5
|
||||
|
|
||||
LL | assert!(v.len() >= 4);
|
||||
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:48:5
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:48:12
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:48:19
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:48:26
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:48:33
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:66:13
|
||||
|
|
||||
LL | assert!(v.len() >= 3);
|
||||
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)`
|
||||
LL | let _ = v[0];
|
||||
| _____________^
|
||||
LL | |
|
||||
LL | | let _ = v[1..4];
|
||||
| |___________________^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:66:13
|
||||
|
|
||||
LL | let _ = v[0];
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:68:13
|
||||
|
|
||||
LL | let _ = v[1..4];
|
||||
| ^^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:80:13
|
||||
|
|
||||
LL | assert!(v.len() >= 4);
|
||||
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
|
||||
LL | let _ = v[0];
|
||||
| _____________^
|
||||
LL | |
|
||||
LL | | let _ = v[1..=4];
|
||||
| |____________________^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:80:13
|
||||
|
|
||||
LL | let _ = v[0];
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:82:13
|
||||
|
|
||||
LL | let _ = v[1..=4];
|
||||
| ^^^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:95:13
|
||||
|
|
||||
LL | assert!(v1.len() >= 12);
|
||||
| ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)`
|
||||
LL | assert!(v2.len() >= 15);
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:95:13
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:95:21
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:97:13
|
||||
|
|
||||
LL | assert!(v2.len() >= 15);
|
||||
| ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)`
|
||||
...
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:97:13
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:97:21
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
|
||||
--> $DIR/missing_asserts_for_indexing.rs:103:13
|
||||
|
|
||||
LL | assert!(v1.len() >= 12);
|
||||
| ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)`
|
||||
LL | assert!(v2.len() > 15);
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:103:13
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing.rs:103:21
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
49
tests/ui/missing_asserts_for_indexing_unfixable.rs
Normal file
49
tests/ui/missing_asserts_for_indexing_unfixable.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#![allow(unused)]
|
||||
#![warn(clippy::missing_asserts_for_indexing)]
|
||||
|
||||
fn sum(v: &[u8]) -> u8 {
|
||||
v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
//~^ ERROR: indexing into a slice multiple times without an `assert`
|
||||
}
|
||||
|
||||
fn subslice(v: &[u8]) {
|
||||
let _ = v[0];
|
||||
//~^ ERROR: indexing into a slice multiple times without an `assert`
|
||||
let _ = v[1..4];
|
||||
}
|
||||
|
||||
fn variables(v: &[u8]) -> u8 {
|
||||
let a = v[0];
|
||||
//~^ ERROR: indexing into a slice multiple times without an `assert`
|
||||
let b = v[1];
|
||||
let c = v[2];
|
||||
a + b + c
|
||||
}
|
||||
|
||||
fn index_different_slices(v1: &[u8], v2: &[u8]) {
|
||||
let _ = v1[0] + v1[12];
|
||||
let _ = v2[5] + v2[15];
|
||||
}
|
||||
|
||||
fn index_different_slices2(v1: &[u8], v2: &[u8]) {
|
||||
assert!(v1.len() > 12);
|
||||
let _ = v1[0] + v1[12];
|
||||
let _ = v2[5] + v2[15];
|
||||
}
|
||||
|
||||
struct Foo<'a> {
|
||||
v: &'a [u8],
|
||||
v2: &'a [u8],
|
||||
}
|
||||
|
||||
fn index_struct_field(f: &Foo<'_>) {
|
||||
let _ = f.v[0] + f.v[1];
|
||||
//~^ ERROR: indexing into a slice multiple times without an `assert`
|
||||
}
|
||||
|
||||
fn index_struct_different_fields(f: &Foo<'_>) {
|
||||
// ok, different fields
|
||||
let _ = f.v[0] + f.v2[1];
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
164
tests/ui/missing_asserts_for_indexing_unfixable.stderr
Normal file
164
tests/ui/missing_asserts_for_indexing_unfixable.stderr
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:5:5
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(v.len() > 4);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:5:5
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:5:12
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:5:19
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:5:26
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:5:33
|
||||
|
|
||||
LL | v[0] + v[1] + v[2] + v[3] + v[4]
|
||||
| ^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
= note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]`
|
||||
|
||||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:10:13
|
||||
|
|
||||
LL | let _ = v[0];
|
||||
| _____________^
|
||||
LL | |
|
||||
LL | | let _ = v[1..4];
|
||||
| |___________________^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(v.len() > 3);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:10:13
|
||||
|
|
||||
LL | let _ = v[0];
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:12:13
|
||||
|
|
||||
LL | let _ = v[1..4];
|
||||
| ^^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:16:13
|
||||
|
|
||||
LL | let a = v[0];
|
||||
| _____________^
|
||||
LL | |
|
||||
LL | | let b = v[1];
|
||||
LL | | let c = v[2];
|
||||
| |________________^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(v.len() > 2);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:16:13
|
||||
|
|
||||
LL | let a = v[0];
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:18:13
|
||||
|
|
||||
LL | let b = v[1];
|
||||
| ^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:19:13
|
||||
|
|
||||
LL | let c = v[2];
|
||||
| ^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:24:13
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(v1.len() > 12);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:24:13
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:24:21
|
||||
|
|
||||
LL | let _ = v1[0] + v1[12];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:25:13
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(v2.len() > 15);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:25:13
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:25:21
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:31:13
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(v2.len() > 15);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:31:13
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:31:21
|
||||
|
|
||||
LL | let _ = v2[5] + v2[15];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: indexing into a slice multiple times without an `assert`
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:40:13
|
||||
|
|
||||
LL | let _ = f.v[0] + f.v[1];
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider asserting the length before indexing: `assert!(f.v.len() > 1);`
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:40:13
|
||||
|
|
||||
LL | let _ = f.v[0] + f.v[1];
|
||||
| ^^^^^^
|
||||
note: slice indexed here
|
||||
--> $DIR/missing_asserts_for_indexing_unfixable.rs:40:22
|
||||
|
|
||||
LL | let _ = f.v[0] + f.v[1];
|
||||
| ^^^^^^
|
||||
= note: asserting the length before indexing will elide bounds checks
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
@ -503,3 +503,16 @@ mod issue_10535 {
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
mod issue_10253 {
|
||||
struct S;
|
||||
trait X {
|
||||
fn f<T>(&self);
|
||||
}
|
||||
impl X for &S {
|
||||
fn f<T>(&self) {}
|
||||
}
|
||||
fn f() {
|
||||
(&S).f::<()>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -503,3 +503,16 @@ mod issue_10535 {
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
mod issue_10253 {
|
||||
struct S;
|
||||
trait X {
|
||||
fn f<T>(&self);
|
||||
}
|
||||
impl X for &S {
|
||||
fn f<T>(&self) {}
|
||||
}
|
||||
fn f() {
|
||||
(&S).f::<()>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,13 @@ fn main() {
|
|||
b"aaa";
|
||||
br#""aaa""#;
|
||||
br#"\s"#;
|
||||
// currently disabled: https://github.com/rust-lang/rust/issues/113333
|
||||
// cr#"aaa"#;
|
||||
// cr#""aaa""#;
|
||||
// cr#"\s"#;
|
||||
c"aaa";
|
||||
cr#""aaa""#;
|
||||
cr#"\s"#;
|
||||
|
||||
"
|
||||
a
|
||||
multiline
|
||||
string
|
||||
";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,13 @@ fn main() {
|
|||
br#"aaa"#;
|
||||
br#""aaa""#;
|
||||
br#"\s"#;
|
||||
// currently disabled: https://github.com/rust-lang/rust/issues/113333
|
||||
// cr#"aaa"#;
|
||||
// cr#""aaa""#;
|
||||
// cr#"\s"#;
|
||||
cr#"aaa"#;
|
||||
cr#""aaa""#;
|
||||
cr#"\s"#;
|
||||
|
||||
r#"
|
||||
a
|
||||
multiline
|
||||
string
|
||||
"#;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,58 @@ error: unnecessary raw string literal
|
|||
--> $DIR/needless_raw_string.rs:6:5
|
||||
|
|
||||
LL | r#"aaa"#;
|
||||
| ^^^^^^^^ help: try: `"aaa"`
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::needless-raw-strings` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_raw_strings)]`
|
||||
help: try
|
||||
|
|
||||
LL - r#"aaa"#;
|
||||
LL + "aaa";
|
||||
|
|
||||
|
||||
error: unnecessary raw string literal
|
||||
--> $DIR/needless_raw_string.rs:9:5
|
||||
|
|
||||
LL | br#"aaa"#;
|
||||
| ^^^^^^^^^ help: try: `b"aaa"`
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: try
|
||||
|
|
||||
LL - br#"aaa"#;
|
||||
LL + b"aaa";
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: unnecessary raw string literal
|
||||
--> $DIR/needless_raw_string.rs:12:5
|
||||
|
|
||||
LL | cr#"aaa"#;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: try
|
||||
|
|
||||
LL - cr#"aaa"#;
|
||||
LL + c"aaa";
|
||||
|
|
||||
|
||||
error: unnecessary raw string literal
|
||||
--> $DIR/needless_raw_string.rs:16:5
|
||||
|
|
||||
LL | / r#"
|
||||
LL | | a
|
||||
LL | | multiline
|
||||
LL | | string
|
||||
LL | | "#;
|
||||
| |______^
|
||||
|
|
||||
help: try
|
||||
|
|
||||
LL ~ "
|
||||
LL | a
|
||||
LL | multiline
|
||||
LL | string
|
||||
LL ~ ";
|
||||
|
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,22 @@
|
|||
#![feature(c_str_literals)]
|
||||
|
||||
fn main() {
|
||||
r#"aaa"#;
|
||||
r"\aaa";
|
||||
r#"Hello "world"!"#;
|
||||
r####" "### "## "# "####;
|
||||
r###" "aa" "# "## "###;
|
||||
br#"aaa"#;
|
||||
br"\aaa";
|
||||
br#"Hello "world"!"#;
|
||||
br####" "### "## "# "####;
|
||||
br###" "aa" "# "## "###;
|
||||
// currently disabled: https://github.com/rust-lang/rust/issues/113333
|
||||
// cr#"aaa"#;
|
||||
// cr##"Hello "world"!"##;
|
||||
// cr######" "### "## "# "######;
|
||||
// cr######" "aa" "# "## "######;
|
||||
cr"\aaa";
|
||||
cr#"Hello "world"!"#;
|
||||
cr####" "### "## "# "####;
|
||||
cr###" "aa" "# "## "###;
|
||||
|
||||
r"
|
||||
\a
|
||||
multiline
|
||||
string
|
||||
";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,22 @@
|
|||
#![feature(c_str_literals)]
|
||||
|
||||
fn main() {
|
||||
r#"aaa"#;
|
||||
r#"\aaa"#;
|
||||
r##"Hello "world"!"##;
|
||||
r######" "### "## "# "######;
|
||||
r######" "aa" "# "## "######;
|
||||
br#"aaa"#;
|
||||
br#"\aaa"#;
|
||||
br##"Hello "world"!"##;
|
||||
br######" "### "## "# "######;
|
||||
br######" "aa" "# "## "######;
|
||||
// currently disabled: https://github.com/rust-lang/rust/issues/113333
|
||||
// cr#"aaa"#;
|
||||
// cr##"Hello "world"!"##;
|
||||
// cr######" "### "## "# "######;
|
||||
// cr######" "aa" "# "## "######;
|
||||
cr#"\aaa"#;
|
||||
cr##"Hello "world"!"##;
|
||||
cr######" "### "## "# "######;
|
||||
cr######" "aa" "# "## "######;
|
||||
|
||||
r#"
|
||||
\a
|
||||
multiline
|
||||
string
|
||||
"#;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +1,167 @@
|
|||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:6:5
|
||||
|
|
||||
LL | r#"\aaa"#;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]`
|
||||
help: remove all the hashes around the literal
|
||||
|
|
||||
LL - r#"\aaa"#;
|
||||
LL + r"\aaa";
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:7:5
|
||||
|
|
||||
LL | r##"Hello "world"!"##;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `r#"Hello "world"!"#`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove one hash from both sides of the literal
|
||||
|
|
||||
LL - r##"Hello "world"!"##;
|
||||
LL + r#"Hello "world"!"#;
|
||||
|
|
||||
= note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]`
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:8:5
|
||||
|
|
||||
LL | r######" "### "## "# "######;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r####" "### "## "# "####`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove 2 hashes from both sides of the literal
|
||||
|
|
||||
LL - r######" "### "## "# "######;
|
||||
LL + r####" "### "## "# "####;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:9:5
|
||||
|
|
||||
LL | r######" "aa" "# "## "######;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r###" "aa" "# "## "###`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove 3 hashes from both sides of the literal
|
||||
|
|
||||
LL - r######" "aa" "# "## "######;
|
||||
LL + r###" "aa" "# "## "###;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:10:5
|
||||
|
|
||||
LL | br#"\aaa"#;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: remove all the hashes around the literal
|
||||
|
|
||||
LL - br#"\aaa"#;
|
||||
LL + br"\aaa";
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:11:5
|
||||
|
|
||||
LL | br##"Hello "world"!"##;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `br#"Hello "world"!"#`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove one hash from both sides of the literal
|
||||
|
|
||||
LL - br##"Hello "world"!"##;
|
||||
LL + br#"Hello "world"!"#;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:12:5
|
||||
|
|
||||
LL | br######" "### "## "# "######;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br####" "### "## "# "####`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove 2 hashes from both sides of the literal
|
||||
|
|
||||
LL - br######" "### "## "# "######;
|
||||
LL + br####" "### "## "# "####;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:13:5
|
||||
|
|
||||
LL | br######" "aa" "# "## "######;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br###" "aa" "# "## "###`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove 3 hashes from both sides of the literal
|
||||
|
|
||||
LL - br######" "aa" "# "## "######;
|
||||
LL + br###" "aa" "# "## "###;
|
||||
|
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:14:5
|
||||
|
|
||||
LL | cr#"\aaa"#;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: remove all the hashes around the literal
|
||||
|
|
||||
LL - cr#"\aaa"#;
|
||||
LL + cr"\aaa";
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:15:5
|
||||
|
|
||||
LL | cr##"Hello "world"!"##;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove one hash from both sides of the literal
|
||||
|
|
||||
LL - cr##"Hello "world"!"##;
|
||||
LL + cr#"Hello "world"!"#;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:16:5
|
||||
|
|
||||
LL | cr######" "### "## "# "######;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove 2 hashes from both sides of the literal
|
||||
|
|
||||
LL - cr######" "### "## "# "######;
|
||||
LL + cr####" "### "## "# "####;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:17:5
|
||||
|
|
||||
LL | cr######" "aa" "# "## "######;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove 3 hashes from both sides of the literal
|
||||
|
|
||||
LL - cr######" "aa" "# "## "######;
|
||||
LL + cr###" "aa" "# "## "###;
|
||||
|
|
||||
|
||||
error: unnecessary hashes around raw string literal
|
||||
--> $DIR/needless_raw_string_hashes.rs:19:5
|
||||
|
|
||||
LL | / r#"
|
||||
LL | | \a
|
||||
LL | | multiline
|
||||
LL | | string
|
||||
LL | | "#;
|
||||
| |______^
|
||||
|
|
||||
help: remove all the hashes around the literal
|
||||
|
|
||||
LL ~ r"
|
||||
LL | \a
|
||||
LL | multiline
|
||||
LL | string
|
||||
LL ~ ";
|
||||
|
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -337,10 +337,8 @@ pub fn test26() {
|
|||
|
||||
pub fn test27() {
|
||||
loop {
|
||||
//~^ ERROR: this loop never actually loops
|
||||
'label: {
|
||||
let x = true;
|
||||
// Lints because we cannot prove it's always `true`
|
||||
if x {
|
||||
break 'label;
|
||||
}
|
||||
|
|
@ -349,6 +347,59 @@ pub fn test27() {
|
|||
}
|
||||
}
|
||||
|
||||
// issue 11004
|
||||
pub fn test29() {
|
||||
loop {
|
||||
'label: {
|
||||
if true {
|
||||
break 'label;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test30() {
|
||||
'a: loop {
|
||||
'b: {
|
||||
for j in 0..2 {
|
||||
if j == 1 {
|
||||
break 'b;
|
||||
}
|
||||
}
|
||||
break 'a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test31(b: bool) {
|
||||
'a: loop {
|
||||
'b: {
|
||||
'c: loop {
|
||||
//~^ ERROR: this loop never actually loops
|
||||
if b { break 'c } else { break 'b }
|
||||
}
|
||||
continue 'a;
|
||||
}
|
||||
break 'a;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test32() {
|
||||
loop {
|
||||
//~^ ERROR: this loop never actually loops
|
||||
panic!("oh no");
|
||||
}
|
||||
loop {
|
||||
//~^ ERROR: this loop never actually loops
|
||||
unimplemented!("not yet");
|
||||
}
|
||||
loop {
|
||||
// no error
|
||||
todo!("maybe later");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test1();
|
||||
test2();
|
||||
|
|
|
|||
|
|
@ -154,16 +154,31 @@ LL | if let Some(_) = (0..20).next() {
|
|||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: this loop never actually loops
|
||||
--> $DIR/never_loop.rs:339:5
|
||||
--> $DIR/never_loop.rs:378:13
|
||||
|
|
||||
LL | / 'c: loop {
|
||||
LL | |
|
||||
LL | | if b { break 'c } else { break 'b }
|
||||
LL | | }
|
||||
| |_____________^
|
||||
|
||||
error: this loop never actually loops
|
||||
--> $DIR/never_loop.rs:389:5
|
||||
|
|
||||
LL | / loop {
|
||||
LL | |
|
||||
LL | | 'label: {
|
||||
LL | | let x = true;
|
||||
... |
|
||||
LL | | }
|
||||
LL | | panic!("oh no");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
error: this loop never actually loops
|
||||
--> $DIR/never_loop.rs:393:5
|
||||
|
|
||||
LL | / loop {
|
||||
LL | |
|
||||
LL | | unimplemented!("not yet");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@ignore-32bit
|
||||
|
||||
#![warn(clippy::result_large_err)]
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:8:23
|
||||
--> $DIR/result_large_err.rs:10:23
|
||||
|
|
||||
LL | pub fn large_err() -> Result<(), [u8; 512]> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
||||
|
|
@ -9,7 +9,7 @@ LL | pub fn large_err() -> Result<(), [u8; 512]> {
|
|||
= help: to override `-D warnings` add `#[allow(clippy::result_large_err)]`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:20:21
|
||||
--> $DIR/result_large_err.rs:22:21
|
||||
|
|
||||
LL | pub fn ret() -> Result<(), Self> {
|
||||
| ^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes
|
||||
|
|
@ -17,7 +17,7 @@ LL | pub fn ret() -> Result<(), Self> {
|
|||
= help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box<FullyDefinedLargeError>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:26:26
|
||||
--> $DIR/result_large_err.rs:28:26
|
||||
|
|
||||
LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes
|
||||
|
|
@ -25,7 +25,7 @@ LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> {
|
|||
= help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box<FullyDefinedLargeError>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:32:45
|
||||
--> $DIR/result_large_err.rs:34:45
|
||||
|
|
||||
LL | pub fn large_err_via_type_alias<T>(x: T) -> Fdlr<T> {
|
||||
| ^^^^^^^ the `Err`-variant is at least 240 bytes
|
||||
|
|
@ -33,7 +33,7 @@ LL | pub fn large_err_via_type_alias<T>(x: T) -> Fdlr<T> {
|
|||
= help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box<FullyDefinedLargeError>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:41:34
|
||||
--> $DIR/result_large_err.rs:43:34
|
||||
|
|
||||
LL | pub fn param_large_error<R>() -> Result<(), (u128, R, FullyDefinedLargeError)> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 256 bytes
|
||||
|
|
@ -41,7 +41,7 @@ LL | pub fn param_large_error<R>() -> Result<(), (u128, R, FullyDefinedLargeErro
|
|||
= help: try reducing the size of `(u128, R, FullyDefinedLargeError)`, for example by boxing large elements or replacing it with `Box<(u128, R, FullyDefinedLargeError)>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:53:34
|
||||
--> $DIR/result_large_err.rs:55:34
|
||||
|
|
||||
LL | _Omg([u8; 512]),
|
||||
| --------------- the largest variant contains at least 512 bytes
|
||||
|
|
@ -52,7 +52,7 @@ LL | pub fn large_enum_error() -> Result<(), Self> {
|
|||
= help: try reducing the size of `LargeErrorVariants<()>`, for example by boxing large elements or replacing it with `Box<LargeErrorVariants<()>>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:66:30
|
||||
--> $DIR/result_large_err.rs:68:30
|
||||
|
|
||||
LL | _Biggest([u8; 1024]),
|
||||
| -------------------- the largest variant contains at least 1024 bytes
|
||||
|
|
@ -65,7 +65,7 @@ LL | fn large_enum_error() -> Result<(), Self> {
|
|||
= help: try reducing the size of `MultipleLargeVariants`, for example by boxing large elements or replacing it with `Box<MultipleLargeVariants>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:73:25
|
||||
--> $DIR/result_large_err.rs:75:25
|
||||
|
|
||||
LL | fn large_error() -> Result<(), [u8; 512]> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
||||
|
|
@ -73,7 +73,7 @@ LL | fn large_error() -> Result<(), [u8; 512]> {
|
|||
= help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:93:29
|
||||
--> $DIR/result_large_err.rs:95:29
|
||||
|
|
||||
LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
||||
|
|
@ -81,7 +81,7 @@ LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
|
|||
= help: try reducing the size of `FullyDefinedUnionError`, for example by boxing large elements or replacing it with `Box<FullyDefinedUnionError>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:103:40
|
||||
--> $DIR/result_large_err.rs:105:40
|
||||
|
|
||||
LL | pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
||||
|
|
@ -89,7 +89,7 @@ LL | pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
|
|||
= help: try reducing the size of `UnionError<T>`, for example by boxing large elements or replacing it with `Box<UnionError<T>>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:113:34
|
||||
--> $DIR/result_large_err.rs:115:34
|
||||
|
|
||||
LL | pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes
|
||||
|
|
@ -97,7 +97,7 @@ LL | pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
|
|||
= help: try reducing the size of `ArrayError<i32, U>`, for example by boxing large elements or replacing it with `Box<ArrayError<i32, U>>`
|
||||
|
||||
error: the `Err`-variant returned from this function is very large
|
||||
--> $DIR/result_large_err.rs:118:31
|
||||
--> $DIR/result_large_err.rs:120:31
|
||||
|
|
||||
LL | pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
unused,
|
||||
clippy::println_empty_string,
|
||||
clippy::empty_loop,
|
||||
clippy::never_loop,
|
||||
clippy::diverging_sub_expression,
|
||||
clippy::let_unit_value
|
||||
)]
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:21:9
|
||||
--> $DIR/similar_names.rs:22:9
|
||||
|
|
||||
LL | let bpple: i32;
|
||||
| ^^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:19:9
|
||||
--> $DIR/similar_names.rs:20:9
|
||||
|
|
||||
LL | let apple: i32;
|
||||
| ^^^^^
|
||||
|
|
@ -13,73 +13,73 @@ LL | let apple: i32;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::similar_names)]`
|
||||
|
||||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:24:9
|
||||
--> $DIR/similar_names.rs:25:9
|
||||
|
|
||||
LL | let cpple: i32;
|
||||
| ^^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:19:9
|
||||
--> $DIR/similar_names.rs:20:9
|
||||
|
|
||||
LL | let apple: i32;
|
||||
| ^^^^^
|
||||
|
||||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:49:9
|
||||
--> $DIR/similar_names.rs:50:9
|
||||
|
|
||||
LL | let bluby: i32;
|
||||
| ^^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:48:9
|
||||
--> $DIR/similar_names.rs:49:9
|
||||
|
|
||||
LL | let blubx: i32;
|
||||
| ^^^^^
|
||||
|
||||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:54:9
|
||||
--> $DIR/similar_names.rs:55:9
|
||||
|
|
||||
LL | let coke: i32;
|
||||
| ^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:52:9
|
||||
--> $DIR/similar_names.rs:53:9
|
||||
|
|
||||
LL | let cake: i32;
|
||||
| ^^^^
|
||||
|
||||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:73:9
|
||||
--> $DIR/similar_names.rs:74:9
|
||||
|
|
||||
LL | let xyzeabc: i32;
|
||||
| ^^^^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:71:9
|
||||
--> $DIR/similar_names.rs:72:9
|
||||
|
|
||||
LL | let xyz1abc: i32;
|
||||
| ^^^^^^^
|
||||
|
||||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:78:9
|
||||
--> $DIR/similar_names.rs:79:9
|
||||
|
|
||||
LL | let parsee: i32;
|
||||
| ^^^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:76:9
|
||||
--> $DIR/similar_names.rs:77:9
|
||||
|
|
||||
LL | let parser: i32;
|
||||
| ^^^^^^
|
||||
|
||||
error: binding's name is too similar to existing binding
|
||||
--> $DIR/similar_names.rs:100:16
|
||||
--> $DIR/similar_names.rs:101:16
|
||||
|
|
||||
LL | bpple: sprang,
|
||||
| ^^^^^^
|
||||
|
|
||||
note: existing binding defined here
|
||||
--> $DIR/similar_names.rs:99:16
|
||||
--> $DIR/similar_names.rs:100:16
|
||||
|
|
||||
LL | apple: spring,
|
||||
| ^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//@ignore-32bit
|
||||
//@aux-build:proc_macros.rs
|
||||
#![allow(clippy::redundant_closure_call, unused)]
|
||||
#![warn(clippy::single_call_fn)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:33:1
|
||||
--> $DIR/single_call_fn.rs:34:1
|
||||
|
|
||||
LL | / fn c() {
|
||||
LL | | println!("really");
|
||||
|
|
@ -9,7 +9,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:40:5
|
||||
--> $DIR/single_call_fn.rs:41:5
|
||||
|
|
||||
LL | c();
|
||||
| ^
|
||||
|
|
@ -17,37 +17,37 @@ LL | c();
|
|||
= help: to override `-D warnings` add `#[allow(clippy::single_call_fn)]`
|
||||
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:12:1
|
||||
--> $DIR/single_call_fn.rs:13:1
|
||||
|
|
||||
LL | fn i() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:17:13
|
||||
--> $DIR/single_call_fn.rs:18:13
|
||||
|
|
||||
LL | let a = i;
|
||||
| ^
|
||||
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:43:1
|
||||
--> $DIR/single_call_fn.rs:44:1
|
||||
|
|
||||
LL | fn a() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:46:5
|
||||
--> $DIR/single_call_fn.rs:47:5
|
||||
|
|
||||
LL | a();
|
||||
| ^
|
||||
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:13:1
|
||||
--> $DIR/single_call_fn.rs:14:1
|
||||
|
|
||||
LL | fn j() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:24:9
|
||||
--> $DIR/single_call_fn.rs:25:9
|
||||
|
|
||||
LL | j();
|
||||
| ^
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::iter::repeat;
|
||||
//@no-rustfix
|
||||
use std::iter::repeat;
|
||||
fn main() {
|
||||
resize_vector();
|
||||
extend_vector();
|
||||
|
|
@ -86,6 +86,20 @@ fn from_empty_vec() {
|
|||
vec1 = Vec::new();
|
||||
vec1.resize(10, 0);
|
||||
//~^ ERROR: slow zero-filling initialization
|
||||
|
||||
vec1 = vec![];
|
||||
vec1.resize(10, 0);
|
||||
//~^ ERROR: slow zero-filling initialization
|
||||
|
||||
macro_rules! x {
|
||||
() => {
|
||||
vec![]
|
||||
};
|
||||
}
|
||||
|
||||
// `vec![]` comes from another macro, don't warn
|
||||
vec1 = x!();
|
||||
vec1.resize(10, 0);
|
||||
}
|
||||
|
||||
fn do_stuff(vec: &mut [u8]) {}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,16 @@ LL | vec1 = Vec::new();
|
|||
LL | vec1.resize(10, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: slow zero-filling initialization
|
||||
--> $DIR/slow_vector_initialization.rs:91:5
|
||||
|
|
||||
LL | vec1 = vec![];
|
||||
| ------ help: consider replacing this with: `vec![0; 10]`
|
||||
LL | vec1.resize(10, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this argument is a mutable reference, but not used mutably
|
||||
--> $DIR/slow_vector_initialization.rs:91:18
|
||||
--> $DIR/slow_vector_initialization.rs:105:18
|
||||
|
|
||||
LL | fn do_stuff(vec: &mut [u8]) {}
|
||||
| ^^^^^^^^^ help: consider changing to: `&[u8]`
|
||||
|
|
@ -106,5 +114,5 @@ LL | fn do_stuff(vec: &mut [u8]) {}
|
|||
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#![warn(clippy::temporary_assignment)]
|
||||
#![allow(const_item_mutation)]
|
||||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:48:5
|
||||
--> $DIR/temporary_assignment.rs:47:5
|
||||
|
|
||||
LL | Struct { field: 0 }.field = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -8,7 +8,7 @@ LL | Struct { field: 0 }.field = 1;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]`
|
||||
|
||||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:51:5
|
||||
--> $DIR/temporary_assignment.rs:50:5
|
||||
|
|
||||
LL | / MultiStruct {
|
||||
LL | |
|
||||
|
|
@ -19,13 +19,13 @@ LL | | .field = 1;
|
|||
| |______________^
|
||||
|
||||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:57:5
|
||||
--> $DIR/temporary_assignment.rs:56:5
|
||||
|
|
||||
LL | ArrayStruct { array: [0] }.array[0] = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:59:5
|
||||
--> $DIR/temporary_assignment.rs:58:5
|
||||
|
|
||||
LL | (0, 0).0 = 1;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
|
|||
8
tests/ui/to_string_in_format_args_incremental.rs
Normal file
8
tests/ui/to_string_in_format_args_incremental.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
//@compile-flags: -C incremental=target/debug/test/incr
|
||||
|
||||
// see https://github.com/rust-lang/rust-clippy/issues/10969
|
||||
|
||||
fn main() {
|
||||
let s = "Hello, world!";
|
||||
println!("{}", s.to_string());
|
||||
}
|
||||
11
tests/ui/to_string_in_format_args_incremental.stderr
Normal file
11
tests/ui/to_string_in_format_args_incremental.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: `to_string` applied to a type that implements `Display` in `println!` args
|
||||
--> $DIR/to_string_in_format_args_incremental.rs:7:21
|
||||
|
|
||||
LL | println!("{}", s.to_string());
|
||||
| ^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,39 +1,28 @@
|
|||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
|
||||
error: transmute from a `f32` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:6:31
|
||||
|
|
||||
LL | let _: *const usize = std::mem::transmute(6.0f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: `f32` (32 bits)
|
||||
= note: target type: `*const usize` (64 bits)
|
||||
= note: `-D clippy::wrong-transmute` implied by `-D warnings`
|
||||
|
||||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
|
||||
error: transmute from a `f32` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:8:29
|
||||
|
|
||||
LL | let _: *mut usize = std::mem::transmute(6.0f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: `f32` (32 bits)
|
||||
= note: target type: `*mut usize` (64 bits)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
|
||||
error: transmute from a `char` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:10:31
|
||||
|
|
||||
LL | let _: *const usize = std::mem::transmute('x');
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: `char` (32 bits)
|
||||
= note: target type: `*const usize` (64 bits)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
|
||||
error: transmute from a `char` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:12:29
|
||||
|
|
||||
LL | let _: *mut usize = std::mem::transmute('x');
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: `char` (32 bits)
|
||||
= note: target type: `*mut usize` (64 bits)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0512`.
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ fn issue11075() {
|
|||
stringify!($e)
|
||||
};
|
||||
}
|
||||
#[allow(clippy::never_loop)]
|
||||
for _string in [repro!(true), repro!(null)] {
|
||||
unimplemented!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ fn issue11075() {
|
|||
stringify!($e)
|
||||
};
|
||||
}
|
||||
#[allow(clippy::never_loop)]
|
||||
for _string in vec![repro!(true), repro!(null)] {
|
||||
unimplemented!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,31 +86,31 @@ LL | for _ in vec![1, 2, 3] {}
|
|||
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
|
||||
|
||||
error: useless use of `vec!`
|
||||
--> $DIR/vec.rs:123:20
|
||||
--> $DIR/vec.rs:124:20
|
||||
|
|
||||
LL | for _string in vec![repro!(true), repro!(null)] {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]`
|
||||
|
||||
error: useless use of `vec!`
|
||||
--> $DIR/vec.rs:140:18
|
||||
--> $DIR/vec.rs:141:18
|
||||
|
|
||||
LL | in_macro!(1, vec![1, 2], vec![1; 2]);
|
||||
| ^^^^^^^^^^ help: you can use an array directly: `[1, 2]`
|
||||
|
||||
error: useless use of `vec!`
|
||||
--> $DIR/vec.rs:140:30
|
||||
--> $DIR/vec.rs:141:30
|
||||
|
|
||||
LL | in_macro!(1, vec![1, 2], vec![1; 2]);
|
||||
| ^^^^^^^^^^ help: you can use an array directly: `[1; 2]`
|
||||
|
||||
error: useless use of `vec!`
|
||||
--> $DIR/vec.rs:159:14
|
||||
--> $DIR/vec.rs:160:14
|
||||
|
|
||||
LL | for a in vec![1, 2, 3] {
|
||||
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
|
||||
|
||||
error: useless use of `vec!`
|
||||
--> $DIR/vec.rs:163:14
|
||||
--> $DIR/vec.rs:164:14
|
||||
|
|
||||
LL | for a in vec![String::new(), String::new()] {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
|
||||
|
|
|
|||
|
|
@ -2,10 +2,15 @@ error: unnecessary raw string literal
|
|||
--> $DIR/write_literal_2.rs:13:24
|
||||
|
|
||||
LL | writeln!(v, r"{}", r"{hello}");
|
||||
| ^^^^^^^^^^ help: try: `"{hello}"`
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::needless-raw-strings` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_raw_strings)]`
|
||||
help: try
|
||||
|
|
||||
LL - writeln!(v, r"{}", r"{hello}");
|
||||
LL + writeln!(v, r"{}", "{hello}");
|
||||
|
|
||||
|
||||
error: literal with an empty format string
|
||||
--> $DIR/write_literal_2.rs:10:23
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue