Skip to content

Commit 81e95c1

Browse files
committed
Use ptr::{null, null_mut} instead of 0 as *{const, mut}
1 parent 2539c15 commit 81e95c1

File tree

12 files changed

+41
-29
lines changed

12 files changed

+41
-29
lines changed

src/libpanic_unwind/gcc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#![allow(private_no_mangle_fns)]
5858

5959
use core::any::Any;
60+
use core::ptr;
6061
use alloc::boxed::Box;
6162

6263
use unwind as uw;
@@ -88,7 +89,7 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
8889
}
8990

9091
pub fn payload() -> *mut u8 {
91-
0 as *mut u8
92+
ptr::null_mut()
9293
}
9394

9495
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {

src/libpanic_unwind/seh64_gnu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use alloc::boxed::Box;
1818

1919
use core::any::Any;
2020
use core::intrinsics;
21+
use core::ptr;
2122
use dwarf::eh;
2223
use windows as c;
2324

@@ -50,7 +51,7 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
5051
}
5152

5253
pub fn payload() -> *mut u8 {
53-
0 as *mut u8
54+
ptr::null_mut()
5455
}
5556

5657
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {

src/librustc_trans/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ use libc::c_uint;
9898
use std::ffi::{CStr, CString};
9999
use std::cell::{Cell, RefCell};
100100
use std::collections::{HashMap, HashSet};
101+
use std::ptr;
101102
use std::rc::Rc;
102103
use std::str;
103104
use std::{i8, i16, i32, i64};
@@ -2304,7 +2305,7 @@ pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
23042305
start_fn,
23052306
args.as_ptr(),
23062307
args.len() as c_uint,
2307-
0 as *mut _,
2308+
ptr::null_mut(),
23082309
noname());
23092310

23102311
llvm::LLVMBuildRet(bld, result);

src/librustc_trans/builder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
177177

178178
check_call("invoke", llfn, args);
179179

180-
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
180+
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
181181

