summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
new file mode 100644
index 000000000..04ee985c0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
@@ -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() {}