Skip to content

Commit

Permalink
Don't collect to vectors where unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Oct 14, 2018
1 parent f517527 commit 12b5c7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/librustc/hir/lowering.rs
Expand Up @@ -60,7 +60,6 @@ use util::nodemap::{DefIdMap, NodeMap};

use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter;
use std::mem;
use smallvec::SmallVec;
use syntax::attr;
Expand Down Expand Up @@ -3888,9 +3887,7 @@ impl<'a> LoweringContext<'a> {
.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));

Expand Down
7 changes: 2 additions & 5 deletions src/librustc_traits/lowering.rs
Expand Up @@ -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()))
);

Expand Down Expand Up @@ -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))),
),
};
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check/demand.rs
Expand Up @@ -115,7 +115,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// 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| {
Expand All @@ -127,12 +127,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} 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",
Expand Down

0 comments on commit 12b5c7b

Please sign in to comment.