Skip to content

Commit 62aaa30

Browse files
committed
Remove now-unnecessary casts of |usize| to |size_t|.
1 parent 426da6c commit 62aaa30

File tree

19 files changed

+45
-64
lines changed

19 files changed

+45
-64
lines changed

src/compiletest/raise_fd_limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub unsafe fn raise_fd_limit() {
5050
// Fetch the kern.maxfilesperproc value
5151
let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC];
5252
let mut maxfiles: libc::c_int = 0;
53-
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
53+
let mut size = size_of_val(&maxfiles);
5454
if sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size,
5555
null_mut(), 0) != 0 {
5656
let err = io::Error::last_os_error();

src/liballoc_jemalloc/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,31 @@ fn align_to_flags(align: usize) -> c_int {
6767
#[no_mangle]
6868
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
6969
let flags = align_to_flags(align);
70-
unsafe { je_mallocx(size as size_t, flags) as *mut u8 }
70+
unsafe { je_mallocx(size, flags) as *mut u8 }
7171
}
7272

7373
#[no_mangle]
7474
pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize,
7575
align: usize) -> *mut u8 {
7676
let flags = align_to_flags(align);
77-
unsafe { je_rallocx(ptr as *mut c_void, size as size_t, flags) as *mut u8 }
77+
unsafe { je_rallocx(ptr as *mut c_void, size, flags) as *mut u8 }
7878
}
7979

8080
#[no_mangle]
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 as size_t, 0, flags) as usize }
84+
unsafe { je_xallocx(ptr as *mut c_void, size, 0, flags) as usize }
8585
}
8686

8787
#[no_mangle]
8888
pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
8989
let flags = align_to_flags(align);
90-
unsafe { je_sdallocx(ptr as *mut c_void, old_size as size_t, flags) }
90+
unsafe { je_sdallocx(ptr as *mut c_void, old_size, flags) }
9191
}
9292

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 as size_t, flags) as usize }
96+
unsafe { je_nallocx(size, flags) as usize }
9797
}

