Skip to content

Commit a2b8829

Browse files
committed
typeck: don't collect to a vector when unnecessary
1 parent 2bab4bf commit a2b8829

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Diff for: src/librustc_typeck/astconv.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
15921592
debug!("ty_of_fn");
15931593

15941594
let tcx = self.tcx();
1595-
let input_tys: Vec<Ty> =
1596-
decl.inputs.iter().map(|a| self.ty_of_arg(a, None)).collect();
1595+
let input_tys =
1596+
decl.inputs.iter().map(|a| self.ty_of_arg(a, None));
15971597

15981598
let output_ty = match decl.output {
15991599
hir::Return(ref output) => self.ast_ty_to_ty(output),
@@ -1603,7 +1603,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
16031603
debug!("ty_of_fn: output_ty={:?}", output_ty);
16041604

16051605
let bare_fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
1606-
input_tys.into_iter(),
1606+
input_tys,
16071607
output_ty,
16081608
decl.variadic,
16091609
unsafety,

Diff for: src/librustc_typeck/check/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
626626

627627
// Typecheck the patterns first, so that we get types for all the
628628
// bindings.
629-
let all_arm_pats_diverge: Vec<_> = arms.iter().map(|arm| {
629+
let all_arm_pats_diverge = arms.iter().map(|arm| {
630630
let mut all_pats_diverge = Diverges::WarnedAlways;
631631
for p in &arm.pats {
632632
self.diverges.set(Diverges::Maybe);
@@ -642,7 +642,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
642642
Diverges::Maybe => Diverges::Maybe,
643643
Diverges::Always | Diverges::WarnedAlways => Diverges::WarnedAlways,
644644
}
645-
}).collect();
645+
});
646646

647647
// Now typecheck the blocks.
648648
//

Diff for: src/librustc_typeck/check/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ fn check_transparent<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: De
17691769
}
17701770

17711771
// For each field, figure out if it's known to be a ZST and align(1)
1772-
let field_infos: Vec<_> = adt.non_enum_variant().fields.iter().map(|field| {
1772+
let field_infos = adt.non_enum_variant().fields.iter().map(|field| {
17731773
let ty = field.ty(tcx, Substs::identity_for_item(tcx, field.did));
17741774
let param_env = tcx.param_env(field.did);
17751775
let layout = tcx.layout_of(param_env.and(ty));
@@ -1778,19 +1778,19 @@ fn check_transparent<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: De
17781778
let zst = layout.map(|layout| layout.is_zst()).unwrap_or(false);
17791779
let align1 = layout.map(|layout| layout.align.abi() == 1).unwrap_or(false);
17801780
(span, zst, align1)
1781-
}).collect();
1781+
});
17821782

1783-
let non_zst_fields = field_infos.iter().filter(|(_span, zst, _align1)| !*zst);
1783+
let non_zst_fields = field_infos.clone().filter(|(_span, zst, _align1)| !*zst);
17841784
let non_zst_count = non_zst_fields.clone().count();
17851785
if non_zst_count != 1 {
1786-
let field_spans: Vec<_> = non_zst_fields.map(|(span, _zst, _align1)| *span).collect();
1786+
let field_spans: Vec<_> = non_zst_fields.map(|(span, _zst, _align1)| span).collect();
17871787
struct_span_err!(tcx.sess, sp, E0690,
17881788
"transparent struct needs exactly one non-zero-sized field, but has {}",
17891789
non_zst_count)
17901790
.span_note(field_spans, "non-zero-sized field")
17911791
.emit();
17921792
}
1793-
for &(span, zst, align1) in &field_infos {
1793+
for (span, zst, align1) in field_infos {
17941794
if zst && !align1 {
17951795
span_err!(tcx.sess, span, E0691,
17961796
"zero-sized field in transparent struct has alignment larger than 1");

0 commit comments

Comments
 (0)