Make use of ptr::null(_mut) instead of casting zero#61864
Make use of ptr::null(_mut) instead of casting zero#61864bors merged 1 commit intorust-lang:masterfrom
ptr::null(_mut) instead of casting zero#61864Conversation
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
3666052 to
b652879
Compare
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/test/ui/fat-ptr-cast.rs
Outdated
There was a problem hiding this comment.
Might be best to leave this one unchanged if it breaks the test.
There was a problem hiding this comment.
Okey thanks! I removed it.
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
Mark as ready for review as I don't know what to do with #61864 (comment) . |
92db647 to
ae0c043
Compare
ptr::{null,null_mut} instead of casting zeroptr::null(mut) instead of casting zero
ptr::null(mut) instead of casting zeroptr::null(_mut) instead of casting zero
|
The build is green. |
|
@bors r+ |
|
📌 Commit 7d69d4c has been approved by |
Make use of `ptr::null(_mut)` instead of casting zero
There are few places that I don't replace the zero casting pointer with `ptr::null`
or `ptr::null_mut`:
```bash
% git grep -E '[ ([{]0 as \*'
src/libcore/ptr/mod.rs:216:pub const fn null<T>() -> *const T { 0 as *const T }
src/libcore/ptr/mod.rs:231:pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
src/test/run-pass/consts/const-cast-ptr-int.rs:12:static a: TestStruct = TestStruct{x: 0 as *const u8};
src/test/ui/issues/issue-45730.rs:5: let x: *const _ = 0 as *const _; //~ ERROR cannot cast
src/test/ui/issues/issue-45730.rs:8: let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast
src/test/ui/issues/issue-45730.stderr:14:LL | let x: *const _ = 0 as *const _;
src/test/ui/issues/issue-45730.stderr:24:LL | let x = 0 as *const i32 as *const _ as *mut _;
src/test/ui/lint/lint-forbid-internal-unsafe.rs:15: println!("{}", evil!(*(0 as *const u8)));
src/test/ui/order-dependent-cast-inference.rs:5: let mut y = 0 as *const _;
src/test/ui/order-dependent-cast-inference.stderr:4:LL | let mut y = 0 as *const _;
```
r? @sfackler
|
☀️ Test successful - checks-travis, status-appveyor |
Tested on commit rust-lang/rust@a6a8f6c. Direct link to PR: <rust-lang/rust#61864> 🎉 rls on linux: test-fail → test-pass (cc @Xanewok, @rust-lang/infra).
| } | ||
|
|
||
| fn main() { | ||
| let _foo: *mut Lorem = 0 as *mut _; // no error here |
…crum Restore a test that was intended to test `as` cast to ptr This test was changed in rust-lang#61864, but the original bug rust-lang#46365 was about casts so I doubt the changed test still even tests what this was intended to test. Let's restore the original test.
…crum Restore a test that was intended to test `as` cast to ptr This test was changed in rust-lang#61864, but the original bug rust-lang#46365 was about casts so I doubt the changed test still even tests what this was intended to test. Let's restore the original test.
There are few places that I don't replace the zero casting pointer with
ptr::nullor
ptr::null_mut:r? @sfackler