Skip to content

Commit ecfacb5

Browse files
committed
Remove unnecesary "as" casts.
- "0 as *mut _" -> "ptr::null_mut()"; and the same goes for ptr::null() - Simplify "0 as c_int" to "0" when the context already expects c_int - And so on... Signed-off-by: NODA, Kai <[email protected]>
1 parent 8f55218 commit ecfacb5

File tree

23 files changed

+59
-54
lines changed

23 files changed

+59
-54
lines changed

src/bootstrap/build/job.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ use self::kernel32::*;
4949

5050
pub unsafe fn setup() {
5151
// Create a new job object for us to use
52-
let job = CreateJobObjectW(0 as *mut _, 0 as *const _);
53-
assert!(job != 0 as *mut _, "{}", io::Error::last_os_error());
52+
let job = CreateJobObjectW(ptr::null_mut(), ptr::null());
53+
assert!(job != ptr::null_mut(), "{}", io::Error::last_os_error());
5454

5555
// Indicate that when all handles to the job object are gone that all
5656
// process in the object should be killed. Note that this includes our
@@ -93,8 +93,8 @@ pub unsafe fn setup() {
9393
};
9494

9595
let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap());
96-
assert!(parent != 0 as *mut _, "{}", io::Error::last_os_error());
97-
let mut parent_handle = 0 as *mut _;
96+
assert!(parent != ptr::null_mut(), "{}", io::Error::last_os_error());
97+
let mut parent_handle = ptr::null_mut();
9898
let r = DuplicateHandle(GetCurrentProcess(), job,
9999
parent, &mut parent_handle,
100100
0, FALSE, DUPLICATE_SAME_ACCESS);

