Skip to content

Commit f164567

Browse files
committed
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|.
1 parent 62aaa30 commit f164567

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/liballoc_jemalloc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize,
8181
pub extern fn __rust_reallocate_inplace(ptr: *mut u8, _old_size: usize,
8282
size: usize, align: usize) -> usize {
8383
let flags = align_to_flags(align);
84-
unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) as usize }
84+
unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) }
8585
}
8686

8787
#[no_mangle]
@@ -93,5 +93,5 @@ pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
9393
#[no_mangle]
9494
pub extern fn __rust_usable_size(size: usize, align: usize) -> usize {
9595
let flags = align_to_flags(align);
96-
unsafe { je_nallocx(size, flags) as usize }
96+
unsafe { je_nallocx(size, flags) }
9797
}

src/liblibc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4749,7 +4749,7 @@ pub mod consts {
47494749

47504750
pub const PTHREAD_CREATE_JOINABLE : c_int = 0;
47514751
pub const PTHREAD_CREATE_DETACHED : c_int = 1;
4752-
pub const PTHREAD_STACK_MIN : size_t = 2048;
4752+
pub const PTHREAD_STACK_MIN: size_t = 2048;
47534753

47544754
pub const CLOCK_REALTIME : c_int = 0;
47554755
pub const CLOCK_MONOTONIC : c_int = 3;

src/libstd/sys/unix/os.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
196196
ptr::null_mut(), &mut sz, ptr::null_mut(), 0);
197197
if err != 0 { return Err(io::Error::last_os_error()); }
198198
if sz == 0 { return Err(io::Error::last_os_error()); }
199-
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
199+
let mut v: Vec<u8> = Vec::with_capacity(sz);
200200
let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
201201
v.as_mut_ptr() as *mut libc::c_void, &mut sz,
202202
ptr::null_mut(), 0);
203203
if err != 0 { return Err(io::Error::last_os_error()); }
204204
if sz == 0 { return Err(io::Error::last_os_error()); }
205-
v.set_len(sz as usize - 1); // chop off trailing NUL
205+
v.set_len(sz - 1); // chop off trailing NUL
206206
Ok(PathBuf::from(OsString::from_vec(v)))
207207
}
208208
}
@@ -246,10 +246,10 @@ pub fn current_exe() -> io::Result<PathBuf> {
246246
let mut sz: u32 = 0;
247247
_NSGetExecutablePath(ptr::null_mut(), &mut sz);
248248
if sz == 0 { return Err(io::Error::last_os_error()); }
249-
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
249+
let mut v: Vec<u8> = Vec::with_capacity(sz);
250250
let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
251251
if err != 0 { return Err(io::Error::last_os_error()); }
252-
v.set_len(sz as usize - 1); // chop off trailing NUL
252+
v.set_len(sz - 1); // chop off trailing NUL
253253
Ok(PathBuf::from(OsString::from_vec(v)))
254254
}
255255
}

src/libstd/sys/unix/thread.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,16 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize {
360360
});
361361

362362
match unsafe { __pthread_get_minstack } {
363-
None => PTHREAD_STACK_MIN as usize,
364-
Some(f) => unsafe { f(attr) as usize },
363+
None => PTHREAD_STACK_MIN,
364+
Some(f) => unsafe { f(attr) },
365365
}
366366
}
367367

368368
// No point in looking up __pthread_get_minstack() on non-glibc
369369
// platforms.
370370
#[cfg(not(target_os = "linux"))]
371371
fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
372-
PTHREAD_STACK_MIN as usize
372+
PTHREAD_STACK_MIN
373373
}
374374

375375
extern {

src/test/compile-fail/warn-foreign-int-types.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
mod xx {
1515
extern {
16-
pub fn strlen(str: *const u8) -> usize; //~ ERROR found Rust type `usize`
17-
pub fn foo(x: isize, y: usize); //~ ERROR found Rust type `isize`
18-
//~^ ERROR found Rust type `usize`
16+
pub fn strlen_good(str: *const u8) -> usize; // `usize` is OK.
17+
pub fn strlen_bad(str: *const char) -> usize; //~ ERROR found Rust type `char`
18+
pub fn foo(x: isize, y: usize); // `isize` is OK.
19+
pub fn bar(x: &[u8]); //~ ERROR found Rust slice type
20+
//~^ ERROR found Rust type `char`
1921
}
2022
}
2123

0 commit comments

Comments
 (0)