Skip to content

Commit 108b540

Browse files
committed
allow lint in transmute_null tests
1 parent 0006811 commit 108b540

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
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() {
@@ -13,7 +14,7 @@ fn one_liners() {
1314
}
1415

1516
pub const ZPTR: *const usize = 0 as *const _;
16-
pub const NOT_ZPTR: *const usize = std::ptr::dangling();
17+
pub const NOT_ZPTR: *const usize = 1 as *const _;
1718

1819
fn transmute_const() {
1920
unsafe {

tests/ui/transmute_null_to_fn.stderr

Lines changed: 6 additions & 6 deletions
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
@@ -9,39 +9,39 @@ LL | let _: fn() = std::mem::transmute(0 as *const ());
99
= help: to override `-D warnings` add `#[allow(clippy::transmute_null_to_fn)]`
1010

1111
error: transmuting a known null pointer into a function pointer
12-
--> tests/ui/transmute_null_to_fn.rs:10:23
12+
--> tests/ui/transmute_null_to_fn.rs:11:23
1313
|
1414
LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>());
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
1616
|
1717
= help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
1818

1919
error: transmuting a known null pointer into a function pointer
20-
--> tests/ui/transmute_null_to_fn.rs:21:23
20+
--> tests/ui/transmute_null_to_fn.rs:22:23
2121
|
2222
LL | let _: fn() = std::mem::transmute(ZPTR);
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
2424
|
2525
= help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
2626

2727
error: transmuting a known null pointer into a function pointer
28-
--> tests/ui/transmute_null_to_fn.rs:30:23
28+
--> tests/ui/transmute_null_to_fn.rs:31:23
2929
|
3030
LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ());
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
3232
|
3333
= help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
3434

3535
error: transmuting a known null pointer into a function pointer
36-
--> tests/ui/transmute_null_to_fn.rs:32:23
36+
--> tests/ui/transmute_null_to_fn.rs:33:23
3737
|
3838
LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8);
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
4040
|
4141
= help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
4242

4343
error: transmuting a known null pointer into a function pointer
44-
--> tests/ui/transmute_null_to_fn.rs:34:23
44+
--> tests/ui/transmute_null_to_fn.rs:35:23
4545
|
4646
LL | let _: fn() = std::mem::transmute(ZPTR as *const u8);
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)