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 Sep 1, 2015
1 parent 62aaa30 commit f164567
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/liballoc_jemalloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize,
pub extern fn __rust_reallocate_inplace(ptr: *mut u8, _old_size: usize,
size: usize, 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 @@ -93,5 +93,5 @@ pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
#[no_mangle]
pub extern 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) }
}
2 changes: 1 addition & 1 deletion src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4749,7 +4749,7 @@ pub mod consts {

pub const PTHREAD_CREATE_JOINABLE : c_int = 0;
pub const PTHREAD_CREATE_DETACHED : c_int = 1;
pub const PTHREAD_STACK_MIN : size_t = 2048;
pub const PTHREAD_STACK_MIN: size_t = 2048;

pub const CLOCK_REALTIME : c_int = 0;
pub const CLOCK_MONOTONIC : c_int = 3;
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
ptr::null_mut(), &mut sz, ptr::null_mut(), 0);
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);
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 @@ -246,10 +246,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
6 changes: 3 additions & 3 deletions src/libstd/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,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
8 changes: 5 additions & 3 deletions src/test/compile-fail/warn-foreign-int-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

mod xx {
extern {
pub fn strlen(str: *const u8) -> usize; //~ ERROR found Rust type `usize`
pub fn foo(x: isize, y: usize); //~ ERROR found Rust type `isize`
//~^ ERROR found Rust type `usize`
pub fn strlen_good(str: *const u8) -> usize; // `usize` is OK.
pub fn strlen_bad(str: *const char) -> usize; //~ ERROR found Rust type `char`
pub fn foo(x: isize, y: usize); // `isize` is OK.
pub fn bar(x: &[u8]); //~ ERROR found Rust slice type
//~^ ERROR found Rust type `char`
}
}

Expand Down

0 comments on commit f164567

Please sign in to comment.