]> git.lizzy.rs Git - rust.git/commitdiff
remove redundant clones, references to operands, explicit boolean comparisons and...
authorMatthias Krüger <matthias.krueger@famsik.de>
Fri, 28 Feb 2020 12:36:45 +0000 (13:36 +0100)
committerMatthias Krüger <matthias.krueger@famsik.de>
Fri, 28 Feb 2020 12:45:30 +0000 (13:45 +0100)
src/librustc_infer/traits/wf.rs
src/librustc_mir/dataflow/mod.rs
src/librustc_parse/parser/stmt.rs
src/librustc_resolve/late/diagnostics.rs
src/librustdoc/test.rs

index 993eb41b9b1a74c517576a005a8d292e5928c68b..980a3f04781346d9ec349aeb51d4a959cb830e4b 100644 (file)
@@ -232,10 +232,8 @@ fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elabo
                         //                 found type `()`
                         if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
                             let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
-                            if let Some(impl_item) = items
-                                .iter()
-                                .filter(|item| item.ident == trait_assoc_item.ident)
-                                .next()
+                            if let Some(impl_item) =
+                                items.iter().find(|item| item.ident == trait_assoc_item.ident)
                             {
                                 cause.span = impl_item.span;
                                 cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
@@ -285,13 +283,11 @@ fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elabo
                         {
                             if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
                                 .iter()
-                                .filter(|i| i.def_id == *item_def_id)
-                                .next()
+                                .find(|i| i.def_id == *item_def_id)
                                 .and_then(|trait_assoc_item| {
                                     items
                                         .iter()
-                                        .filter(|i| i.ident == trait_assoc_item.ident)
-                                        .next()
+                                        .find(|i| i.ident == trait_assoc_item.ident)
                                         .map(|impl_item| (impl_item, trait_assoc_item))
                                 })
                             {
index eccdac2fb9987b5dbc5d0f0f994bff909fd5380e..a0d93d6d19ab89b30c0cb1917c0805568edce1a0 100644 (file)
@@ -689,11 +689,7 @@ pub trait BottomValue {
     /// 3. Override `join` to do the opposite from what it's doing now.
     #[inline]
     fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
-        if Self::BOTTOM_VALUE == false {
-            inout_set.union(in_set)
-        } else {
-            inout_set.intersect(in_set)
-        }
+        if !Self::BOTTOM_VALUE { inout_set.union(in_set) } else { inout_set.intersect(in_set) }
     }
 }
 
index 257292ae0729cd8683adf0a1d46a31e68488fb78..9073e131f700dda25281d4bcbed8b61e9c317152 100644 (file)
@@ -89,7 +89,7 @@ fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
 
     fn parse_stmt_item(&mut self, attrs: Vec<Attribute>) -> PResult<'a, Option<ast::Item>> {
         let old = mem::replace(&mut self.directory.ownership, DirectoryOwnership::UnownedViaBlock);
-        let item = self.parse_item_common(attrs.clone(), false, true, |_| true)?;
+        let item = self.parse_item_common(attrs, false, true, |_| true)?;
         self.directory.ownership = old;
         Ok(item)
     }
index 957574cced79ba3d42b4d02f520c3d74ac289e3f..e2aa853e78ced6afa11f10428236b5c71752d69a 100644 (file)
@@ -968,18 +968,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
         for missing in &self.missing_named_lifetime_spots {
             match missing {
                 MissingLifetimeSpot::Generics(generics) => {
-                    let (span, sugg) = if let Some(param) = generics
-                        .params
-                        .iter()
-                        .filter(|p| match p.kind {
+                    let (span, sugg) = if let Some(param) =
+                        generics.params.iter().find(|p| match p.kind {
                             hir::GenericParamKind::Type {
                                 synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
                                 ..
                             } => false,
                             _ => true,
-                        })
-                        .next()
-                    {
+                        }) {
                         (param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
                     } else {
                         (generics.span, format!("<{}>", lifetime_ref))
@@ -1053,25 +1049,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
                     Applicability::MaybeIncorrect,
                 );
             };
-            let suggest_new =
-                |err: &mut DiagnosticBuilder<'_>, sugg: &str| {
-                    err.span_label(span, "expected named lifetime parameter");
+            let suggest_new = |err: &mut DiagnosticBuilder<'_>, sugg: &str| {
+                err.span_label(span, "expected named lifetime parameter");
 
-                    for missing in self.missing_named_lifetime_spots.iter().rev() {
-                        let mut introduce_suggestion = vec![];
-                        let msg;
-                        let should_break;
-                        introduce_suggestion.push(match missing {
+                for missing in self.missing_named_lifetime_spots.iter().rev() {
+                    let mut introduce_suggestion = vec![];
+                    let msg;
+                    let should_break;
+                    introduce_suggestion.push(match missing {
                         MissingLifetimeSpot::Generics(generics) => {
                             msg = "consider introducing a named lifetime parameter".to_string();
                             should_break = true;
-                            if let Some(param) = generics.params.iter().filter(|p| match p.kind {
+                            if let Some(param) = generics.params.iter().find(|p| match p.kind {
                                 hir::GenericParamKind::Type {
                                     synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
                                     ..
                                 } => false,
                                 _ => true,
-                            }).next() {
+                            }) {
                                 (param.span.shrink_to_lo(), "'a, ".to_string())
                             } else {
                                 (generics.span, "<'a>".to_string())
@@ -1090,30 +1085,29 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
                             (*span, span_type.suggestion("'a"))
                         }
                     });
-                        for param in params {
-                            if let Ok(snippet) =
-                                self.tcx.sess.source_map().span_to_snippet(param.span)
-                            {
-                                if snippet.starts_with("&") && !snippet.starts_with("&'") {
-                                    introduce_suggestion
-                                        .push((param.span, format!("&'a {}", &snippet[1..])));
-                                } else if snippet.starts_with("&'_ ") {
-                                    introduce_suggestion
-                                        .push((param.span, format!("&'a {}", &snippet[4..])));
-                                }
+                    for param in params {
+                        if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span)
+                        {
+                            if snippet.starts_with("&") && !snippet.starts_with("&'") {
+                                introduce_suggestion
+                                    .push((param.span, format!("&'a {}", &snippet[1..])));
+                            } else if snippet.starts_with("&'_ ") {
+                                introduce_suggestion
+                                    .push((param.span, format!("&'a {}", &snippet[4..])));
                             }
                         }
-                        introduce_suggestion.push((span, sugg.to_string()));
-                        err.multipart_suggestion(
-                            &msg,
-                            introduce_suggestion,
-                            Applicability::MaybeIncorrect,
-                        );
-                        if should_break {
-                            break;
-                        }
                     }
-                };
+                    introduce_suggestion.push((span, sugg.to_string()));
+                    err.multipart_suggestion(
+                        &msg,
+                        introduce_suggestion,
+                        Applicability::MaybeIncorrect,
+                    );
+                    if should_break {
+                        break;
+                    }
+                }
+            };
 
             match (
                 lifetime_names.len(),
index 5dd7bd82755752e8ef5eb290bc86ad9a22d8879f..4d51b63b740fd8ee9e0ed5ca94c6e6cbf2ab7342 100644 (file)
@@ -398,7 +398,7 @@ pub fn make_test(
             use rustc_span::source_map::FilePathMapping;
 
             let filename = FileName::anon_source_code(s);
-            let source = crates + &everything_else;
+            let source = crates + everything_else;
 
             // Any errors in parsing should also appear when the doctest is compiled for real, so just
             // send all the errors that libsyntax emits directly into a `Sink` instead of stderr.