Skip to content

Commit

Permalink
Remove some now-unnecessary casts of |size_t| to |usize|.
Browse files Browse the repository at this point in the history
I didn't try to find every such cast. I concentrated on the files that
had now-unnecessary casts from |usize| to |size_t|.
  • Loading branch information
briansmith committed Oct 22, 2015
1 parent e2311fc commit 5864ba9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/liballoc_jemalloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) }
}
4 changes: 2 additions & 2 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
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<u8> = Vec::with_capacity(sz as usize);
let mut v: Vec<u8> = 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)))
}
}
Expand Down Expand Up @@ -252,10 +252,10 @@ pub fn current_exe() -> io::Result<PathBuf> {
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<u8> = Vec::with_capacity(sz as usize);
let mut v: Vec<u8> = 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)))
}
}
Expand Down Expand Up @@ -479,7 +479,7 @@ pub fn home_dir() -> Option<PathBuf> {
target_os = "ios")))]
unsafe fn fallback() -> Option<OsString> {
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();
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,16 @@ 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) },
}
}

// No point in looking up __pthread_get_minstack() on non-glibc
// 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 {
Expand Down

0 comments on commit 5864ba9

Please sign in to comment.