Skip to content

Commit 7b1f9d8

Browse files
committed
Update tests files for manual_dangling_ptr lint
1 parent de3aa1d commit 7b1f9d8

5 files changed

+12
-10
lines changed

tests/ui/transmute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn useless() {
5959
let _: *const usize = std::mem::transmute(5_isize);
6060
//~^ useless_transmute
6161

62-
let _ = 5_isize as *const usize;
62+
let _ = std::ptr::dangling::<usize>();
6363

6464
let _: *const usize = std::mem::transmute(1 + 1usize);
6565
//~^ useless_transmute

tests/ui/transmute_null_to_fn.rs

Lines changed: 1 addition & 0 deletions
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() {

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:11:23
12+
--> tests/ui/transmute_null_to_fn.rs:12: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:22:23
20+
--> tests/ui/transmute_null_to_fn.rs:23: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:32:23
28+
--> tests/ui/transmute_null_to_fn.rs:33: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:35:23
36+
--> tests/ui/transmute_null_to_fn.rs:36: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:38:23
44+
--> tests/ui/transmute_null_to_fn.rs:39: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: 1 addition & 0 deletions
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() {

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)