blob: f53cbacdb3771f9deca08a70bd090d80cfd9ebca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
//@revisions: 32bit 64bit
//@[32bit]ignore-bitwidth: 64
//@[64bit]ignore-bitwidth: 32
//@no-rustfix
#![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;
//~^ fn_to_numeric_cast_with_truncation
let _ = foo as i16;
//~^ fn_to_numeric_cast_with_truncation
let _ = foo as i32;
//~[64bit]^ fn_to_numeric_cast_with_truncation
//~[32bit]^^ fn_to_numeric_cast
let _ = foo as i64;
//~^ fn_to_numeric_cast
let _ = foo as i128;
//~^ fn_to_numeric_cast
let _ = foo as isize;
//~^ fn_to_numeric_cast
let _ = foo as u8;
//~^ fn_to_numeric_cast_with_truncation
let _ = foo as u16;
//~^ fn_to_numeric_cast_with_truncation
let _ = foo as u32;
//~[64bit]^ fn_to_numeric_cast_with_truncation
//~[32bit]^^ fn_to_numeric_cast
let _ = foo as u64;
//~^ fn_to_numeric_cast
let _ = foo as u128;
//~^ fn_to_numeric_cast
// 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;
//~^ fn_to_numeric_cast_with_truncation
let _ = abc as i16;
//~^ fn_to_numeric_cast_with_truncation
let _ = abc as i32;
//~[64bit]^ fn_to_numeric_cast_with_truncation
//~[32bit]^^ fn_to_numeric_cast
let _ = abc as i64;
//~^ fn_to_numeric_cast
let _ = abc as i128;
//~^ fn_to_numeric_cast
let _ = abc as isize;
//~^ fn_to_numeric_cast
let _ = abc as u8;
//~^ fn_to_numeric_cast_with_truncation
let _ = abc as u16;
//~^ fn_to_numeric_cast_with_truncation
let _ = abc as u32;
//~[64bit]^ fn_to_numeric_cast_with_truncation
//~[32bit]^^ fn_to_numeric_cast
let _ = abc as u64;
//~^ fn_to_numeric_cast
let _ = abc as u128;
//~^ fn_to_numeric_cast
// 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
//~[64bit]^ fn_to_numeric_cast_with_truncation
//~[32bit]^^ fn_to_numeric_cast
}
fn main() {}
|