182182
unsafe {
183183
llvm::LLVMRustBuildInvoke(self.llbuilder,
@@ -859,7 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
859859

860860
check_call("call", llfn, args);
861861

862-
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
862+
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
863863

864864
unsafe {
865865
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@@ -961,7 +961,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
961961
self.count_insn("trap");
962962
llvm::LLVMRustBuildCall(self.llbuilder, t,
963963
args.as_ptr(), args.len() as c_uint,
964-
0 as *mut _,
964+
ptr::null_mut(),
965965
noname());
966966
}
967967
}
@@ -1000,7 +1000,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10001000
parent: Option<ValueRef>,
10011001
args: &[ValueRef]) -> ValueRef {
10021002
self.count_insn("cleanuppad");
1003-
let parent = parent.unwrap_or(0 as *mut _);
1003+
let parent = parent.unwrap_or(ptr::null_mut());
10041004
let name = CString::new("cleanuppad").unwrap();
10051005
let ret = unsafe {
10061006
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@@ -1016,7 +1016,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10161016
pub fn cleanup_ret(&self, cleanup: ValueRef,
10171017
unwind: Option<BasicBlockRef>) -> ValueRef {
10181018
self.count_insn("cleanupret");
1019-
let unwind = unwind.unwrap_or(0 as *mut _);
1019+
let unwind = unwind.unwrap_or(ptr::null_mut());
10201020
let ret = unsafe {
10211021
llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
10221022
};
@@ -1052,8 +1052,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10521052
unwind: Option<BasicBlockRef>,
10531053
num_handlers: usize) -> ValueRef {
10541054
self.count_insn("catchswitch");
1055-
let parent = parent.unwrap_or(0 as *mut _);
1056-
let unwind = unwind.unwrap_or(0 as *mut _);
1055+
let parent = parent.unwrap_or(ptr::null_mut());
1056+
let unwind = unwind.unwrap_or(ptr::null_mut());
10571057
let name = CString::new("catchswitch").unwrap();
10581058
let ret = unsafe {
10591059
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,

src/libstd/sync/once.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
// it!
6666

6767
use marker;
68+
use ptr;
6869
use sync::atomic::{AtomicUsize, AtomicBool, Ordering};
6970
use thread::{self, Thread};
7071

@@ -297,7 +298,7 @@ impl Once {
297298
let mut node = Waiter {
298299
thread: Some(thread::current()),
299300
signaled: AtomicBool::new(false),
300-
next: 0 as *mut Waiter,
301+
next: ptr::null_mut(),
301302
};
302303
let me = &mut node as *mut Waiter as usize;
303304
assert!(me & STATE_MASK == 0);

src/libstd/sys/unix/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
227227
libc::KERN_PROC_ARGV];
228228
let mib = mib.as_mut_ptr();
229229
let mut argv_len = 0;
230-
cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len,
231-
0 as *mut _, 0))?;
230+
cvt(libc::sysctl(mib, 4, ptr::null_mut(), &mut argv_len,
231+
ptr::null_mut(), 0))?;
232232
let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize);
233233
cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _,
234-
&mut argv_len, 0 as *mut _, 0))?;
234+
&mut argv_len, ptr::null_mut(), 0))?;
235235
argv.set_len(argv_len as usize);
236236
if argv[0].is_null() {
237237
return Err(io::Error::new(io::ErrorKind::Other,

src/libstd/sys/unix/pipe.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cmp;
1414
use io;
1515
use libc::{self, c_int};
1616
use mem;
17+
use ptr;
1718
use sys::cvt_r;
1819
use sys::fd::FileDesc;
1920

@@ -92,8 +93,8 @@ pub fn read2(p1: AnonPipe,
9293
let mut read: libc::fd_set = mem::zeroed();
9394
libc::FD_SET(p1.raw(), &mut read);
9495
libc::FD_SET(p2.raw(), &mut read);
95-
libc::select(max + 1, &mut read, 0 as *mut _, 0 as *mut _,
96-
0 as *mut _)
96+
libc::select(max + 1, &mut read, ptr::null_mut(), ptr::null_mut(),
97+
ptr::null_mut())
9798
})?;
9899

99100
// Read as much as we can from each pipe, ignoring EWOULDBLOCK or

src/libstd/sys/unix/process.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Command {
9696
let mut saw_nul = false;
9797
let program = os2c(program, &mut saw_nul);
9898
Command {
99-
argv: vec![program.as_ptr(), 0 as *const _],
99+
argv: vec![program.as_ptr(), ptr::null()],
100100
program: program,
101101
args: Vec::new(),
102102
env: None,
@@ -117,7 +117,7 @@ impl Command {
117117
// pointer.
118118
let arg = os2c(arg, &mut self.saw_nul);
119119
self.argv[self.args.len() + 1] = arg.as_ptr();
120-
self.argv.push(0 as *const _);
120+
self.argv.push(ptr::null());
121121

122122
// Also make sure we keep track of the owned value to schedule a
123123
// destructor for this memory.
@@ -134,7 +134,7 @@ impl Command {
134134
envp.push(s.as_ptr());
135135
map.insert(k, (envp.len() - 1, s));
136136
}
137-
envp.push(0 as *const _);
137+
envp.push(ptr::null());
138138
self.env = Some(map);
139139
self.envp = Some(envp);
140140
}
@@ -158,7 +158,7 @@ impl Command {
158158
Entry::Vacant(e) => {
159159
let len = envp.len();
160160
envp[len - 1] = new_key.as_ptr();
161-
envp.push(0 as *const _);
161+
envp.push(ptr::null());
162162
e.insert((len - 1, new_key));
163163
}
164164
}
@@ -183,7 +183,7 @@ impl Command {
183183

184184
pub fn env_clear(&mut self) {
185185
self.env = Some(HashMap::new());
186-
self.envp = Some(vec![0 as *const _]);
186+
self.envp = Some(vec![ptr::null()]);
187187
}
188188

189189
pub fn cwd(&mut self, dir: &OsStr) {

src/libstd/sys/unix/time.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// except according to those terms.
1010

1111
use cmp::Ordering;
12-
use time::Duration;
1312
use libc;
13+
use time::Duration;
1414

1515
pub use self::inner::{Instant, SystemTime, UNIX_EPOCH};
1616

@@ -164,12 +164,14 @@ mod inner {
164164

165165
impl SystemTime {
166166
pub fn now() -> SystemTime {
167+
use ptr;
168+
167169
let mut s = libc::timeval {
168170
tv_sec: 0,
169171
tv_usec: 0,
170172
};
171173
cvt(unsafe {
172-
libc::gettimeofday(&mut s, 0 as *mut _)
174+
libc::gettimeofday(&mut s, ptr::null_mut())
173175
}).unwrap();
174176
return SystemTime::from(s)
175177
}

src/libstd/sys/windows/handle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ impl Handle {
4646

4747
pub fn new_event(manual: bool, init: bool) -> io::Result<Handle> {
4848
unsafe {
49-
let event = c::CreateEventW(0 as *mut _,
49+
let event = c::CreateEventW(ptr::null_mut(),
5050
manual as c::BOOL,
5151
init as c::BOOL,
52-
0 as *const _);
52+
ptr::null());
5353
if event.is_null() {
5454
Err(io::Error::last_os_error())
5555
} else {

src/libstd/sys/windows/pipe.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use prelude::v1::*;
1212
use os::windows::prelude::*;
1313

1414
use ffi::OsStr;
15-
use path::Path;
1615
use io;
1716
use mem;
17+
use path::Path;
18+
use ptr;
1819
use rand::{self, Rng};
1920
use slice;
2021
use sys::c;
@@ -66,7 +67,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
6667
4096,
6768
4096,
6869
0,
69-
0 as *mut _);
70+
ptr::null_mut());
7071

7172
// We pass the FILE_FLAG_FIRST_PIPE_INSTANCE flag above, and we're
7273
// also just doing a best effort at selecting a unique name. If

src/libtest/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ fn get_concurrency() -> usize {
959959
target_os = "bitrig",
960960
target_os = "netbsd"))]
961961
fn num_cpus() -> usize {
962+
use std::ptr;
963+
962964
let mut cpus: libc::c_uint = 0;
963965
let mut cpus_size = std::mem::size_of_val(&cpus);
964966

@@ -972,7 +974,7 @@ fn get_concurrency() -> usize {
972974
2,
973975
&mut cpus as *mut _ as *mut _,
974976
&mut cpus_size as *mut _ as *mut _,
975-
0 as *mut _,
977+
ptr::null_mut(),
976978
0);
977979
}
978980
if cpus < 1 {
@@ -984,6 +986,8 @@ fn get_concurrency() -> usize {
984986

985987
#[cfg(target_os = "openbsd")]
986988
fn num_cpus() -> usize {
989+
use std::ptr;
990+
987991
let mut cpus: libc::c_uint = 0;
988992
let mut cpus_size = std::mem::size_of_val(&cpus);
989993
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
@@ -993,7 +997,7 @@ fn get_concurrency() -> usize {
993997
2,
994998
&mut cpus as *mut _ as *mut _,
995999
&mut cpus_size as *mut _ as *mut _,
996-
0 as *mut _,
1000+
ptr::null_mut(),
9971001
0);
9981002
}
9991003
if cpus < 1 {

0 commit comments

Comments
 (0)