summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-06-18 05:16:26 +0000
committerbors <bors@rust-lang.org>2019-06-18 05:16:26 +0000
commita6a8f6c5b37597bf69178ee5cc6c185b7137f5d8 (patch)
tree6a337af65cf1c71cfe81bf552912e67f949b3d4c /src/bootstrap
parent704ab2ba10c4d878f879047cdac94a61751ce943 (diff)
parent7d69d4ced23c446d6af341e3f9dc031a302150fc (diff)
downloadrust-a6a8f6c5b37597bf69178ee5cc6c185b7137f5d8.tar.gz
rust-a6a8f6c5b37597bf69178ee5cc6c185b7137f5d8.zip
Auto merge of #61864 - lzutao:ptr-null, r=sfackler
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
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/job.rs9
-rw-r--r--src/bootstrap/util.rs2
2 files changed, 6 insertions, 5 deletions
diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs
index df492e0fdfd..6867d62a480 100644
--- a/src/bootstrap/job.rs
+++ b/src/bootstrap/job.rs
@@ -32,6 +32,7 @@
 use std::env;
 use std::io;
 use std::mem;
+use std::ptr;
 use crate::Build;
 
 type HANDLE = *mut u8;
@@ -118,8 +119,8 @@ pub unsafe fn setup(build: &mut Build) {
     SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
 
     // Create a new job object for us to use
-    let job = CreateJobObjectW(0 as *mut _, 0 as *const _);
-    assert!(job != 0 as *mut _, "{}", io::Error::last_os_error());
+    let job = CreateJobObjectW(ptr::null_mut(), ptr::null());
+    assert!(!job.is_null(), "{}", io::Error::last_os_error());
 
     // Indicate that when all handles to the job object are gone that all
     // process in the object should be killed. Note that this includes our
@@ -166,8 +167,8 @@ pub unsafe fn setup(build: &mut Build) {
     };
 
     let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap());
-    assert!(parent != 0 as *mut _, "{}", io::Error::last_os_error());
-    let mut parent_handle = 0 as *mut _;
+    assert!(!parent.is_null(), "{}", io::Error::last_os_error());
+    let mut parent_handle = ptr::null_mut();
     let r = DuplicateHandle(GetCurrentProcess(), job,
                             parent, &mut parent_handle,
                             0, FALSE, DUPLICATE_SAME_ACCESS);
diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs
index 9f684678bb0..47f5edd1563 100644
--- a/src/bootstrap/util.rs
+++ b/src/bootstrap/util.rs
@@ -209,7 +209,7 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> {
             let h = CreateFileW(path.as_ptr(),
                                 GENERIC_WRITE,
                                 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
-                                0 as *mut _,
+                                ptr::null_mut(),
                                 OPEN_EXISTING,
                                 FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
                                 ptr::null_mut());