Skip to content

A few iterator-related improvements #55067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#![feature(in_band_lifetimes)]
#![feature(macro_at_most_once_rep)]
#![feature(crate_visibility_modifier)]
#![feature(transpose_result)]

#![recursion_limit="512"]

Expand Down
11 changes: 4 additions & 7 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {

// Winnow, but record the exact outcome of evaluation, which
// is needed for specialization. Propagate overflow if it occurs.
let candidates: Result<Vec<Option<EvaluatedCandidate<'_>>>, _> = candidates
.into_iter()
let mut candidates = candidates.into_iter()
.map(|c| match self.evaluate_candidate(stack, &c) {
Ok(eval) if eval.may_apply() => Ok(Some(EvaluatedCandidate {
candidate: c,
Expand All @@ -1378,10 +1377,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
Ok(_) => Ok(None),
Err(OverflowError) => Err(Overflow),
})
.collect();

let mut candidates: Vec<EvaluatedCandidate<'_>> =
candidates?.into_iter().filter_map(|c| c).collect();
.flat_map(Result::transpose)
.collect::<Result<Vec<_>, _>>()?;

debug!(
"winnowed to {} candidates for {:?}: {:?}",
Expand All @@ -1390,7 +1387,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
candidates
);

// If there are STILL multiple candidate, we can further
// If there are STILL multiple candidates, we can further
// reduce the list by dropping duplicates -- including
// resolving specializations.
if candidates.len() > 1 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
match (r1, r2) {
(Representability::SelfRecursive(v1),
Representability::SelfRecursive(v2)) => {
Representability::SelfRecursive(v1.iter().map(|s| *s).chain(v2).collect())
Representability::SelfRecursive(v1.into_iter().chain(v2).collect())
}
(r1, r2) => cmp::max(r1, r2)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
debug!("ty_of_fn");

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

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

let bare_fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
input_tys.into_iter(),
input_tys,
output_ty,
decl.variadic,
unsafety,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");

// Typecheck the patterns first, so that we get types for all the
// bindings.
let all_arm_pats_diverge: Vec<_> = arms.iter().map(|arm| {
let all_arm_pats_diverge = arms.iter().map(|arm| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change injected #55810, because it delayed our type-checking of the patterns. (Note the comment right above this line.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a stronger comment, heh.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll be fixing that.

let mut all_pats_diverge = Diverges::WarnedAlways;
for p in &arm.pats {
self.diverges.set(Diverges::Maybe);
Expand All @@ -642,7 +642,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
Diverges::Maybe => Diverges::Maybe,
Diverges::Always | Diverges::WarnedAlways => Diverges::WarnedAlways,
}
}).collect();
});

// Now typecheck the blocks.
//
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ fn check_transparent<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: De
}

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

let non_zst_fields = field_infos.iter().filter(|(_span, zst, _align1)| !*zst);
let non_zst_fields = field_infos.clone().filter(|(_span, zst, _align1)| !*zst);
let non_zst_count = non_zst_fields.clone().count();
if non_zst_count != 1 {
let field_spans: Vec<_> = non_zst_fields.map(|(span, _zst, _align1)| *span).collect();
let field_spans: Vec<_> = non_zst_fields.map(|(span, _zst, _align1)| span).collect();
struct_span_err!(tcx.sess, sp, E0690,
"transparent struct needs exactly one non-zero-sized field, but has {}",
non_zst_count)
.span_note(field_spans, "non-zero-sized field")
.emit();
}
for &(span, zst, align1) in &field_infos {
for (span, zst, align1) in field_infos {
if zst && !align1 {
span_err!(tcx.sess, span, E0691,
"zero-sized field in transparent struct has alignment larger than 1");
Expand Down