summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/transmute_null_to_fn.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/transmute_null_to_fn.rs')
-rw-r--r--src/tools/clippy/tests/ui/transmute_null_to_fn.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/transmute_null_to_fn.rs b/src/tools/clippy/tests/ui/transmute_null_to_fn.rs
new file mode 100644
index 000000000..b3ea3d903
--- /dev/null
+++ b/src/tools/clippy/tests/ui/transmute_null_to_fn.rs
@@ -0,0 +1,28 @@
+#![allow(dead_code)]
+#![warn(clippy::transmute_null_to_fn)]
+#![allow(clippy::zero_ptr)]
+
+// Easy to lint because these only span one line.
+fn one_liners() {
+ unsafe {
+ let _: fn() = std::mem::transmute(0 as *const ());
+ let _: fn() = std::mem::transmute(std::ptr::null::<()>());
+ }
+}
+
+pub const ZPTR: *const usize = 0 as *const _;
+pub const NOT_ZPTR: *const usize = 1 as *const _;
+
+fn transmute_const() {
+ unsafe {
+ // Should raise a lint.
+ let _: fn() = std::mem::transmute(ZPTR);
+ // Should NOT raise a lint.
+ let _: fn() = std::mem::transmute(NOT_ZPTR);
+ }
+}
+
+fn main() {
+ one_liners();
+ transmute_const();
+}