Skip to content

Commit 5864ba9

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 e2311fc commit 5864ba9

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/liballoc_jemalloc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
9797
align: usize)
9898
-> usize {
9999
let flags = align_to_flags(align);
100-
unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) as usize }
100+
unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) }
101101
}
102102

103103
#[no_mangle]
@@ -109,5 +109,5 @@ pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize)
109109
#[no_mangle]
110110
pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
111111
let flags = align_to_flags(align);
112-
unsafe { je_nallocx(size, flags) as usize }
112+
unsafe { je_nallocx(size, flags) }
113113
}

src/libstd/ffi/c_str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl CString {
232232
#[stable(feature = "cstr_memory", since = "1.4.0")]
233233
pub unsafe fn from_raw(ptr: *mut libc::c_char) -> CString {
234234
let len = libc::strlen(ptr) + 1; // Including the NUL byte
235-
let slice = slice::from_raw_parts(ptr, len as usize);
235+
let slice = slice::from_raw_parts(ptr, len);
236236
CString { inner: mem::transmute(slice) }
237237
}
238238

@@ -447,7 +447,7 @@ impl CStr {
447447
#[stable(feature = "rust1", since = "1.0.0")]
448448
pub unsafe fn from_ptr<'a>(ptr: *const libc::c_char) -> &'a CStr {
449449
let len = libc::strlen(ptr);
450-
mem::transmute(slice::from_raw_parts(ptr, len as usize + 1))
450+
mem::transmute(slice::from_raw_parts(ptr, len + 1))
451451
}
452452

453453
/// Returns the inner pointer to this C string.

src/libstd/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1642,8 +1642,8 @@ mod tests {
16421642
let stem = f.file_stem().unwrap().to_str().unwrap();
16431643
let root = stem.as_bytes()[0] - b'0';
16441644
let name = stem.as_bytes()[1] - b'0';
1645-
assert!(cur[root as usize] < name);
1646-
cur[root as usize] = name;
1645+
assert!(cur[root] < name);
1646+
cur[root] = name;
16471647
}
16481648

16491649
check!(fs::remove_dir_all(dir));

src/libstd/sys/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl fmt::Debug for File {
388388
return None;
389389
}
390390
let l = buf.iter().position(|&c| c == 0).unwrap();
391-
buf.truncate(l as usize);
391+
buf.truncate(l);
392392
buf.shrink_to_fit();
393393
Some(PathBuf::from(OsString::from_vec(buf)))
394394
}

src/libstd/sys/unix/os.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
197197
0 as libc::size_t);
198198
if err != 0 { return Err(io::Error::last_os_error()); }
199199
if sz == 0 { return Err(io::Error::last_os_error()); }
200-
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
200+
let mut v: Vec<u8> = Vec::with_capacity(sz);
201201
let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
202202
v.as_mut_ptr() as *mut libc::c_void, &mut sz,
203203
ptr::null_mut(), 0 as libc::size_t);
204204
if err != 0 { return Err(io::Error::last_os_error()); }
205205
if sz == 0 { return Err(io::Error::last_os_error()); }
206-
v.set_len(sz as usize - 1); // chop off trailing NUL
206+
v.set_len(sz - 1); // chop off trailing NUL
207207
Ok(PathBuf::from(OsString::from_vec(v)))
208208
}
209209
}
@@ -252,10 +252,10 @@ pub fn current_exe() -> io::Result<PathBuf> {
252252
let mut sz: u32 = 0;
253253
_NSGetExecutablePath(ptr::null_mut(), &mut sz);
254254
if sz == 0 { return Err(io::Error::last_os_error()); }
255-
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
255+
let mut v: Vec<u8> = Vec::with_capacity(sz);
256256
let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
257257
if err != 0 { return Err(io::Error::last_os_error()); }
258-
v.set_len(sz as usize - 1); // chop off trailing NUL
258+
v.set_len(sz - 1); // chop off trailing NUL
259259
Ok(PathBuf::from(OsString::from_vec(v)))
260260
}
261261
}
@@ -479,7 +479,7 @@ pub fn home_dir() -> Option<PathBuf> {
479479
target_os = "ios")))]
480480
unsafe fn fallback() -> Option<OsString> {
481481
let amt = match libc::sysconf(c::_SC_GETPW_R_SIZE_MAX) {
482-
n if n < 0 => 512 as usize,
482+
n if n < 0 => 512usize,
483483
n => n as usize,
484484
};
485485
let me = libc::getuid();

src/libstd/sys/unix/thread.rs

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

379379
match unsafe { __pthread_get_minstack } {
380-
None => PTHREAD_STACK_MIN as usize,
381-
Some(f) => unsafe { f(attr) as usize },
380+
None => PTHREAD_STACK_MIN,
381+
Some(f) => unsafe { f(attr) },
382382
}
383383
}
384384

385385
// No point in looking up __pthread_get_minstack() on non-glibc
386386
// platforms.
387387
#[cfg(not(target_os = "linux"))]
388388
fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
389-
PTHREAD_STACK_MIN as usize
389+
PTHREAD_STACK_MIN
390390
}
391391

392392
extern {

0 commit comments

Comments
 (0)