chore: fix and split some ui tests on 32bit system
This commit is contained in:
parent
94aa0398c2
commit
142b289a51
@ -24,6 +24,7 @@ declare_clippy_lint! {
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// # #[cfg(target_pointer_width = "64")]
|
||||
/// #[repr(usize)]
|
||||
/// enum NonPortable {
|
||||
/// X = 0x1_0000_0000,
|
||||
|
@ -1,3 +1,4 @@
|
||||
// ignore-32bit
|
||||
#[warn(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: casting isize to i8 may truncate the value
|
||||
--> $DIR/cast_size.rs:11:5
|
||||
--> $DIR/cast_size.rs:12:5
|
||||
|
|
||||
LL | 1isize as i8;
|
||||
| ^^^^^^^^^^^^
|
||||
@ -7,7 +7,7 @@ LL | 1isize as i8;
|
||||
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
|
||||
|
||||
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:14:5
|
||||
--> $DIR/cast_size.rs:15:5
|
||||
|
|
||||
LL | x0 as f64;
|
||||
| ^^^^^^^^^
|
||||
@ -15,49 +15,49 @@ LL | x0 as f64;
|
||||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:15:5
|
||||
--> $DIR/cast_size.rs:16:5
|
||||
|
|
||||
LL | x1 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:16:5
|
||||
--> $DIR/cast_size.rs:17: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:17:5
|
||||
--> $DIR/cast_size.rs:18: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:18:5
|
||||
--> $DIR/cast_size.rs:19:5
|
||||
|
|
||||
LL | 1isize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:19:5
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
|
|
||||
LL | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
|
|
||||
LL | 1usize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -65,49 +65,49 @@ LL | 1usize as i32;
|
||||
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
|
||||
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
|
|
||||
LL | 1i64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
LL | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
--> $DIR/cast_size.rs:26: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:26:5
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
|
|
||||
LL | 1u64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
--> $DIR/cast_size.rs:28: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:32:5
|
||||
--> $DIR/cast_size.rs:33: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:33:5
|
||||
--> $DIR/cast_size.rs:34:5
|
||||
|
|
||||
LL | 9_999_999_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
35
tests/ui/cast_size_32bit.rs
Normal file
35
tests/ui/cast_size_32bit.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// 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;
|
||||
let x0 = 1isize;
|
||||
let x1 = 1usize;
|
||||
x0 as f64;
|
||||
x1 as f64;
|
||||
x0 as f32;
|
||||
x1 as f32;
|
||||
1isize as i32;
|
||||
1isize as u32;
|
||||
1usize as u32;
|
||||
1usize as i32;
|
||||
// Casting to *size
|
||||
1i64 as isize;
|
||||
1i64 as usize;
|
||||
1u64 as isize;
|
||||
1u64 as usize;
|
||||
1u32 as isize;
|
||||
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;
|
||||
3_999_999_999usize as f64;
|
||||
}
|
132
tests/ui/cast_size_32bit.stderr
Normal file
132
tests/ui/cast_size_32bit.stderr
Normal file
@ -0,0 +1,132 @@
|
||||
error: casting isize to i8 may truncate the value
|
||||
--> $DIR/cast_size_32bit.rs:12:5
|
||||
|
|
||||
LL | 1isize as i8;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
|
||||
|
||||
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
|
||||
|
|
||||
LL | x0 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting isize to f64 may become silently lossy if you later change the type
|
||||
--> $DIR/cast_size_32bit.rs:15:5
|
||||
|
|
||||
LL | x0 as f64;
|
||||
| ^^^^^^^^^ help: try: `f64::from(x0)`
|
||||
|
|
||||
= note: `-D clippy::cast-lossless` 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
|
||||
|
|
||||
LL | x1 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting usize to f64 may become silently lossy if you later change the type
|
||||
--> $DIR/cast_size_32bit.rs:16:5
|
||||
|
|
||||
LL | x1 as f64;
|
||||
| ^^^^^^^^^ help: try: `f64::from(x1)`
|
||||
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
LL | 1isize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:20:5
|
||||
|
|
||||
LL | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:21:5
|
||||
|
|
||||
LL | 1usize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:22:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:22:5
|
||||
|
|
||||
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
|
||||
|
|
||||
LL | 1i64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:25:5
|
||||
|
|
||||
LL | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:26:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:26: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
|
||||
|
|
||||
LL | 1u64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size_32bit.rs:28: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
|
||||
|
|
||||
LL | 999_999_999 as f32;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting integer literal to f64 is unnecessary
|
||||
--> $DIR/cast_size_32bit.rs:34:5
|
||||
|
|
||||
LL | 3_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `3999999999_f64`
|
||||
|
|
||||
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 20 previous errors
|
||||
|
@ -1,4 +1,4 @@
|
||||
// only-64bit
|
||||
// ignore-32bit
|
||||
|
||||
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
|
||||
|
||||
|
55
tests/ui/fn_to_numeric_cast_32bit.rs
Normal file
55
tests/ui/fn_to_numeric_cast_32bit.rs
Normal file
@ -0,0 +1,55 @@
|
||||
// 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;
|
||||
let _ = foo as i16;
|
||||
let _ = foo as i32;
|
||||
let _ = foo as i64;
|
||||
let _ = foo as i128;
|
||||
let _ = foo as isize;
|
||||
|
||||
let _ = foo as u8;
|
||||
let _ = foo as u16;
|
||||
let _ = foo as u32;
|
||||
let _ = foo as u64;
|
||||
let _ = foo as 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;
|
||||
let _ = abc as i16;
|
||||
let _ = abc as i32;
|
||||
let _ = abc as i64;
|
||||
let _ = abc as i128;
|
||||
let _ = abc as isize;
|
||||
|
||||
let _ = abc as u8;
|
||||
let _ = abc as u16;
|
||||
let _ = abc as u32;
|
||||
let _ = abc as u64;
|
||||
let _ = abc as 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
|
||||
}
|
||||
|
||||
fn main() {}
|
144
tests/ui/fn_to_numeric_cast_32bit.stderr
Normal file
144
tests/ui/fn_to_numeric_cast_32bit.stderr
Normal file
@ -0,0 +1,144 @@
|
||||
error: casting function pointer `foo` to `i8`, which truncates the value
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:10:13
|
||||
|
|
||||
LL | let _ = foo as i8;
|
||||
| ^^^^^^^^^ help: try: `foo as usize`
|
||||
|
|
||||
= 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
|
||||
|
|
||||
LL | let _ = foo as i16;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `i32`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:12:13
|
||||
|
|
||||
LL | let _ = foo as i32;
|
||||
| ^^^^^^^^^^ 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_32bit.rs:13: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
|
||||
|
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
LL | let _ = foo as u16;
|
||||
| ^^^^^^^^^^ help: try: `foo as usize`
|
||||
|
||||
error: casting function pointer `foo` to `u32`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.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_32bit.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_32bit.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_32bit.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_32bit.rs:35:13
|
||||
|
|
||||
LL | let _ = abc as i16;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `i32`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.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_32bit.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_32bit.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_32bit.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_32bit.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_32bit.rs:42:13
|
||||
|
|
||||
LL | let _ = abc as u16;
|
||||
| ^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `abc` to `u32`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.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_32bit.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_32bit.rs:45:13
|
||||
|
|
||||
LL | let _ = abc as u128;
|
||||
| ^^^^^^^^^^^ help: try: `abc as usize`
|
||||
|
||||
error: casting function pointer `f` to `i32`
|
||||
--> $DIR/fn_to_numeric_cast_32bit.rs:52:5
|
||||
|
|
||||
LL | f as i32
|
||||
| ^^^^^^^^ help: try: `f as usize`
|
||||
|
||||
error: aborting due to 23 previous errors
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#[warn(clippy::large_digit_groups)]
|
||||
#[allow(unused_variables)]
|
||||
#![warn(clippy::large_digit_groups)]
|
||||
|
||||
fn main() {
|
||||
macro_rules! mac {
|
||||
() => {
|
||||
@ -8,7 +8,7 @@ fn main() {
|
||||
};
|
||||
}
|
||||
|
||||
let good = (
|
||||
let _good = (
|
||||
0b1011_i64,
|
||||
0o1_234_u32,
|
||||
0x1_234_567,
|
||||
@ -18,15 +18,14 @@ fn main() {
|
||||
1_234.123_f32,
|
||||
1.123_4_f32,
|
||||
);
|
||||
let bad = (
|
||||
let _bad = (
|
||||
0b11_0110_i64,
|
||||
0x0123_4567_8901_usize,
|
||||
0xdead_beef_usize,
|
||||
123_456_f32,
|
||||
123_456.12_f32,
|
||||
123_456.123_45_f64,
|
||||
123_456.123_456_f64,
|
||||
);
|
||||
|
||||
// Ignore literals in macros
|
||||
let _ = mac!();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#[warn(clippy::large_digit_groups)]
|
||||
#[allow(unused_variables)]
|
||||
#![warn(clippy::large_digit_groups)]
|
||||
|
||||
fn main() {
|
||||
macro_rules! mac {
|
||||
() => {
|
||||
@ -8,7 +8,7 @@ fn main() {
|
||||
};
|
||||
}
|
||||
|
||||
let good = (
|
||||
let _good = (
|
||||
0b1011_i64,
|
||||
0o1_234_u32,
|
||||
0x1_234_567,
|
||||
@ -18,15 +18,14 @@ fn main() {
|
||||
1_234.123_f32,
|
||||
1.123_4_f32,
|
||||
);
|
||||
let bad = (
|
||||
let _bad = (
|
||||
0b1_10110_i64,
|
||||
0x1_23456_78901_usize,
|
||||
0xd_e_adbee_f_usize,
|
||||
1_23456_f32,
|
||||
1_23456.12_f32,
|
||||
1_23456.12345_f64,
|
||||
1_23456.12345_6_f64,
|
||||
);
|
||||
|
||||
// Ignore literals in macros
|
||||
let _ = mac!();
|
||||
}
|
||||
|
@ -6,11 +6,13 @@ LL | 0b1_10110_i64,
|
||||
|
|
||||
= note: `-D clippy::large-digit-groups` implied by `-D warnings`
|
||||
|
||||
error: digit groups should be smaller
|
||||
error: digits grouped inconsistently by underscores
|
||||
--> $DIR/large_digit_groups.rs:23:9
|
||||
|
|
||||
LL | 0x1_23456_78901_usize,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize`
|
||||
LL | 0xd_e_adbee_f_usize,
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize`
|
||||
|
|
||||
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`
|
||||
|
||||
error: digit groups should be smaller
|
||||
--> $DIR/large_digit_groups.rs:24:9
|
||||
|
@ -1,6 +1,6 @@
|
||||
//ignore-x86_64
|
||||
// ignore-64bit
|
||||
|
||||
#[warn(wrong_transmute)]
|
||||
#[warn(clippy::wrong_transmute)]
|
||||
fn main() {
|
||||
unsafe {
|
||||
let _: *const usize = std::mem::transmute(6.0f32);
|
||||
|
28
tests/ui/transmute_32bit.stderr
Normal file
28
tests/ui/transmute_32bit.stderr
Normal file
@ -0,0 +1,28 @@
|
||||
error: transmute from a `f32` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:6:31
|
||||
|
|
||||
LL | let _: *const usize = std::mem::transmute(6.0f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::wrong-transmute` implied by `-D warnings`
|
||||
|
||||
error: transmute from a `f32` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:8:29
|
||||
|
|
||||
LL | let _: *mut usize = std::mem::transmute(6.0f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: transmute from a `char` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:10:31
|
||||
|
|
||||
LL | let _: *const usize = std::mem::transmute('x');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: transmute from a `char` to a pointer
|
||||
--> $DIR/transmute_32bit.rs:12:29
|
||||
|
|
||||
LL | let _: *mut usize = std::mem::transmute('x');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
@ -1,5 +1,4 @@
|
||||
//ignore-x86
|
||||
//no-ignore-x86_64
|
||||
// ignore-32bit
|
||||
|
||||
#[warn(clippy::wrong_transmute)]
|
||||
fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: transmute from a `f64` to a pointer
|
||||
--> $DIR/transmute_64bit.rs:7:31
|
||||
--> $DIR/transmute_64bit.rs:6:31
|
||||
|
|
||||
LL | let _: *const usize = std::mem::transmute(6.0f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -7,7 +7,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64);
|
||||
= note: `-D clippy::wrong-transmute` implied by `-D warnings`
|
||||
|
||||
error: transmute from a `f64` to a pointer
|
||||
--> $DIR/transmute_64bit.rs:9:29
|
||||
--> $DIR/transmute_64bit.rs:8:29
|
||||
|
|
||||
LL | let _: *mut usize = std::mem::transmute(6.0f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,5 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::unreadable_literal)]
|
||||
|
||||
struct Foo(u64);
|
||||
|
||||
macro_rules! foo {
|
||||
@ -8,10 +10,8 @@ macro_rules! foo {
|
||||
};
|
||||
}
|
||||
|
||||
#[warn(clippy::unreadable_literal)]
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
let good = (
|
||||
let _good = (
|
||||
0b1011_i64,
|
||||
0o1_234_u32,
|
||||
0x1_234_567,
|
||||
@ -22,14 +22,14 @@ fn main() {
|
||||
1_234.123_f32,
|
||||
1.123_4_f32,
|
||||
);
|
||||
let bad = (0b11_0110_i64, 0x0123_4567_8901_usize, 123_456_f32, 1.234_567_f32);
|
||||
let good_sci = 1.1234e1;
|
||||
let bad_sci = 1.123_456e1;
|
||||
let _bad = (0b11_0110_i64, 0xcafe_babe_usize, 123_456_f32, 1.234_567_f32);
|
||||
let _good_sci = 1.1234e1;
|
||||
let _bad_sci = 1.123_456e1;
|
||||
|
||||
let fail9 = 0x00ab_cdef;
|
||||
let fail10: u32 = 0xBAFE_BAFE;
|
||||
let fail11 = 0x0abc_deff;
|
||||
let fail12: i128 = 0x00ab_cabc_abca_bcab_cabc;
|
||||
let _fail9 = 0x00ab_cdef;
|
||||
let _fail10: u32 = 0xBAFE_BAFE;
|
||||
let _fail11 = 0x0abc_deff;
|
||||
let _fail12: i128 = 0x00ab_cabc_abca_bcab_cabc;
|
||||
|
||||
let _ = foo!();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::unreadable_literal)]
|
||||
|
||||
struct Foo(u64);
|
||||
|
||||
macro_rules! foo {
|
||||
@ -8,10 +10,8 @@ macro_rules! foo {
|
||||
};
|
||||
}
|
||||
|
||||
#[warn(clippy::unreadable_literal)]
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
let good = (
|
||||
let _good = (
|
||||
0b1011_i64,
|
||||
0o1_234_u32,
|
||||
0x1_234_567,
|
||||
@ -22,14 +22,14 @@ fn main() {
|
||||
1_234.123_f32,
|
||||
1.123_4_f32,
|
||||
);
|
||||
let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
|
||||
let good_sci = 1.1234e1;
|
||||
let bad_sci = 1.123456e1;
|
||||
let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32);
|
||||
let _good_sci = 1.1234e1;
|
||||
let _bad_sci = 1.123456e1;
|
||||
|
||||
let fail9 = 0xabcdef;
|
||||
let fail10: u32 = 0xBAFEBAFE;
|
||||
let fail11 = 0xabcdeff;
|
||||
let fail12: i128 = 0xabcabcabcabcabcabc;
|
||||
let _fail9 = 0xabcdef;
|
||||
let _fail10: u32 = 0xBAFEBAFE;
|
||||
let _fail11 = 0xabcdeff;
|
||||
let _fail12: i128 = 0xabcabcabcabcabcabc;
|
||||
|
||||
let _ = foo!();
|
||||
}
|
||||
|
@ -1,58 +1,58 @@
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:25:16
|
||||
--> $DIR/unreadable_literal.rs:25:17
|
||||
|
|
||||
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
|
||||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
|
||||
|
|
||||
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:25:30
|
||||
--> $DIR/unreadable_literal.rs:25:31
|
||||
|
|
||||
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize`
|
||||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^^^^^ help: consider: `0xcafe_babe_usize`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:25:51
|
||||
--> $DIR/unreadable_literal.rs:25:49
|
||||
|
|
||||
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^ help: consider: `123_456_f32`
|
||||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^ help: consider: `123_456_f32`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:25:63
|
||||
--> $DIR/unreadable_literal.rs:25:61
|
||||
|
|
||||
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^ help: consider: `1.234_567_f32`
|
||||
LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^ help: consider: `1.234_567_f32`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:27:19
|
||||
--> $DIR/unreadable_literal.rs:27:20
|
||||
|
|
||||
LL | let bad_sci = 1.123456e1;
|
||||
| ^^^^^^^^^^ help: consider: `1.123_456e1`
|
||||
LL | let _bad_sci = 1.123456e1;
|
||||
| ^^^^^^^^^^ help: consider: `1.123_456e1`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:29:17
|
||||
--> $DIR/unreadable_literal.rs:29:18
|
||||
|
|
||||
LL | let fail9 = 0xabcdef;
|
||||
| ^^^^^^^^ help: consider: `0x00ab_cdef`
|
||||
LL | let _fail9 = 0xabcdef;
|
||||
| ^^^^^^^^ help: consider: `0x00ab_cdef`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:30:23
|
||||
--> $DIR/unreadable_literal.rs:30:24
|
||||
|
|
||||
LL | let fail10: u32 = 0xBAFEBAFE;
|
||||
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE`
|
||||
LL | let _fail10: u32 = 0xBAFEBAFE;
|
||||
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:31:18
|
||||
--> $DIR/unreadable_literal.rs:31:19
|
||||
|
|
||||
LL | let fail11 = 0xabcdeff;
|
||||
| ^^^^^^^^^ help: consider: `0x0abc_deff`
|
||||
LL | let _fail11 = 0xabcdeff;
|
||||
| ^^^^^^^^^ help: consider: `0x0abc_deff`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:32:24
|
||||
--> $DIR/unreadable_literal.rs:32:25
|
||||
|
|
||||
LL | let fail12: i128 = 0xabcabcabcabcabcabc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc`
|
||||
LL | let _fail12: i128 = 0xabcabcabcabcabcabc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user