Skip to content

Commit 06fb196

Browse files
committed
Use null()/null_mut() instead of 0 as *const T/0 as *mut T
1 parent 3903ea9 commit 06fb196

File tree

22 files changed

+65
-52
lines changed

22 files changed

+65
-52
lines changed

src/libcollections/btree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<K, V> Drop for Node<K, V> {
296296
self.destroy();
297297
}
298298

299-
self.keys = unsafe { Unique::new(0 as *mut K) };
299+
self.keys = unsafe { Unique::new(ptr::null_mut()) };
300300
}
301301
}
302302

src/libcollections/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<T> ops::Deref for Vec<T> {
11351135
fn deref(&self) -> &[T] {
11361136
unsafe {
11371137
let p = self.buf.ptr();
1138-
assume(p != 0 as *mut T);
1138+
assume(!p.is_null());
11391139
slice::from_raw_parts(p, self.len)
11401140
}
11411141
}

src/liblog/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ use std::io::{self, Stderr};
184184
use std::io::prelude::*;
185185
use std::mem;
186186
use std::env;
187+
use std::ptr;
187188
use std::rt;
188189
use std::slice;
189190
use std::sync::{Once, StaticMutex};
@@ -209,11 +210,10 @@ static LOCK: StaticMutex = StaticMutex::new();
209210
/// logging statement should be run.
210211
static mut LOG_LEVEL: u32 = MAX_LOG_LEVEL;
211212

212-
static mut DIRECTIVES: *mut Vec<directive::LogDirective> =
213-
0 as *mut Vec<directive::LogDirective>;
213+
static mut DIRECTIVES: *mut Vec<directive::LogDirective> = ptr::null_mut();
214214

215215
/// Optional filter.
216-
static mut FILTER: *mut String = 0 as *mut _;
216+
static mut FILTER: *mut String = ptr::null_mut();
217217

218218
/// Debug log level
219219
pub const DEBUG: u32 = 4;

src/librustc_trans/back/archive.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::io;
1818
use std::mem;
1919
use std::path::{Path, PathBuf};
2020
use std::process::{Command, Output, Stdio};
21+
use std::ptr;
2122
use std::str;
2223

2324
use libc;
@@ -449,7 +450,7 @@ impl<'a> ArchiveBuilder<'a> {
449450
}
450451

451452
let name = try!(CString::new(child_name));
452-
members.push(llvm::LLVMRustArchiveMemberNew(0 as *const _,
453+
members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
453454
name.as_ptr(),
454455
child.raw()));
455456
strings.push(name);
@@ -462,7 +463,7 @@ impl<'a> ArchiveBuilder<'a> {
462463
let name = try!(CString::new(name_in_archive));
463464
members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(),
464465
name.as_ptr(),
465-
0 as *mut _));
466+
ptr::null_mut()));
466467
strings.push(path);
467468
strings.push(name);
468469
}
@@ -472,7 +473,7 @@ impl<'a> ArchiveBuilder<'a> {
472473
if skip(child_name) { continue }
473474

474475
let name = try!(CString::new(child_name));
475-
let m = llvm::LLVMRustArchiveMemberNew(0 as *const _,
476+
let m = llvm::LLVMRustArchiveMemberNew(ptr::null(),
476477
name.as_ptr(),
477478
child.raw());
478479
members.push(m);

src/librustc_trans/back/msvc/registry.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::io;
1212
use std::ffi::{OsString, OsStr};
1313
use std::os::windows::prelude::*;
1414
use std::ops::RangeFrom;
15+
use std::ptr;
1516
use libc::{DWORD, LPCWSTR, LONG, LPDWORD, LPBYTE, ERROR_SUCCESS};
1617
use libc::c_void;
1718

@@ -88,7 +89,7 @@ impl RegistryKey {
8889

8990
pub fn open(&self, key: &OsStr) -> io::Result<RegistryKey> {
9091
let key = key.encode_wide().chain(Some(0)).collect::<Vec<_>>();
91-
let mut ret = 0 as *mut _;
92+
let mut ret = ptr::null_mut();
9293
let err = unsafe {
9394
RegOpenKeyExW(self.raw(), key.as_ptr(), 0,
9495
KEY_READ | KEY_WOW64_32KEY, &mut ret)
@@ -110,8 +111,8 @@ impl RegistryKey {
110111
let mut len = 0;
111112
let mut kind = 0;
112113
unsafe {
113-
let err = RegQueryValueExW(self.raw(), name.as_ptr(), 0 as *mut _,
114-
&mut kind, 0 as *mut _, &mut len);
114+
let err = RegQueryValueExW(self.raw(), name.as_ptr(), ptr::null_mut(),
115+
&mut kind, ptr::null_mut(), &mut len);
115116
if err != ERROR_SUCCESS {
116117
return Err(io::Error::from_raw_os_error(err as i32))
117118
}
@@ -124,8 +125,8 @@ impl RegistryKey {
124125
// characters so we need to be sure to halve it for the capacity
125126
// passed in.
126127
let mut v = Vec::with_capacity(len as usize / 2);
127-
let err = RegQueryValueExW(self.raw(), name.as_ptr(), 0 as *mut _,
128-
0 as *mut _, v.as_mut_ptr() as *mut _,
128+
let err = RegQueryValueExW(self.raw(), name.as_ptr(), ptr::null_mut(),
129+
ptr::null_mut(), v.as_mut_ptr() as *mut _,
129130
&mut len);
130131
if err != ERROR_SUCCESS {
131132
return Err(io::Error::from_raw_os_error(err as i32))
@@ -156,8 +157,8 @@ impl<'a> Iterator for Iter<'a> {
156157
let mut v = Vec::with_capacity(256);
157158
let mut len = v.capacity() as DWORD;
158159
let ret = RegEnumKeyExW(self.key.raw(), i, v.as_mut_ptr(), &mut len,
159-
0 as *mut _, 0 as *mut _, 0 as *mut _,
160-
0 as *mut _);
160+
ptr::null_mut(), ptr::null_mut(), ptr::null_mut(),
161+
ptr::null_mut());
161162
if ret == ERROR_NO_MORE_ITEMS as LONG {
162163
None
163164
} else if ret != ERROR_SUCCESS {

src/libstd/io/lazy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use prelude::v1::*;
1212

1313
use cell::Cell;
14+
use ptr;
1415
use rt;
1516
use sync::{StaticMutex, Arc};
1617

@@ -26,7 +27,7 @@ impl<T: Send + Sync + 'static> Lazy<T> {
2627
pub const fn new(init: fn() -> Arc<T>) -> Lazy<T> {
2728
Lazy {
2829
lock: StaticMutex::new(),
29-
ptr: Cell::new(0 as *mut _),
30+
ptr: Cell::new(ptr::null_mut()),
3031
init: init
3132
}
3233
}

src/libstd/rand/os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ mod imp {
185185

186186
use io;
187187
use mem;
188+
use ptr;
188189
use rand::Rng;
189190
use libc::{c_int, size_t};
190191

@@ -207,7 +208,7 @@ mod imp {
207208
enum SecRandom {}
208209

209210
#[allow(non_upper_case_globals)]
210-
const kSecRandomDefault: *const SecRandom = 0 as *const SecRandom;
211+
const kSecRandomDefault: *const SecRandom = ptr::null();
211212

212213
#[link(name = "Security", kind = "framework")]
213214
extern "C" {

src/libstd/rt/at_exit_imp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use alloc::boxed::FnBox;
2020
use boxed::Box;
21+
use ptr;
2122
use sys_common::mutex::Mutex;
2223
use vec::Vec;
2324

@@ -28,7 +29,7 @@ type Queue = Vec<Box<FnBox()>>;
2829
// the thread infrastructure to be in place (useful on the borders of
2930
// initialization/destruction).
3031
static LOCK: Mutex = Mutex::new();
31-
static mut QUEUE: *mut Queue = 0 as *mut Queue;
32+
static mut QUEUE: *mut Queue = ptr::null_mut();
3233

3334
// The maximum number of times the cleanup routines will be run. While running
3435
// the at_exit closures new ones may be registered, and this count is the number

src/libstd/rt/unwind/seh.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use prelude::v1::*;
5353

5454
use any::Any;
5555
use libc::{c_ulong, DWORD, c_void};
56+
use ptr;
5657
use sys_common::thread_local::StaticKey;
5758

5859
// 0x R U S T
@@ -98,7 +99,7 @@ pub unsafe fn panic(data: Box<Any + Send + 'static>) -> ! {
9899
rtassert!(PANIC_DATA.get().is_null());
99100
PANIC_DATA.set(Box::into_raw(exception) as *mut u8);
100101

101-
RaiseException(RUST_PANIC, 0, 0, 0 as *const _);
102+
RaiseException(RUST_PANIC, 0, 0, ptr::null());
102103
rtabort!("could not unwind stack");
103104
}
104105

@@ -108,7 +109,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send + 'static> {
108109
rtassert!(ptr as DWORD == RUST_PANIC);
109110

110111
let data = PANIC_DATA.get() as *mut Box<Any + Send + 'static>;
111-
PANIC_DATA.set(0 as *mut u8);
112+
PANIC_DATA.set(ptr::null_mut());
112113
rtassert!(!data.is_null());
113114

114115
*Box::from_raw(data)

src/libstd/sys/common/net.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use io::{self, Error, ErrorKind};
1616
use libc::{self, c_int, c_char, c_void, socklen_t};
1717
use mem;
1818
use net::{SocketAddr, Shutdown, IpAddr};
19+
use ptr;
1920
use str::from_utf8;
2021
use sys::c;
2122
use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t};
@@ -123,9 +124,9 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> {
123124
init();
124125

125126
let c_host = try!(CString::new(host));
126-
let mut res = 0 as *mut _;
127+
let mut res = ptr::null_mut();
127128
unsafe {
128-
try!(cvt_gai(getaddrinfo(c_host.as_ptr(), 0 as *const _, 0 as *const _,
129+
try!(cvt_gai(getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(),
129130
&mut res)));
130131
Ok(LookupHost { original: res, cur: res })
131132
}
@@ -154,7 +155,7 @@ pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> {
154155
let data = unsafe {
155156
try!(cvt_gai(getnameinfo(inner, len,
156157
hostbuf.as_mut_ptr(), NI_MAXHOST as libc::size_t,
157-
0 as *mut _, 0, 0)));
158+
ptr::null_mut(), 0, 0)));
158159

159160
CStr::from_ptr(hostbuf.as_ptr())
160161
};

0 commit comments

Comments
 (0)