Fix Clippy warnings

This commit is contained in:
Mateusz Mikuła
2019-05-10 12:01:02 +02:00
parent 30f6a9c323
commit 7597c082e7
20 changed files with 115 additions and 126 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ pub const L_tmpnam: c_int = 7;
pub const TMP_MAX: int32_t = 2_147_483_647;
// XXX: defined manually in bits/stdio.h as well because cbindgen can't handle
// string constants in any form AFAICT
pub const P_tmpdir: &'static [u8; 5] = b"/tmp\0";
pub const P_tmpdir: &[u8; 5] = b"/tmp\0";
#[allow(non_camel_case_types)]
pub type fpos_t = off_t;
+5 -5
View File
@@ -319,7 +319,7 @@ pub unsafe extern "C" fn fgets(
// TODO: When NLL is a thing, this block can be flattened out
let (read, exit) = {
let mut buf = match stream.fill_buf() {
let buf = match stream.fill_buf() {
Ok(buf) => buf,
Err(_) => return ptr::null_mut(),
};
@@ -580,7 +580,7 @@ pub unsafe extern "C" fn fwrite(
let buf = slice::from_raw_parts_mut(ptr as *mut u8, size as usize * nitems as usize);
let mut written = 0;
while written < buf.len() {
match stream.write(&mut buf[written..]) {
match stream.write(&buf[written..]) {
Ok(0) | Err(_) => break,
Ok(n) => written += n,
}
@@ -885,8 +885,8 @@ pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut
let dirname = {
let tmpdir = stdlib::getenv(b"TMPDIR\0".as_ptr() as _);
[tmpdir, dir, P_tmpdir.as_ptr() as _]
.into_iter()
.map(|&d| d)
.iter()
.copied()
.skip_while(|&d| !is_appropriate(d))
.next()
.unwrap_or(b"/tmp\0".as_ptr() as _)
@@ -934,7 +934,7 @@ pub unsafe extern "C" fn tmpfile() -> *mut FILE {
Sys::unlink(file_name);
}
if fp == ptr::null_mut() {
if fp.is_null() {
Sys::close(fd);
}
+23 -22
View File
@@ -307,7 +307,7 @@ fn float_string(float: c_double, precision: usize, trim: bool) -> String {
let mut string = format!("{:.p$}", float, p = precision);
if trim {
let truncate = {
let mut slice = string.trim_end_matches('0');
let slice = string.trim_end_matches('0');
if slice.ends_with('.') {
slice.len() - 1
} else {
@@ -678,22 +678,23 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
// add an extra zero if octal.
let no_precision = precision.map(|pad| pad < string.len()).unwrap_or(true);
let mut len = string.len();
let mut final_len = string.len().max(precision.unwrap_or(0))
+ if alternate && string != "0" {
match fmt {
b'o' if no_precision => 1,
b'x' | b'X' => 2,
_ => 0,
}
} else {
0
};
if zero {
let len;
let final_len = if zero {
len = 0;
final_len = 0;
}
0
} else {
len = string.len();
len.max(precision.unwrap_or(0))
+ if alternate && string != "0" {
match fmt {
b'o' if no_precision => 1,
b'x' | b'X' => 2,
_ => 0,
}
} else {
0
}
};
pad(w, !left, b' ', final_len..pad_space)?;
@@ -714,7 +715,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
pad(w, left, b' ', final_len..pad_space)?;
}
FmtKind::Scientific => {
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
let float = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::c_double(i) => i,
_ => panic!("this should not be possible"),
};
@@ -725,7 +726,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
)?;
}
FmtKind::Decimal => {
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
let float = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::c_double(i) => i,
_ => panic!("this should not be possible"),
};
@@ -734,7 +735,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
fmt_float_normal(w, false, precision, float, left, pad_space, pad_zero)?;
}
FmtKind::AnyNotation => {
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
let float = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::c_double(i) => i,
_ => panic!("this should not be possible"),
};
@@ -758,7 +759,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
FmtKind::String => {
// if intkind == IntKind::Long || intkind == IntKind::LongLong, handle *const wchar_t
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::pointer(p) => p,
_ => panic!("this should not be possible"),
} as *const c_char;
@@ -790,7 +791,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
pad(w, left, b' ', 1..pad_space)?;
}
FmtKind::Pointer => {
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::pointer(p) => p,
_ => panic!("this should not be possible"),
};
@@ -815,7 +816,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
pad(w, left, b' ', len..pad_space)?;
}
FmtKind::GetWritten => {
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::pointer(p) => p,
_ => panic!("this should not be possible"),
};
+6 -5
View File
@@ -349,7 +349,7 @@ unsafe fn inner_scanf<R: Read>(
}
}
b'c' => {
let mut ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.arg()) };
let ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.arg()) };
for i in 0..width.unwrap_or(1) {
if let Some(ptr) = ptr {
@@ -370,11 +370,12 @@ unsafe fn inner_scanf<R: Read>(
c = next_byte(&mut format)?;
let mut matches = Vec::new();
let mut invert = false;
if c == b'^' {
let invert = if c == b'^' {
c = next_byte(&mut format)?;
invert = true;
}
true
} else {
false
};
let mut prev;
loop {