From 5864ba9e26653780a2325357ab1fd42a7e121307 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 30 Aug 2015 14:42:23 -0700 Subject: [PATCH] Remove some now-unnecessary casts of |size_t| to |usize|. I didn't try to find every such cast. I concentrated on the files that had now-unnecessary casts from |usize| to |size_t|. --- src/liballoc_jemalloc/lib.rs | 4 ++-- src/libstd/ffi/c_str.rs | 4 ++-- src/libstd/fs.rs | 4 ++-- src/libstd/sys/unix/fs.rs | 2 +- src/libstd/sys/unix/os.rs | 10 +++++----- src/libstd/sys/unix/thread.rs | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index 4fb1985070d09..0b28fad3dbb6f 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -97,7 +97,7 @@ pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8, align: usize) -> usize { let flags = align_to_flags(align); - unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) as usize } + unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) } } #[no_mangle] @@ -109,5 +109,5 @@ pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) #[no_mangle] pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { let flags = align_to_flags(align); - unsafe { je_nallocx(size, flags) as usize } + unsafe { je_nallocx(size, flags) } } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 89427f7851b38..e9bfde2e50c9f 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -232,7 +232,7 @@ impl CString { #[stable(feature = "cstr_memory", since = "1.4.0")] pub unsafe fn from_raw(ptr: *mut libc::c_char) -> CString { let len = libc::strlen(ptr) + 1; // Including the NUL byte - let slice = slice::from_raw_parts(ptr, len as usize); + let slice = slice::from_raw_parts(ptr, len); CString { inner: mem::transmute(slice) } } @@ -447,7 +447,7 @@ impl CStr { #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_ptr<'a>(ptr: *const libc::c_char) -> &'a CStr { let len = libc::strlen(ptr); - mem::transmute(slice::from_raw_parts(ptr, len as usize + 1)) + mem::transmute(slice::from_raw_parts(ptr, len + 1)) } /// Returns the inner pointer to this C string. diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 1da7a1502d92d..1e4da1c1aa9e1 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1642,8 +1642,8 @@ mod tests { let stem = f.file_stem().unwrap().to_str().unwrap(); let root = stem.as_bytes()[0] - b'0'; let name = stem.as_bytes()[1] - b'0'; - assert!(cur[root as usize] < name); - cur[root as usize] = name; + assert!(cur[root] < name); + cur[root] = name; } check!(fs::remove_dir_all(dir)); diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index ac414742f8b5d..c8623554d920a 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -388,7 +388,7 @@ impl fmt::Debug for File { return None; } let l = buf.iter().position(|&c| c == 0).unwrap(); - buf.truncate(l as usize); + buf.truncate(l); buf.shrink_to_fit(); Some(PathBuf::from(OsString::from_vec(buf))) } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index fa5057364e622..4602a92e3e62b 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -197,13 +197,13 @@ pub fn current_exe() -> io::Result { 0 as libc::size_t); if err != 0 { return Err(io::Error::last_os_error()); } if sz == 0 { return Err(io::Error::last_os_error()); } - let mut v: Vec = Vec::with_capacity(sz as usize); + let mut v: Vec = Vec::with_capacity(sz); let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, v.as_mut_ptr() as *mut libc::c_void, &mut sz, ptr::null_mut(), 0 as libc::size_t); if err != 0 { return Err(io::Error::last_os_error()); } if sz == 0 { return Err(io::Error::last_os_error()); } - v.set_len(sz as usize - 1); // chop off trailing NUL + v.set_len(sz - 1); // chop off trailing NUL Ok(PathBuf::from(OsString::from_vec(v))) } } @@ -252,10 +252,10 @@ pub fn current_exe() -> io::Result { let mut sz: u32 = 0; _NSGetExecutablePath(ptr::null_mut(), &mut sz); if sz == 0 { return Err(io::Error::last_os_error()); } - let mut v: Vec = Vec::with_capacity(sz as usize); + let mut v: Vec = Vec::with_capacity(sz); let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz); if err != 0 { return Err(io::Error::last_os_error()); } - v.set_len(sz as usize - 1); // chop off trailing NUL + v.set_len(sz - 1); // chop off trailing NUL Ok(PathBuf::from(OsString::from_vec(v))) } } @@ -479,7 +479,7 @@ pub fn home_dir() -> Option { target_os = "ios")))] unsafe fn fallback() -> Option { let amt = match libc::sysconf(c::_SC_GETPW_R_SIZE_MAX) { - n if n < 0 => 512 as usize, + n if n < 0 => 512usize, n => n as usize, }; let me = libc::getuid(); diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 6378360301ec3..79828be30bbd3 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -377,8 +377,8 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize { }); match unsafe { __pthread_get_minstack } { - None => PTHREAD_STACK_MIN as usize, - Some(f) => unsafe { f(attr) as usize }, + None => PTHREAD_STACK_MIN, + Some(f) => unsafe { f(attr) }, } } @@ -386,7 +386,7 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize { // platforms. #[cfg(not(target_os = "linux"))] fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { - PTHREAD_STACK_MIN as usize + PTHREAD_STACK_MIN } extern {