Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
| sym::ptr_read_unaligned
| sym::ptr_read_volatile
| sym::ptr_replace
| sym::ptr_slice_from_raw_parts
| sym::ptr_slice_from_raw_parts_mut
| sym::ptr_write
| sym::ptr_write_bytes
| sym::ptr_write_unaligned
Expand Down
5 changes: 0 additions & 5 deletions tests/ui/invalid_null_ptr_usage.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ fn main() {

let _a: A = std::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A);

let _slice: *const [usize] = std::ptr::slice_from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0);

let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0);

std::ptr::swap::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A);
std::ptr::swap::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr());

Expand Down
5 changes: 0 additions & 5 deletions tests/ui/invalid_null_ptr_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ fn main() {

let _a: A = std::ptr::replace(std::ptr::null_mut(), A);

let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0);

let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);

std::ptr::swap::<A>(std::ptr::null_mut(), &mut A);
std::ptr::swap::<A>(&mut A, std::ptr::null_mut());

Expand Down
36 changes: 9 additions & 27 deletions tests/ui/invalid_null_ptr_usage.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -85,70 +85,52 @@ LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:28:69
|
LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0);
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:29:69
|
LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:31:73
|
LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:33:29
--> tests/ui/invalid_null_ptr_usage.rs:28:29
|
LL | std::ptr::swap::<A>(std::ptr::null_mut(), &mut A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:34:37
--> tests/ui/invalid_null_ptr_usage.rs:29:37
|
LL | std::ptr::swap::<A>(&mut A, std::ptr::null_mut());
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:36:44
--> tests/ui/invalid_null_ptr_usage.rs:31:44
|
LL | std::ptr::swap_nonoverlapping::<A>(std::ptr::null_mut(), &mut A, 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:37:52
--> tests/ui/invalid_null_ptr_usage.rs:32:52
|
LL | std::ptr::swap_nonoverlapping::<A>(&mut A, std::ptr::null_mut(), 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:39:25
--> tests/ui/invalid_null_ptr_usage.rs:34:25
|
LL | std::ptr::write(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:41:35
--> tests/ui/invalid_null_ptr_usage.rs:36:35
|
LL | std::ptr::write_unaligned(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:43:34
--> tests/ui/invalid_null_ptr_usage.rs:38:34
|
LL | std::ptr::write_volatile(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:45:40
--> tests/ui/invalid_null_ptr_usage.rs:40:40
|
LL | std::ptr::write_bytes::<usize>(std::ptr::null_mut(), 42, 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`

error: aborting due to 25 previous errors
error: aborting due to 22 previous errors