From 139c64625173edab849acd9fbcea9739bb2bb802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 15 Apr 2020 15:15:31 +0200 Subject: [PATCH] Fix clippy warnings clippy::{filter_next,single_char_pattern,unit_arg,identity_conversion,nonminimal_bool} --- src/liballoc/vec.rs | 12 ++++++------ src/librustc_infer/infer/outlives/verify.rs | 1 - src/librustc_mir/borrow_check/region_infer/mod.rs | 2 +- src/librustc_mir/interpret/place.rs | 2 +- .../traits/error_reporting/mod.rs | 4 ++-- src/librustdoc/docfs.rs | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 7ef281ff208..b4a9da84787 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -971,7 +971,7 @@ impl Vec { } let len = self.len(); - if !(index < len) { + if index >= len { assert_failed(index, len); } unsafe { @@ -1010,7 +1010,7 @@ impl Vec { } let len = self.len(); - if !(index <= len) { + if index > len { assert_failed(index, len); } @@ -1058,7 +1058,7 @@ impl Vec { } let len = self.len(); - if !(index < len) { + if index >= len { assert_failed(index, len); } unsafe { @@ -1331,10 +1331,10 @@ impl Vec { panic!("end drain index (is {}) should be <= len (is {})", end, len); } - if !(start <= end) { + if start > end { start_assert_failed(start, end); } - if !(end <= len) { + if end > len { end_assert_failed(end, len); } @@ -1432,7 +1432,7 @@ impl Vec { panic!("`at` split index (is {}) should be <= len (is {})", at, len); } - if !(at <= self.len()) { + if at > self.len() { assert_failed(at, self.len()); } diff --git a/src/librustc_infer/infer/outlives/verify.rs b/src/librustc_infer/infer/outlives/verify.rs index 5b6db324e6c..4adf314c3d4 100644 --- a/src/librustc_infer/infer/outlives/verify.rs +++ b/src/librustc_infer/infer/outlives/verify.rs @@ -297,7 +297,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { self.collect_outlives_from_predicate_list( move |ty| ty == identity_proj, traits::elaborate_predicates(tcx, trait_predicates) - .into_iter() .map(|o| o.predicate) .collect::>(), ) diff --git a/src/librustc_mir/borrow_check/region_infer/mod.rs b/src/librustc_mir/borrow_check/region_infer/mod.rs index 40012116633..7987b77997d 100644 --- a/src/librustc_mir/borrow_check/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/region_infer/mod.rs @@ -495,7 +495,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // to store those. Otherwise, we'll pass in `None` to the // functions below, which will trigger them to report errors // eagerly. - let mut outlives_requirements = infcx.tcx.is_closure(mir_def_id).then(|| vec![]); + let mut outlives_requirements = infcx.tcx.is_closure(mir_def_id).then(Vec::new); self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer); diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 9ac4b3551fc..0fd930090d5 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -549,7 +549,7 @@ where let n = base.len(self)?; if n < u64::from(min_length) { // This can only be reached in ConstProp and non-rustc-MIR. - throw_ub!(BoundsCheckFailed { len: min_length.into(), index: n.into() }); + throw_ub!(BoundsCheckFailed { len: min_length.into(), index: n }); } let index = if from_end { diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index fef7adf0224..0f527419d03 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -1388,7 +1388,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { (self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code) { let generics = self.tcx.generics_of(*def_id); - if generics.params.iter().filter(|p| p.name.as_str() != "Self").next().is_some() + if generics.params.iter().any(|p| p.name.as_str() != "Self") && !snippet.ends_with('>') { // FIXME: To avoid spurious suggestions in functions where type arguments @@ -1817,7 +1817,7 @@ pub fn suggest_constraining_type_param( // Account for `fn foo(t: T) where T: Foo,` so we don't suggest two trailing commas. let mut trailing_comma = false; if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(where_clause_span) { - trailing_comma = snippet.ends_with(","); + trailing_comma = snippet.ends_with(','); } let where_clause_span = if trailing_comma { let hi = where_clause_span.hi(); diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index 9c9a00295c3..7ebb200abfe 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -16,12 +16,12 @@ use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::Arc; macro_rules! try_err { - ($e:expr, $file:expr) => {{ + ($e:expr, $file:expr) => { match $e { Ok(e) => e, Err(e) => return Err(E::new(e, $file)), } - }}; + }; } pub trait PathError {