Skip to content

Commit 4d34995

Browse files
committed
allow lint in transmute_null tests
1 parent 955fbeb commit 4d34995

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

tests/ui/transmute_null_to_fn.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(dead_code)]
22
#![warn(clippy::transmute_null_to_fn)]
33
#![allow(clippy::zero_ptr, clippy::missing_transmute_annotations)]
4+
#![allow(clippy::manual_dangling_ptr)]
45

56
// Easy to lint because these only span one line.
67
fn one_liners() {
@@ -14,7 +15,7 @@ fn one_liners() {
1415
}
1516

1617
pub const ZPTR: *const usize = 0 as *const _;
17-
pub const NOT_ZPTR: *const usize = std::ptr::dangling();
18+
pub const NOT_ZPTR: *const usize = 1 as *const _;
1819

1920
fn transmute_const() {
2021
unsafe {

tests/ui/transmute_null_to_fn.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: transmuting a known null pointer into a function pointer
2-
--> tests/ui/transmute_null_to_fn.rs:8:23
2+
--> tests/ui/transmute_null_to_fn.rs:9:23
33
|
44
LL | let _: fn() = std::mem::transmute(0 as *const ());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior

tests/ui/transmuting_null.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![allow(clippy::zero_ptr)]
44
#![allow(clippy::transmute_ptr_to_ref)]
55
#![allow(clippy::eq_op, clippy::missing_transmute_annotations)]
6+
#![allow(clippy::manual_dangling_ptr)]
67

78
// Easy to lint because these only span one line.
89
fn one_liners() {
@@ -16,7 +17,7 @@ fn one_liners() {
1617
}
1718

1819
pub const ZPTR: *const usize = 0 as *const _;
19-
pub const NOT_ZPTR: *const usize = std::ptr::dangling();
20+
pub const NOT_ZPTR: *const usize = 1 as *const _;
2021

2122
fn transmute_const() {
2223
unsafe {

tests/ui/transmuting_null.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: transmuting a known null pointer into a reference
2-
--> tests/ui/transmuting_null.rs:10:23
2+
--> tests/ui/transmuting_null.rs:11:23
33
|
44
LL | let _: &u64 = std::mem::transmute(0 as *const u64);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,13 +8,13 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64);
88
= help: to override `-D warnings` add `#[allow(clippy::transmuting_null)]`
99

1010
error: transmuting a known null pointer into a reference
11-
--> tests/ui/transmuting_null.rs:13:23
11+
--> tests/ui/transmuting_null.rs:14:23
1212
|
1313
LL | let _: &u64 = std::mem::transmute(std::ptr::null::<u64>());
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: transmuting a known null pointer into a reference
17-
--> tests/ui/transmuting_null.rs:24:23
17+
--> tests/ui/transmuting_null.rs:25:23
1818
|
1919
LL | let _: &u64 = std::mem::transmute(ZPTR);
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)