diff --git a/src/bootstrap/build/job.rs b/src/bootstrap/build/job.rs index a4e53bc45fcfb..311b4dde209ee 100644 --- a/src/bootstrap/build/job.rs +++ b/src/bootstrap/build/job.rs @@ -49,8 +49,8 @@ use self::kernel32::*; pub unsafe fn setup() { // 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 != ptr::null_mut(), "{}", 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 @@ -93,8 +93,8 @@ pub unsafe fn setup() { }; 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 != ptr::null_mut(), "{}", 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/libarena/lib.rs b/src/libarena/lib.rs index b299b786b35a8..914fb8f36b4f8 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -106,7 +106,7 @@ impl TypedArenaChunk { unsafe { if mem::size_of::() == 0 { // A pointer as large as possible for zero-sized elements. - !0 as *mut T + (!0usize) as *mut T } else { self.start().offset(self.storage.cap() as isize) } diff --git a/src/librustc_back/dynamic_lib.rs b/src/librustc_back/dynamic_lib.rs index 2f86262afbe22..2956a9d9103c8 100644 --- a/src/librustc_back/dynamic_lib.rs +++ b/src/librustc_back/dynamic_lib.rs @@ -276,7 +276,7 @@ mod dl { None => { let mut handle = ptr::null_mut(); let succeeded = unsafe { - GetModuleHandleExW(0 as DWORD, ptr::null(), &mut handle) + GetModuleHandleExW(0, ptr::null(), &mut handle) }; if succeeded == 0 { Err(io::Error::last_os_error().to_string()) diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 9190389b722b6..f0741d0d44cae 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -99,7 +99,7 @@ use libc::c_uint; use std::ffi::{CStr, CString}; use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet}; -use std::str; +use std::{str, ptr}; use std::{i8, i16, i32, i64}; use syntax::codemap::{Span, DUMMY_SP}; use syntax::parse::token::InternedString; @@ -2409,7 +2409,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext, sp: Span, main_llfn: ValueRef) { (start_fn, args) } else { debug!("using user-defined start fn"); - let args = vec![get_param(llfn, 0 as c_uint), get_param(llfn, 1 as c_uint)]; + let args = vec![get_param(llfn, 0), get_param(llfn, 1)]; (rust_main, args) }; @@ -2418,7 +2418,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext, sp: Span, main_llfn: ValueRef) { start_fn, args.as_ptr(), args.len() as c_uint, - 0 as *mut _, + ptr::null_mut(), noname()); llvm::LLVMBuildRet(bld, result); diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs index 92fb342497b5a..7bb486f5e9f99 100644 --- a/src/librustc_trans/builder.rs +++ b/src/librustc_trans/builder.rs @@ -176,7 +176,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .collect::>() .join(", ")); - let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _); + let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut()); unsafe { llvm::LLVMRustBuildInvoke(self.llbuilder, @@ -879,7 +879,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _); + let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut()); unsafe { llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(), @@ -981,7 +981,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.count_insn("trap"); llvm::LLVMRustBuildCall(self.llbuilder, t, args.as_ptr(), args.len() as c_uint, - 0 as *mut _, + ptr::null_mut(), noname()); } } @@ -1020,7 +1020,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { parent: Option, args: &[ValueRef]) -> ValueRef { self.count_insn("cleanuppad"); - let parent = parent.unwrap_or(0 as *mut _); + let parent = parent.unwrap_or(ptr::null_mut()); let name = CString::new("cleanuppad").unwrap(); let ret = unsafe { llvm::LLVMRustBuildCleanupPad(self.llbuilder, @@ -1036,7 +1036,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub fn cleanup_ret(&self, cleanup: ValueRef, unwind: Option) -> ValueRef { self.count_insn("cleanupret"); - let unwind = unwind.unwrap_or(0 as *mut _); + let unwind = unwind.unwrap_or(ptr::null_mut()); let ret = unsafe { llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind) }; @@ -1072,8 +1072,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { unwind: Option, num_handlers: usize) -> ValueRef { self.count_insn("catchswitch"); - let parent = parent.unwrap_or(0 as *mut _); - let unwind = unwind.unwrap_or(0 as *mut _); + let parent = parent.unwrap_or(ptr::null_mut()); + let unwind = unwind.unwrap_or(ptr::null_mut()); let name = CString::new("catchswitch").unwrap(); let ret = unsafe { llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind, diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 1217b2b5a1b17..20e4663f91c0e 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -552,7 +552,7 @@ impl<'tcx> LocalCrateContext<'tcx> { CrateContext { shared: shared, local: self, - index: !0 as usize, + index: !0, } } } diff --git a/src/librustc_trans/tvec.rs b/src/librustc_trans/tvec.rs index f5b9bef5313f2..d4c1617600205 100644 --- a/src/librustc_trans/tvec.rs +++ b/src/librustc_trans/tvec.rs @@ -336,7 +336,7 @@ fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, Br(bcx, loop_bcx.llbb, DebugLoc::None); let loop_counter = Phi(loop_bcx, bcx.ccx().int_type(), - &[C_uint(bcx.ccx(), 0 as usize)], &[bcx.llbb]); + &[C_uint(bcx.ccx(), 0u64)], &[bcx.llbb]); let bcx = loop_bcx; @@ -346,7 +346,7 @@ fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, InBoundsGEP(bcx, data_ptr, &[loop_counter]) }; let bcx = f(bcx, lleltptr, vt.unit_ty); - let plusone = Add(bcx, loop_counter, C_uint(bcx.ccx(), 1usize), DebugLoc::None); + let plusone = Add(bcx, loop_counter, C_uint(bcx.ccx(), 1u64), DebugLoc::None); AddIncomingToPhi(loop_counter, plusone, bcx.llbb); let cond_val = ICmp(bcx, llvm::IntULT, plusone, count, DebugLoc::None); diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index a1002fdb645fc..a9e5903620411 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -324,7 +324,7 @@ mod tests { #[test] fn test_buf_writer() { - let mut buf = [0 as u8; 9]; + let mut buf = [0u8; 9]; { let mut writer = Cursor::new(&mut buf[..]); assert_eq!(writer.position(), 0); @@ -345,7 +345,7 @@ mod tests { #[test] fn test_buf_writer_seek() { - let mut buf = [0 as u8; 8]; + let mut buf = [0u8; 8]; { let mut writer = Cursor::new(&mut buf[..]); assert_eq!(writer.position(), 0); @@ -374,7 +374,7 @@ mod tests { #[test] fn test_buf_writer_error() { - let mut buf = [0 as u8; 2]; + let mut buf = [0u8; 2]; let mut writer = Cursor::new(&mut buf[..]); assert_eq!(writer.write(&[0]).unwrap(), 1); assert_eq!(writer.write(&[0, 0]).unwrap(), 1); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index e228d236a3ca7..369d8894bd9c1 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -67,6 +67,7 @@ use marker; use sync::atomic::{AtomicUsize, AtomicBool, Ordering}; use thread::{self, Thread}; +use ptr; /// A synchronization primitive which can be used to run a one-time global /// initialization. Useful for one-time initialization for FFI or related @@ -298,7 +299,7 @@ impl Once { let mut node = Waiter { thread: Some(thread::current()), signaled: AtomicBool::new(false), - next: 0 as *mut Waiter, + next: ptr::null_mut(), }; let me = &mut node as *mut Waiter as usize; assert!(me & STATE_MASK == 0); diff --git a/src/libstd/sys/common/dwarf/mod.rs b/src/libstd/sys/common/dwarf/mod.rs index 822826bcc837f..4e64a0391c8ff 100644 --- a/src/libstd/sys/common/dwarf/mod.rs +++ b/src/libstd/sys/common/dwarf/mod.rs @@ -77,7 +77,7 @@ impl DwarfReader { } // sign-extend if shift < 8 * mem::size_of::() && (byte & 0x40) != 0 { - result |= (!0 as u64) << shift; + result |= (!0u64) << shift; } result as i64 } diff --git a/src/libstd/sys/common/unwind/gcc.rs b/src/libstd/sys/common/unwind/gcc.rs index da7a340af3515..36d65c557c787 100644 --- a/src/libstd/sys/common/unwind/gcc.rs +++ b/src/libstd/sys/common/unwind/gcc.rs @@ -14,6 +14,7 @@ use prelude::v1::*; use any::Any; use sys_common::libunwind as uw; +use ptr; struct Exception { uwe: uw::_Unwind_Exception, @@ -42,7 +43,7 @@ pub unsafe fn panic(data: Box) -> ! { } pub fn payload() -> *mut u8 { - 0 as *mut u8 + ptr::null_mut() } pub unsafe fn cleanup(ptr: *mut u8) -> Box { diff --git a/src/libstd/sys/common/unwind/seh64_gnu.rs b/src/libstd/sys/common/unwind/seh64_gnu.rs index 57281d67ebb40..9ae77e6a93433 100644 --- a/src/libstd/sys/common/unwind/seh64_gnu.rs +++ b/src/libstd/sys/common/unwind/seh64_gnu.rs @@ -51,7 +51,7 @@ pub unsafe fn panic(data: Box) -> ! { } pub fn payload() -> *mut u8 { - 0 as *mut u8 + ptr::null_mut() } pub unsafe fn cleanup(ptr: *mut u8) -> Box { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 94ebbd70ae83d..6597d015b9594 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -227,11 +227,11 @@ pub fn current_exe() -> io::Result { libc::KERN_PROC_ARGV]; let mib = mib.as_mut_ptr(); let mut argv_len = 0; - cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len, - 0 as *mut _, 0))?; + cvt(libc::sysctl(mib, 4, ptr::null_mut(), &mut argv_len, + ptr::null_mut(), 0))?; let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, - &mut argv_len, 0 as *mut _, 0))?; + &mut argv_len, ptr::null_mut(), 0))?; argv.set_len(argv_len as usize); if argv[0].is_null() { return Err(io::Error::new(io::ErrorKind::Other, diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index beca2d467536d..16be38ae662b5 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -14,6 +14,7 @@ use cmp; use io; use libc::{self, c_int}; use mem; +use ptr; use sys::cvt_r; use sys::fd::FileDesc; @@ -91,8 +92,8 @@ pub fn read2(p1: AnonPipe, let mut read: libc::fd_set = mem::zeroed(); libc::FD_SET(p1.raw(), &mut read); libc::FD_SET(p2.raw(), &mut read); - libc::select(max + 1, &mut read, 0 as *mut _, 0 as *mut _, - 0 as *mut _) + libc::select(max + 1, &mut read, ptr::null_mut(), ptr::null_mut(), + ptr::null_mut()) })?; // Read as much as we can from each pipe, ignoring EWOULDBLOCK or diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 270c2096b2c3b..6abec457fd077 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -97,7 +97,7 @@ impl Command { let mut saw_nul = false; let program = os2c(program, &mut saw_nul); Command { - argv: vec![program.as_ptr(), 0 as *const _], + argv: vec![program.as_ptr(), ptr::null()], program: program, args: Vec::new(), env: None, @@ -119,7 +119,7 @@ impl Command { // pointer. let arg = os2c(arg, &mut self.saw_nul); self.argv[self.args.len() + 1] = arg.as_ptr(); - self.argv.push(0 as *const _); + self.argv.push(ptr::null()); // Also make sure we keep track of the owned value to schedule a // destructor for this memory. @@ -136,7 +136,7 @@ impl Command { envp.push(s.as_ptr()); map.insert(k, (envp.len() - 1, s)); } - envp.push(0 as *const _); + envp.push(ptr::null()); self.env = Some(map); self.envp = Some(envp); } @@ -160,7 +160,7 @@ impl Command { Entry::Vacant(e) => { let len = envp.len(); envp[len - 1] = new_key.as_ptr(); - envp.push(0 as *const _); + envp.push(ptr::null()); e.insert((len - 1, new_key)); } } @@ -185,7 +185,7 @@ impl Command { pub fn env_clear(&mut self) { self.env = Some(HashMap::new()); - self.envp = Some(vec![0 as *const _]); + self.envp = Some(vec![ptr::null()]); } pub fn cwd(&mut self, dir: &OsStr) { @@ -588,7 +588,7 @@ impl Process { if let Some(status) = self.status { return Ok(status) } - let mut status = 0 as c_int; + let mut status: c_int = 0; cvt_r(|| unsafe { libc::waitpid(self.pid, &mut status, 0) })?; self.status = Some(ExitStatus(status)); Ok(ExitStatus(status)) diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index cc7abe25e35e5..3844844f1c631 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -79,7 +79,7 @@ mod inner { }, }; cvt(unsafe { - libc::gettimeofday(&mut s.t, 0 as *mut _) + libc::gettimeofday(&mut s.t, ptr::null_mut()) }).unwrap(); return s } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index ab24b9e6fd601..ee1470dd0c4bf 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -191,7 +191,7 @@ pub const ERROR_OPERATION_ABORTED: DWORD = 995; pub const ERROR_IO_PENDING: DWORD = 997; pub const ERROR_TIMEOUT: DWORD = 0x5B4; -pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE; +pub const INVALID_HANDLE_VALUE: HANDLE = (!0usize) as HANDLE; pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000; pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200; diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index 74546bb893bea..d10abae286527 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -46,10 +46,10 @@ impl Handle { pub fn new_event(manual: bool, init: bool) -> io::Result { unsafe { - let event = c::CreateEventW(0 as *mut _, + let event = c::CreateEventW(ptr::null_mut(), manual as c::BOOL, init as c::BOOL, - 0 as *const _); + ptr::null()); if event.is_null() { Err(io::Error::last_os_error()) } else { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 32ca32e76cb62..cd9ea85a351e4 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -38,7 +38,7 @@ pub fn errno() -> i32 { pub fn error_string(errnum: i32) -> String { // This value is calculated from the macro // MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT) - let langId = 0x0800 as c::DWORD; + let langId: c::DWORD = 0x0800; let mut buf = [0 as c::WCHAR; 2048]; diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 8631a63d653a3..96a7cd9245453 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -15,6 +15,7 @@ use ffi::OsStr; use path::Path; use io; use mem; +use ptr; use rand::{self, Rng}; use slice; use sys::c; @@ -66,7 +67,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> { 4096, 4096, 0, - 0 as *mut _); + ptr::null_mut()); // We pass the FILE_FLAG_FIRST_PIPE_INSTANCE flag above, and we're // also just doing a best effort at selecting a unique name. If diff --git a/src/libstd/sys/windows/rand.rs b/src/libstd/sys/windows/rand.rs index 10e3d45f9d5eb..728945fa8f356 100644 --- a/src/libstd/sys/windows/rand.rs +++ b/src/libstd/sys/windows/rand.rs @@ -11,6 +11,7 @@ use io; use mem; +use ptr; use rand::Rng; use sys::c; @@ -23,7 +24,7 @@ impl OsRng { pub fn new() -> io::Result { let mut hcp = 0; let ret = unsafe { - c::CryptAcquireContextA(&mut hcp, 0 as c::LPCSTR, 0 as c::LPCSTR, + c::CryptAcquireContextA(&mut hcp, ptr::null(), ptr::null(), c::PROV_RSA_FULL, c::CRYPT_VERIFYCONTEXT | c::CRYPT_SILENT) }; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index c6a70edf2a8f2..ce61b15c78c4c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -971,9 +971,9 @@ fn get_concurrency() -> usize { unsafe { libc::sysctl(mib.as_mut_ptr(), 2, - &mut cpus as *mut _ as *mut _, - &mut cpus_size as *mut _ as *mut _, - 0 as *mut _, + &mut cpus as *mut _, + &mut cpus_size as *mut _, + ptr::null_mut(), 0); } if cpus < 1 { @@ -992,9 +992,9 @@ fn get_concurrency() -> usize { unsafe { libc::sysctl(mib.as_mut_ptr(), 2, - &mut cpus as *mut _ as *mut _, - &mut cpus_size as *mut _ as *mut _, - 0 as *mut _, + &mut cpus as *mut _, + &mut cpus_size as *mut _, + ptr::null_mut(), 0); } if cpus < 1 { diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 335b6d67209de..072a449a93dba 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -210,7 +210,7 @@ impl Stats for [f64] { } fn median(&self) -> f64 { - self.percentile(50 as f64) + self.percentile(50_f64) } fn var(&self) -> f64 { @@ -236,7 +236,7 @@ impl Stats for [f64] { } fn std_dev_pct(&self) -> f64 { - let hundred = 100 as f64; + let hundred = 100_f64; (self.std_dev() / self.mean()) * hundred } @@ -250,7 +250,7 @@ impl Stats for [f64] { } fn median_abs_dev_pct(&self) -> f64 { - let hundred = 100 as f64; + let hundred = 100_f64; (self.median_abs_dev() / self.median()) * hundred } @@ -315,7 +315,7 @@ pub fn winsorize(samples: &mut [f64], pct: f64) { let mut tmp = samples.to_vec(); local_sort(&mut tmp); let lo = percentile_of_sorted(&tmp, pct); - let hundred = 100 as f64; + let hundred = 100_f64; let hi = percentile_of_sorted(&tmp, hundred - pct); for samp in samples { if *samp > hi {