Skip to content

Commit 0282ff8

Browse files
committed
Add test for ptr::null_mut.
1 parent cc64934 commit 0282ff8

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

tests/ui/invalid_null_ptr_usage.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
fn main() {
44
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) };
55
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) };
6+
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) };
7+
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) };
68
}

tests/ui/invalid_null_ptr_usage.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
fn main() {
44
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null(), 0) };
55
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null(), 0) };
6+
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null_mut(), 0) };
7+
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null_mut(), 0) };
68
}

tests/ui/invalid_null_ptr_usage.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,17 @@ error: pointer must be non-null
1212
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null(), 0) };
1313
| ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
1414

15-
error: aborting due to 2 previous errors
15+
error: pointer must be non-null
16+
--> $DIR/invalid_null_ptr_usage.rs:6:64
17+
|
18+
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null_mut(), 0) };
19+
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
20+
21+
error: pointer must be non-null
22+
--> $DIR/invalid_null_ptr_usage.rs:7:64
23+
|
24+
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null_mut(), 0) };
25+
| ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
26+
27+
error: aborting due to 4 previous errors
1628

0 commit comments

Comments
 (0)