-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remaining functions from std::ptr.
- Loading branch information
Showing
5 changed files
with
259 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,49 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0) }; | ||
unsafe { | ||
let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); | ||
let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); | ||
|
||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0) }; | ||
let _slice: &[usize] = std::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); | ||
|
||
std::ptr::copy::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ||
std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ||
|
||
std::ptr::copy_nonoverlapping::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ||
std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ||
|
||
struct A; // zero sized struct | ||
assert_eq!(std::mem::size_of::<A>(), 0); | ||
|
||
let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); | ||
let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); | ||
|
||
let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); | ||
let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); | ||
|
||
let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); | ||
let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); | ||
|
||
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()); | ||
|
||
std::ptr::swap_nonoverlapping::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); | ||
std::ptr::swap_nonoverlapping::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); | ||
|
||
std::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); | ||
|
||
std::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); | ||
|
||
std::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); | ||
|
||
std::ptr::write_bytes::<usize>(core::ptr::NonNull::dangling().as_ptr(), 42, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,49 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null_mut(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null_mut(), 0) }; | ||
unsafe { | ||
let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); | ||
let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); | ||
|
||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0) }; | ||
let _slice: &[usize] = unsafe { std::slice::from_raw_parts_mut(core::ptr::null_mut(), 0) }; | ||
let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); | ||
|
||
std::ptr::copy::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ||
std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ||
|
||
std::ptr::copy_nonoverlapping::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ||
std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ||
|
||
struct A; // zero sized struct | ||
assert_eq!(std::mem::size_of::<A>(), 0); | ||
|
||
let _a: A = std::ptr::read(std::ptr::null()); | ||
let _a: A = std::ptr::read(std::ptr::null_mut()); | ||
|
||
let _a: A = std::ptr::read_unaligned(std::ptr::null()); | ||
let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); | ||
|
||
let _a: A = std::ptr::read_volatile(std::ptr::null()); | ||
let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); | ||
|
||
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()); | ||
|
||
std::ptr::swap_nonoverlapping::<A>(std::ptr::null_mut(), &mut A, 0); | ||
std::ptr::swap_nonoverlapping::<A>(&mut A, std::ptr::null_mut(), 0); | ||
|
||
std::ptr::write(std::ptr::null_mut(), A); | ||
|
||
std::ptr::write_unaligned(std::ptr::null_mut(), A); | ||
|
||
std::ptr::write_volatile(std::ptr::null_mut(), A); | ||
|
||
std::ptr::write_bytes::<usize>(std::ptr::null_mut(), 42, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,130 @@ | ||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:4:64 | ||
--> $DIR/invalid_null_ptr_usage.rs:5:59 | ||
| | ||
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null(), 0) }; | ||
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); | ||
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
| | ||
= note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default | ||
|
||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:5:64 | ||
--> $DIR/invalid_null_ptr_usage.rs:6:59 | ||
| | ||
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null(), 0) }; | ||
| ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
LL | let _slice: &[usize] = std::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 | ||
--> $DIR/invalid_null_ptr_usage.rs:6:64 | ||
--> $DIR/invalid_null_ptr_usage.rs:8:63 | ||
| | ||
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(std::ptr::null_mut(), 0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
LL | let _slice: &[usize] = std::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 | ||
--> $DIR/invalid_null_ptr_usage.rs:7:64 | ||
--> $DIR/invalid_null_ptr_usage.rs:19:36 | ||
| | ||
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts(core::ptr::null_mut(), 0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
LL | let _a: A = std::ptr::read(std::ptr::null()); | ||
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
|
||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:9:68 | ||
--> $DIR/invalid_null_ptr_usage.rs:20:36 | ||
| | ||
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
LL | let _a: A = std::ptr::read(std::ptr::null_mut()); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
|
||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:10:68 | ||
--> $DIR/invalid_null_ptr_usage.rs:22:46 | ||
| | ||
LL | let _slice: &[usize] = unsafe { std::slice::from_raw_parts_mut(core::ptr::null_mut(), 0) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
LL | let _a: A = std::ptr::read_unaligned(std::ptr::null()); | ||
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
|
||
error: aborting due to 6 previous errors | ||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:23:46 | ||
| | ||
LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
|
||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:25:45 | ||
| | ||
LL | let _a: A = std::ptr::read_volatile(std::ptr::null()); | ||
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
|
||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:26:45 | ||
| | ||
LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` | ||
|
||
error: pointer must be non-null | ||
--> $DIR/invalid_null_ptr_usage.rs:28:39 | ||
| | ||
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 | ||
--> $DIR/invalid_null_ptr_usage.rs:30: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:31: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:33: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:35: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:36: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:38: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:39: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:41: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:43: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:45: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 | ||
--> $DIR/invalid_null_ptr_usage.rs:47: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 21 previous errors | ||
|