src/libarena/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<T> TypedArenaChunk<T> {
106106
unsafe {
107107
if mem::size_of::<T>() == 0 {
108108
// A pointer as large as possible for zero-sized elements.
109-
!0 as *mut T
109+
(!0usize) as *mut T
110110
} else {
111111
self.start().offset(self.storage.cap() as isize)
112112
}

src/librustc_back/dynamic_lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ mod dl {
276276
None => {
277277
let mut handle = ptr::null_mut();
278278
let succeeded = unsafe {
279-
GetModuleHandleExW(0 as DWORD, ptr::null(), &mut handle)
279+
GetModuleHandleExW(0, ptr::null(), &mut handle)
280280
};
281281
if succeeded == 0 {
282282
Err(io::Error::last_os_error().to_string())

src/librustc_trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use libc::c_uint;
9999
use std::ffi::{CStr, CString};
100100
use std::cell::{Cell, RefCell};
101101
use std::collections::{HashMap, HashSet};
102-
use std::str;
102+
use std::{str, ptr};
103103
use std::{i8, i16, i32, i64};
104104
use syntax::codemap::{Span, DUMMY_SP};
105105
use syntax::parse::token::InternedString;
@@ -2409,7 +2409,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext, sp: Span, main_llfn: ValueRef) {
24092409
(start_fn, args)
24102410
} else {
24112411
debug!("using user-defined start fn");
2412-
let args = vec![get_param(llfn, 0 as c_uint), get_param(llfn, 1 as c_uint)];
2412+
let args = vec![get_param(llfn, 0), get_param(llfn, 1)];
24132413

24142414
(rust_main, args)
24152415
};
@@ -2418,7 +2418,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext, sp: Span, main_llfn: ValueRef) {
24182418
start_fn,
24192419
args.as_ptr(),
24202420
args.len() as c_uint,
2421-
0 as *mut _,
2421+
ptr::null_mut(),
24222422
noname());
24232423

24242424
llvm::LLVMBuildRet(bld, result);

src/librustc_trans/builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
176176
.collect::<Vec<String>>()
177177
.join(", "));
178178

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

181181
unsafe {
182182
llvm::LLVMRustBuildInvoke(self.llbuilder,
@@ -879,7 +879,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
879879
}
880880
}
881881

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

884884
unsafe {
885885
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@@ -981,7 +981,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
981981
self.count_insn("trap");
982982
llvm::LLVMRustBuildCall(self.llbuilder, t,
983983
args.as_ptr(), args.len() as c_uint,
984-
0 as *mut _,
984+
ptr::null_mut(),
985985
noname());
986986
}
987987
}
@@ -1020,7 +1020,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10201020
parent: Option<ValueRef>,
10211021
args: &[ValueRef]) -> ValueRef {
10221022
self.count_insn("cleanuppad");
1023-
let parent = parent.unwrap_or(0 as *mut _);
1023+
let parent = parent.unwrap_or(ptr::null_mut());
10241024
let name = CString::new("cleanuppad").unwrap();
10251025
let ret = unsafe {
10261026
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@@ -1036,7 +1036,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10361036
pub fn cleanup_ret(&self, cleanup: ValueRef,
10371037
unwind: Option<BasicBlockRef>) -> ValueRef {
10381038
self.count_insn("cleanupret");
1039-
let unwind = unwind.unwrap_or(0 as *mut _);
1039+
let unwind = unwind.unwrap_or(ptr::null_mut());
10401040
let ret = unsafe {
10411041
llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
10421042
};
@@ -1072,8 +1072,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10721072
unwind: Option<BasicBlockRef>,
10731073
num_handlers: usize) -> ValueRef {
10741074
self.count_insn("catchswitch");
1075-
let parent = parent.unwrap_or(0 as *mut _);
1076-
let unwind = unwind.unwrap_or(0 as *mut _);
1075+
let parent = parent.unwrap_or(ptr::null_mut());
1076+
let unwind = unwind.unwrap_or(ptr::null_mut());
10771077
let name = CString::new("catchswitch").unwrap();
10781078
let ret = unsafe {
10791079
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,

src/librustc_trans/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl<'tcx> LocalCrateContext<'tcx> {
552552
CrateContext {
553553
shared: shared,
554554
local: self,
555-
index: !0 as usize,
555+
index: !0,
556556
}
557557
}
558558
}

src/librustc_trans/tvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
336336
Br(bcx, loop_bcx.llbb, DebugLoc::None);
337337

338338
let loop_counter = Phi(loop_bcx, bcx.ccx().int_type(),
339-
&[C_uint(bcx.ccx(), 0 as usize)], &[bcx.llbb]);
339+
&[C_uint(bcx.ccx(), 0u64)], &[bcx.llbb]);
340340

341341
let bcx = loop_bcx;
342342

@@ -346,7 +346,7 @@ fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
346346
InBoundsGEP(bcx, data_ptr, &[loop_counter])
347347
};
348348
let bcx = f(bcx, lleltptr, vt.unit_ty);
349-
let plusone = Add(bcx, loop_counter, C_uint(bcx.ccx(), 1usize), DebugLoc::None);
349+
let plusone = Add(bcx, loop_counter, C_uint(bcx.ccx(), 1u64), DebugLoc::None);
350350
AddIncomingToPhi(loop_counter, plusone, bcx.llbb);
351351

352352
let cond_val = ICmp(bcx, llvm::IntULT, plusone, count, DebugLoc::None);

src/libstd/io/cursor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mod tests {
324324

325325
#[test]
326326
fn test_buf_writer() {
327-
let mut buf = [0 as u8; 9];
327+
let mut buf = [0u8; 9];
328328
{
329329
let mut writer = Cursor::new(&mut buf[..]);
330330
assert_eq!(writer.position(), 0);
@@ -345,7 +345,7 @@ mod tests {
345345

346346
#[test]
347347
fn test_buf_writer_seek() {
348-
let mut buf = [0 as u8; 8];
348+
let mut buf = [0u8; 8];
349349
{
350350
let mut writer = Cursor::new(&mut buf[..]);
351351
assert_eq!(writer.position(), 0);
@@ -374,7 +374,7 @@ mod tests {
374374

375375
#[test]
376376
fn test_buf_writer_error() {
377-
let mut buf = [0 as u8; 2];
377+
let mut buf = [0u8; 2];
378378
let mut writer = Cursor::new(&mut buf[..]);
379379
assert_eq!(writer.write(&[0]).unwrap(), 1);
380380
assert_eq!(writer.write(&[0, 0]).unwrap(), 1);

src/libstd/sync/once.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use marker;
6868
use sync::atomic::{AtomicUsize, AtomicBool, Ordering};
6969
use thread::{self, Thread};
70+
use ptr;
7071

7172
/// A synchronization primitive which can be used to run a one-time global
7273
/// initialization. Useful for one-time initialization for FFI or related
@@ -298,7 +299,7 @@ impl Once {
298299
let mut node = Waiter {
299300
thread: Some(thread::current()),
300301
signaled: AtomicBool::new(false),
301-
next: 0 as *mut Waiter,
302+
next: ptr::null_mut(),
302303
};
303304
let me = &mut node as *mut Waiter as usize;
304305
assert!(me & STATE_MASK == 0);

src/libstd/sys/common/dwarf/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl DwarfReader {
7777
}
7878
// sign-extend
7979
if shift < 8 * mem::size_of::<u64>() && (byte & 0x40) != 0 {
80-
result |= (!0 as u64) << shift;
80+
result |= (!0u64) << shift;
8181
}
8282
result as i64
8383
}

0 commit comments

Comments
 (0)