From dffc1b32820d740b3e2b3cf8e98b4d0511a62163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 5 Sep 2019 12:23:56 +0200 Subject: [PATCH 1/5] Apply clippy::useless_let_if_seq suggestion --- src/libcore/num/dec2flt/algorithm.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libcore/num/dec2flt/algorithm.rs b/src/libcore/num/dec2flt/algorithm.rs index fa3c8075378c..ed89852dc48d 100644 --- a/src/libcore/num/dec2flt/algorithm.rs +++ b/src/libcore/num/dec2flt/algorithm.rs @@ -143,13 +143,12 @@ pub fn fast_path(integral: &[u8], fractional: &[u8], e: i64) -> Opt /// > not a bound for the true error, but bounds the difference between the approximation z and /// > the best possible approximation that uses p bits of significand.) pub fn bellerophon(f: &Big, e: i16) -> T { - let slop; - if f <= &Big::from_u64(T::MAX_SIG) { + let slop = if f <= &Big::from_u64(T::MAX_SIG) { // The cases abs(e) < log5(2^N) are in fast_path() - slop = if e >= 0 { 0 } else { 3 }; + if e >= 0 { 0 } else { 3 } } else { - slop = if e >= 0 { 1 } else { 4 }; - } + if e >= 0 { 1 } else { 4 } + }; let z = rawfp::big_to_fp(f).mul(&power_of_ten(e)).normalize(); let exp_p_n = 1 << (P - T::SIG_BITS as u32); let lowbits: i64 = (z.f % exp_p_n) as i64; From 95c06a29707c8b2f811495c05b0cd009743e29de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 5 Sep 2019 13:30:30 +0200 Subject: [PATCH 2/5] Apply clippy::needless_return suggestions --- src/liballoc/collections/vec_deque.rs | 2 +- src/liballoc/str.rs | 2 +- src/liballoc/sync.rs | 2 +- src/libpanic_unwind/gcc.rs | 12 ++++++------ src/libpanic_unwind/seh64_gnu.rs | 2 +- src/libstd/panicking.rs | 2 +- src/libstd/sys/unix/rand.rs | 2 +- src/libstd/sys/windows/handle.rs | 2 +- src/libstd/sys/windows/mutex.rs | 2 +- src/libstd/sys/windows/process.rs | 2 +- src/libstd/sys/windows/rand.rs | 2 +- src/libstd/sys/windows/thread_local.rs | 2 +- src/libstd/sys/windows/time.rs | 4 ++-- src/libtest/bench.rs | 4 ++-- src/libtest/cli.rs | 2 +- src/libtest/console.rs | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 0bf573f5e253..8f3dfabd8886 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -1817,7 +1817,7 @@ impl VecDeque { } } - return elem; + elem } /// Splits the `VecDeque` into two at the given index. diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 9231c2d3f1d5..83816d8b954c 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -456,7 +456,7 @@ impl str { } } } - return s; + s } /// Converts a [`Box`] into a [`String`] without copying or allocating. diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 69f8f71197c1..80d6c6e0d439 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1638,7 +1638,7 @@ impl Clone for Weak { } } - return Weak { ptr: self.ptr }; + Weak { ptr: self.ptr } } } diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs index 236ed1505057..a35847c85fc2 100644 --- a/src/libpanic_unwind/gcc.rs +++ b/src/libpanic_unwind/gcc.rs @@ -156,21 +156,21 @@ unsafe extern "C" fn rust_eh_personality(version: c_int, if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 { match eh_action { EHAction::None | - EHAction::Cleanup(_) => return uw::_URC_CONTINUE_UNWIND, - EHAction::Catch(_) => return uw::_URC_HANDLER_FOUND, - EHAction::Terminate => return uw::_URC_FATAL_PHASE1_ERROR, + EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND, + EHAction::Catch(_) => uw::_URC_HANDLER_FOUND, + EHAction::Terminate => uw::_URC_FATAL_PHASE1_ERROR, } } else { match eh_action { - EHAction::None => return uw::_URC_CONTINUE_UNWIND, + EHAction::None => uw::_URC_CONTINUE_UNWIND, EHAction::Cleanup(lpad) | EHAction::Catch(lpad) => { uw::_Unwind_SetGR(context, UNWIND_DATA_REG.0, exception_object as uintptr_t); uw::_Unwind_SetGR(context, UNWIND_DATA_REG.1, 0); uw::_Unwind_SetIP(context, lpad); - return uw::_URC_INSTALL_CONTEXT; + uw::_URC_INSTALL_CONTEXT } - EHAction::Terminate => return uw::_URC_FATAL_PHASE2_ERROR, + EHAction::Terminate => uw::_URC_FATAL_PHASE2_ERROR, } } } diff --git a/src/libpanic_unwind/seh64_gnu.rs b/src/libpanic_unwind/seh64_gnu.rs index 457ffcd34f9c..16b699a44379 100644 --- a/src/libpanic_unwind/seh64_gnu.rs +++ b/src/libpanic_unwind/seh64_gnu.rs @@ -46,7 +46,7 @@ pub fn payload() -> *mut u8 { pub unsafe fn cleanup(ptr: *mut u8) -> Box { let panic_ctx = Box::from_raw(ptr as *mut PanicData); - return panic_ctx.data; + panic_ctx.data } // SEH doesn't support resuming unwinds after calling a landing pad like diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 2dde81bb0ecd..619b18201908 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -217,7 +217,7 @@ pub fn update_panic_count(amt: isize) -> usize { PANIC_COUNT.with(|c| { let next = (c.get() as isize + amt) as usize; c.set(next); - return next + next }) } diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index c5be17633025..be112f6fc032 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -8,7 +8,7 @@ pub fn hashmap_random_keys() -> (u64, u64) { mem::size_of_val(&v)); imp::fill_bytes(view); } - return v + v } #[cfg(all(unix, diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index 3e5aa6933546..3986cda1a504 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -46,7 +46,7 @@ impl Handle { pub fn into_raw(self) -> c::HANDLE { let ret = self.raw(); mem::forget(self); - return ret; + ret } } diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 37cbdcefcedc..79dec1adf4bc 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -144,7 +144,7 @@ fn kind() -> Kind { Some(..) => Kind::SRWLock, }; KIND.store(ret as usize, Ordering::SeqCst); - return ret; + ret } pub struct ReentrantMutex { inner: UnsafeCell> } diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 8658deb85463..61393680883f 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -257,7 +257,7 @@ impl Stdio { let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS); io.into_raw(); - return ret + ret } Err(..) => Ok(Handle::new(c::INVALID_HANDLE_VALUE)), } diff --git a/src/libstd/sys/windows/rand.rs b/src/libstd/sys/windows/rand.rs index c9bcb5d74151..993831bec188 100644 --- a/src/libstd/sys/windows/rand.rs +++ b/src/libstd/sys/windows/rand.rs @@ -13,7 +13,7 @@ pub fn hashmap_random_keys() -> (u64, u64) { panic!("couldn't generate random bytes: {}", io::Error::last_os_error()); } - return v + v } #[cfg(target_vendor = "uwp")] diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 4c9734fa0aa6..728257cdd4bb 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -52,7 +52,7 @@ pub unsafe fn create(dtor: Option) -> Key { if let Some(f) = dtor { register_dtor(key, f); } - return key; + key } #[inline] diff --git a/src/libstd/sys/windows/time.rs b/src/libstd/sys/windows/time.rs index e0f0e3a1a45b..bd533c93d434 100644 --- a/src/libstd/sys/windows/time.rs +++ b/src/libstd/sys/windows/time.rs @@ -80,7 +80,7 @@ impl SystemTime { unsafe { let mut t: SystemTime = mem::zeroed(); c::GetSystemTimeAsFileTime(&mut t.t); - return t + t } } @@ -228,7 +228,7 @@ mod perf_counter { FREQUENCY = frequency; STATE.store(2, SeqCst); } - return frequency; + frequency } } diff --git a/src/libtest/bench.rs b/src/libtest/bench.rs index c142c5213d2e..c86bfd16c21b 100644 --- a/src/libtest/bench.rs +++ b/src/libtest/bench.rs @@ -48,7 +48,7 @@ impl Bencher { F: FnMut(&mut Bencher), { f(self); - return self.summary; + self.summary } } @@ -116,7 +116,7 @@ where for _ in 0..k { black_box(inner()); } - return ns_from_dur(start.elapsed()); + ns_from_dur(start.elapsed()) } pub fn iter(inner: &mut F) -> stats::Summary diff --git a/src/libtest/cli.rs b/src/libtest/cli.rs index f95d5aad18a6..a34426305be2 100644 --- a/src/libtest/cli.rs +++ b/src/libtest/cli.rs @@ -149,7 +149,7 @@ fn optgroups() -> getopts::Options { `CRITICAL_TIME` here means the limit that should not be exceeded by test. " ); - return opts; + opts } fn usage(binary: &str, options: &getopts::Options) { diff --git a/src/libtest/console.rs b/src/libtest/console.rs index e17030726cea..244cbd2cf5fe 100644 --- a/src/libtest/console.rs +++ b/src/libtest/console.rs @@ -296,7 +296,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec) -> io::Resu assert!(st.current_test_count() == st.total); - return out.write_run_finish(&st); + out.write_run_finish(&st) } // Calculates padding for given test description. From e1aa297b8be571eb3b9bf936d9de9ecb13b3eace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 5 Sep 2019 13:38:00 +0200 Subject: [PATCH 3/5] Apply clippy::redundant_pattern_matching suggestion --- src/libcore/fmt/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 8413b2e0ac49..0e83a282b18f 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -2025,7 +2025,7 @@ impl Pointer for *const T { if f.alternate() { f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32); - if let None = f.width { + if f.width.is_none() { f.width = Some(((mem::size_of::() * 8) / 4) + 2); } } From 749146827865dfe1f62ce757795415414bb75a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 5 Sep 2019 13:47:59 +0200 Subject: [PATCH 4/5] Apply clippy::while_let_on_iterator suggestions --- src/libstd/sys/windows/process.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 61393680883f..096b7bea8a5f 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -472,9 +472,8 @@ fn make_command_line(prog: &OsStr, args: &[OsString]) -> io::Result> { cmd.push('"' as u16); } - let mut iter = arg.encode_wide(); let mut backslashes: usize = 0; - while let Some(x) = iter.next() { + for x in arg.encode_wide() { if x == '\\' as u16 { backslashes += 1; } else { From bedbf3bacbff36a477dcf28523cbf6cab67e9e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 5 Sep 2019 14:08:06 +0200 Subject: [PATCH 5/5] Apply clippy::single_match suggestion --- src/libcore/option.rs | 5 ++--- src/libstd/thread/local.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 9eb29eae7f75..89f2d7ab29c9 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -837,9 +837,8 @@ impl Option { #[inline] #[stable(feature = "option_entry", since = "1.20.0")] pub fn get_or_insert_with T>(&mut self, f: F) -> &mut T { - match *self { - None => *self = Some(f()), - _ => (), + if let None = *self { + *self = Some(f()); } match *self { diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index e92c0d1c58e4..cfaab4e22e9c 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -509,9 +509,8 @@ pub mod os { pub unsafe fn get(&'static self, init: fn() -> T) -> Option<&'static T> { let ptr = self.os.get() as *mut Value; if ptr as usize > 1 { - match (*ptr).inner.get() { - Some(ref value) => return Some(value), - None => {}, + if let Some(ref value) = (*ptr).inner.get() { + return Some(value); } } self.try_initialize(init)