src/liballoc_system/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,16 @@ mod imp {
8585

8686
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
8787
if align <= MIN_ALIGN {
88-
libc::malloc(size as libc::size_t) as *mut u8
88+
libc::malloc(size) as *mut u8
8989
} else {
9090
#[cfg(target_os = "android")]
9191
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
92-
memalign(align as libc::size_t, size as libc::size_t) as *mut u8
92+
memalign(align, size) as *mut u8
9393
}
9494
#[cfg(not(target_os = "android"))]
9595
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
9696
let mut out = ptr::null_mut();
97-
let ret = posix_memalign(&mut out,
98-
align as libc::size_t,
99-
size as libc::size_t);
97+
let ret = posix_memalign(&mut out, align, size);
10098
if ret != 0 {
10199
ptr::null_mut()
102100
} else {
@@ -110,7 +108,7 @@ mod imp {
110108
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize,
111109
align: usize) -> *mut u8 {
112110
if align <= MIN_ALIGN {
113-
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
111+
libc::realloc(ptr as *mut libc::c_void, size) as *mut u8
114112
} else {
115113
let new_ptr = allocate(size, align);
116114
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));

src/libflate/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Bytes {
102102
unsafe {
103103
let mut outsz: size_t = 0;
104104
let res = tdefl_compress_mem_to_heap(bytes.as_ptr() as *const _,
105-
bytes.len() as size_t,
106-
&mut outsz,
107-
flags);
105+
bytes.len(), &mut outsz, flags);
108106
assert!(!res.is_null());
109107
Bytes {
110108
ptr: Unique::new(res as *mut u8),
@@ -127,9 +125,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Result<Bytes,Error> {
127125
unsafe {
128126
let mut outsz: size_t = 0;
129127
let res = tinfl_decompress_mem_to_heap(bytes.as_ptr() as *const _,
130-
bytes.len() as size_t,
131-
&mut outsz,
132-
flags);
128+
bytes.len(), &mut outsz, flags);
133129
if !res.is_null() {
134130
Ok(Bytes {
135131
ptr: Unique::new(res as *mut u8),

src/librustc_trans/back/archive.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::path::{Path, PathBuf};
2020
use std::process::{Command, Output, Stdio};
2121
use std::str;
2222

23-
use libc;
2423
use llvm::archive_ro::{ArchiveRO, Child};
2524
use llvm::{self, ArchiveKind};
2625
use rustc::metadata::loader::METADATA_FILENAME;
@@ -485,8 +484,7 @@ impl<'a> ArchiveBuilder<'a> {
485484

486485
let dst = self.config.dst.to_str().unwrap().as_bytes();
487486
let dst = try!(CString::new(dst));
488-
let r = llvm::LLVMRustWriteArchive(dst.as_ptr(),
489-
members.len() as libc::size_t,
487+
let r = llvm::LLVMRustWriteArchive(dst.as_ptr(), members.len(),
490488
members.as_ptr(),
491489
self.should_update_symbols,
492490
kind);

src/librustc_trans/back/lto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
9797
time(sess.time_passes(), &format!("ll link {}", name), || unsafe {
9898
if !llvm::LLVMRustLinkInExternalBitcode(llmod,
9999
ptr as *const libc::c_char,
100-
bc_decoded.len() as libc::size_t) {
100+
bc_decoded.len()) {
101101
write::llvm_err(sess.diagnostic().handler(),
102102
format!("failed to load bc of `{}`",
103103
&name[..]));
@@ -115,7 +115,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
115115
unsafe {
116116
llvm::LLVMRustRunRestrictionPass(llmod,
117117
ptr as *const *const libc::c_char,
118-
arr.len() as libc::size_t);
118+
arr.len());
119119
}
120120

121121
if sess.no_landing_pads() {

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
361361
(*renderer).codespan = Some(codespan);
362362

363363
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
364-
hoedown_document_render(document, ob, s.as_ptr(),
365-
s.len() as libc::size_t);
364+
hoedown_document_render(document, ob, s.as_ptr(), s.len());
366365
hoedown_document_free(document);
367366

368367
hoedown_html_renderer_free(renderer);
@@ -435,8 +434,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
435434
= tests as *mut _ as *mut libc::c_void;
436435

437436
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
438-
hoedown_document_render(document, ob, doc.as_ptr(),
439-
doc.len() as libc::size_t);
437+
hoedown_document_render(document, ob, doc.as_ptr(), doc.len());
440438
hoedown_document_free(document);
441439

442440
hoedown_html_renderer_free(renderer);
@@ -556,8 +554,7 @@ pub fn plain_summary_line(md: &str) -> String {
556554
(*renderer).normal_text = Some(normal_text);
557555

558556
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
559-
hoedown_document_render(document, ob, md.as_ptr(),
560-
md.len() as libc::size_t);
557+
hoedown_document_render(document, ob, md.as_ptr(), md.len());
561558
hoedown_document_free(document);
562559
let plain_slice = (*ob).as_bytes();
563560
let plain = match str::from_utf8(plain_slice) {

src/libstd/primitive_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod prim_unit { }
136136
///
137137
/// fn main() {
138138
/// unsafe {
139-
/// let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>() as libc::size_t) as *mut i32;
139+
/// let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>()) as *mut i32;
140140
/// if my_num.is_null() {
141141
/// panic!("failed to allocate memory");
142142
/// }

src/libstd/rand/os.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ mod imp {
235235
}
236236
fn fill_bytes(&mut self, v: &mut [u8]) {
237237
let ret = unsafe {
238-
SecRandomCopyBytes(kSecRandomDefault, v.len() as size_t,
239-
v.as_mut_ptr())
238+
SecRandomCopyBytes(kSecRandomDefault, v.len(), v.as_mut_ptr())
240239
};
241240
if ret == -1 {
242241
panic!("couldn't generate random bytes: {}",

src/libstd/sys/common/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> {
153153

154154
let data = unsafe {
155155
try!(cvt_gai(getnameinfo(inner, len,
156-
hostbuf.as_mut_ptr(), NI_MAXHOST as libc::size_t,
157-
0 as *mut _, 0, 0)));
156+
hostbuf.as_mut_ptr(), NI_MAXHOST, 0 as *mut _,
157+
0, 0)));
158158

159159
CStr::from_ptr(hostbuf.as_ptr())
160160
};

src/libstd/sys/unix/fd.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use io;
12-
use libc::{self, c_int, size_t, c_void};
12+
use libc::{self, c_int, c_void};
1313
use mem;
1414
use sys::c;
1515
use sys::cvt;
@@ -35,18 +35,14 @@ impl FileDesc {
3535

3636
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
3737
let ret = try!(cvt(unsafe {
38-
libc::read(self.fd,
39-
buf.as_mut_ptr() as *mut c_void,
40-
buf.len() as size_t)
38+
libc::read(self.fd, buf.as_mut_ptr() as *mut c_void, buf.len())
4139
}));
4240
Ok(ret as usize)
4341
}
4442

4543
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
4644
let ret = try!(cvt(unsafe {
47-
libc::write(self.fd,
48-
buf.as_ptr() as *const c_void,
49-
buf.len() as size_t)
45+
libc::write(self.fd, buf.as_ptr() as *const c_void, buf.len())
5046
}));
5147
Ok(ret as usize)
5248
}

src/libstd/sys/unix/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use os::unix::prelude::*;
1414
use ffi::{CString, CStr, OsString, OsStr};
1515
use fmt;
1616
use io::{self, Error, ErrorKind, SeekFrom};
17-
use libc::{self, c_int, size_t, off_t, c_char, mode_t};
17+
use libc::{self, c_int, off_t, c_char, mode_t};
1818
use mem;
1919
use path::{Path, PathBuf};
2020
use ptr;
@@ -477,7 +477,7 @@ pub fn readlink(p: &Path) -> io::Result<PathBuf> {
477477

478478
loop {
479479
let buf_read = try!(cvt(unsafe {
480-
libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity() as libc::size_t)
480+
libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity())
481481
})) as usize;
482482

483483
unsafe { buf.set_len(buf_read); }

src/libstd/sys/unix/os.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn error_string(errno: i32) -> String {
8383

8484
let p = buf.as_mut_ptr();
8585
unsafe {
86-
if strerror_r(errno as c_int, p, buf.len() as libc::size_t) < 0 {
86+
if strerror_r(errno as c_int, p, buf.len()) < 0 {
8787
panic!("strerror_r failure");
8888
}
8989

@@ -97,7 +97,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
9797
loop {
9898
unsafe {
9999
let ptr = buf.as_mut_ptr() as *mut libc::c_char;
100-
if !libc::getcwd(ptr, buf.capacity() as libc::size_t).is_null() {
100+
if !libc::getcwd(ptr, buf.capacity()).is_null() {
101101
let len = CStr::from_ptr(buf.as_ptr() as *const libc::c_char).to_bytes().len();
102102
buf.set_len(len);
103103
buf.shrink_to_fit();
@@ -193,14 +193,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
193193
-1 as c_int];
194194
let mut sz: libc::size_t = 0;
195195
let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
196-
ptr::null_mut(), &mut sz, ptr::null_mut(),
197-
0 as libc::size_t);
196+
ptr::null_mut(), &mut sz, ptr::null_mut(), 0);
198197
if err != 0 { return Err(io::Error::last_os_error()); }
199198
if sz == 0 { return Err(io::Error::last_os_error()); }
200199
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
201200
let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
202201
v.as_mut_ptr() as *mut libc::c_void, &mut sz,
203-
ptr::null_mut(), 0 as libc::size_t);
202+
ptr::null_mut(), 0);
204203
if err != 0 { return Err(io::Error::last_os_error()); }
205204
if sz == 0 { return Err(io::Error::last_os_error()); }
206205
v.set_len(sz as usize - 1); // chop off trailing NUL
@@ -483,8 +482,7 @@ pub fn home_dir() -> Option<PathBuf> {
483482
let mut passwd: c::passwd = mem::zeroed();
484483
let mut result = 0 as *mut _;
485484
match c::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(),
486-
buf.capacity() as libc::size_t,
487-
&mut result) {
485+
buf.capacity(), &mut result) {
488486
0 if !result.is_null() => {}
489487
_ => return None
490488
}

src/libstd/sys/unix/thread.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Thread {
4343
assert_eq!(pthread_attr_init(&mut attr), 0);
4444

4545
let stack_size = cmp::max(stack, min_stack_size(&attr));
46-
match pthread_attr_setstacksize(&mut attr, stack_size as libc::size_t) {
46+
match pthread_attr_setstacksize(&mut attr, stack_size) {
4747
0 => {}
4848
n => {
4949
assert_eq!(n, libc::EINVAL);
@@ -54,7 +54,7 @@ impl Thread {
5454
let page_size = os::page_size();
5555
let stack_size = (stack_size + page_size - 1) &
5656
(-(page_size as isize - 1) as usize - 1);
57-
let stack_size = stack_size as libc::size_t;
57+
let stack_size = stack_size;
5858
assert_eq!(pthread_attr_setstacksize(&mut attr, stack_size), 0);
5959
}
6060
};
@@ -238,7 +238,7 @@ pub mod guard {
238238
// This ensures SIGBUS will be raised on
239239
// stack overflow.
240240
let result = mmap(stackaddr,
241-
psize as libc::size_t,
241+
psize,
242242
PROT_NONE,
243243
MAP_PRIVATE | MAP_ANON | MAP_FIXED,
244244
-1,
@@ -259,7 +259,7 @@ pub mod guard {
259259
fn pthread_get_stackaddr_np(thread: pthread_t) -> *mut libc::c_void;
260260
fn pthread_get_stacksize_np(thread: pthread_t) -> libc::size_t;
261261
}
262-
Some((pthread_get_stackaddr_np(pthread_self()) as libc::size_t -
262+
Some((pthread_get_stackaddr_np(pthread_self()) -
263263
pthread_get_stacksize_np(pthread_self())) as usize)
264264
}
265265

src/libstd/sys/windows/thread.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl Thread {
3737
// Round up to the next 64 kB because that's what the NT kernel does,
3838
// might as well make it explicit.
3939
let stack_size = (stack + 0xfffe) & (!0xfffe);
40-
let ret = c::CreateThread(ptr::null_mut(), stack_size as libc::size_t,
41-
thread_start, &*p as *const _ as *mut _,
42-
0, ptr::null_mut());
40+
let ret = c::CreateThread(ptr::null_mut(), stack_size, thread_start,
41+
&*p as *const _ as *mut _, 0,
42+
ptr::null_mut());
4343

4444
return if ret as usize == 0 {
4545
Err(io::Error::last_os_error())

src/test/auxiliary/allocator-dummy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub static mut HITS: usize = 0;
2323
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
2424
unsafe {
2525
HITS += 1;
26-
libc::malloc(size as libc::size_t) as *mut u8
26+
libc::malloc(size) as *mut u8
2727
}
2828
}
2929

@@ -39,7 +39,7 @@ pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
3939
pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize,
4040
align: usize) -> *mut u8 {
4141
unsafe {
42-
libc::realloc(ptr as *mut _, size as libc::size_t) as *mut u8
42+
libc::realloc(ptr as *mut _, size) as *mut u8
4343
}
4444
}
4545

src/test/bench/shootout-reverse-complement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ impl Tables {
103103

104104
/// Finds the first position at which `b` occurs in `s`.
105105
fn memchr(h: &[u8], n: u8) -> Option<usize> {
106-
use libc::{c_void, c_int, size_t};
106+
use libc::{c_void, c_int};
107107
let res = unsafe {
108-
libc::memchr(h.as_ptr() as *const c_void, n as c_int, h.len() as size_t)
108+
libc::memchr(h.as_ptr() as *const c_void, n as c_int, h.len())
109109
};
110110
if res.is_null() {
111111
None

src/test/run-pass/regions-mock-trans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ struct Ccx {
3232

3333
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
3434
unsafe {
35-
mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
36-
as libc::size_t))
35+
mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()))
3736
}
3837
}
3938

0 commit comments

Comments
 (0)