]> git.lizzy.rs Git - rust.git/commitdiff
Don't collect to vectors where unnecessary
authorljedrz <ljedrz@gmail.com>
Sat, 13 Oct 2018 18:51:25 +0000 (20:51 +0200)
committerljedrz <ljedrz@gmail.com>
Sun, 14 Oct 2018 05:53:36 +0000 (07:53 +0200)
src/librustc/hir/lowering.rs
src/librustc_traits/lowering.rs
src/librustc_typeck/check/demand.rs

index 4d51126621d7dcaf66d10f50170d892d17fdd54a..e99d65024967b7c63de2d8b9a564d17903190887 100644 (file)
@@ -60,7 +60,6 @@
 
 use std::collections::BTreeMap;
 use std::fmt::Debug;
-use std::iter;
 use std::mem;
 use smallvec::SmallVec;
 use syntax::attr;
@@ -3888,9 +3887,7 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
                     .collect::<P<[hir::Field]>>();
 
                 let is_unit = fields.is_empty();
-                let struct_path = iter::once("ops")
-                    .chain(iter::once(path))
-                    .collect::<Vec<_>>();
+                let struct_path = ["ops", path];
                 let struct_path = self.std_path(e.span, &struct_path, None, is_unit);
                 let struct_path = hir::QPath::Resolved(None, P(struct_path));
 
index 181106d3f84bf19f9b4f371ff65edd1476ae162d..1e3f0a21cefb3ef3593d723eca5a8f2eed4c94ea 100644 (file)
@@ -306,8 +306,7 @@ fn program_clauses_for_trait<'a, 'tcx>(
     let wf_conditions = iter::once(ty::Binder::dummy(trait_pred.lower()))
         .chain(
             where_clauses
-                .iter()
-                .cloned()
+                .into_iter()
                 .map(|wc| wc.map_bound(|goal| goal.into_well_formed_goal()))
         );
 
@@ -350,15 +349,13 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
     // `WC`
     let where_clauses = tcx.predicates_of(def_id).predicates
         .into_iter()
-        .map(|(wc, _)| wc.lower())
-        .collect::<Vec<_>>();
+        .map(|(wc, _)| wc.lower());
 
     // `Implemented(A0: Trait<A1..An>) :- WC`
     let clause = ProgramClause {
         goal: trait_pred,
         hypotheses: tcx.mk_goals(
             where_clauses
-                .into_iter()
                 .map(|wc| tcx.mk_goal(GoalKind::from_poly_domain_goal(wc, tcx))),
         ),
     };
index 85b6bcbd144fc7a8debf1e8d8444b1efdcb94f81..d82d36a1937bf4b5449249789643be1b5285e2e2 100644 (file)
@@ -115,7 +115,7 @@ pub fn demand_coerce_diag(&self,
         // field is of the found type, suggest such variants. See Issue
         // #42764.
         if let ty::Adt(expected_adt, substs) = expected.sty {
-            let compatible_variants = expected_adt.variants
+            let mut compatible_variants = expected_adt.variants
                                                   .iter()
                                                   .filter(|variant| variant.fields.len() == 1)
                                                   .filter_map(|variant| {
@@ -127,12 +127,12 @@ pub fn demand_coerce_diag(&self,
                 } else {
                     None
                 }
-            }).collect::<Vec<_>>();
+            }).peekable();
 
-            if !compatible_variants.is_empty() {
+            if compatible_variants.peek().is_some() {
                 let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
-                let suggestions = compatible_variants.iter()
-                    .map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
+                let suggestions = compatible_variants.map(|v|
+                    format!("{}({})", v, expr_text)).collect::<Vec<_>>();
                 err.span_suggestions_with_applicability(
                      expr.span,
                      "try using a variant of the expected type",