Skip to content

Commit 89bbef3

Browse files
committed
check_match: misc cleanup.
1 parent 75fb42a commit 89bbef3

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -563,40 +563,30 @@ fn check_legality_of_move_bindings(
563563
}
564564
})
565565
}
566+
566567
let span_vec = &mut Vec::new();
567-
let check_move = |
568-
cx: &mut MatchVisitor<'_, '_>,
569-
p: &Pat,
570-
sub: Option<&Pat>,
571-
span_vec: &mut Vec<Span>,
572-
| {
573-
// check legality of moving out of the enum
574-
575-
// x @ Foo(..) is legal, but x @ Foo(y) isn't.
568+
let mut check_move = |p: &Pat, sub: Option<&Pat>| {
569+
// Check legality of moving out of the enum.
570+
//
571+
// `x @ Foo(..)` is legal, but `x @ Foo(y)` isn't.
576572
if sub.map_or(false, |p| p.contains_bindings()) {
577-
struct_span_err!(cx.tcx.sess, p.span, E0007,
578-
"cannot bind by-move with sub-bindings")
573+
struct_span_err!(cx.tcx.sess, p.span, E0007, "cannot bind by-move with sub-bindings")
579574
.span_label(p.span, "binds an already bound by-move value by moving it")
580575
.emit();
581-
} else if !has_guard {
582-
if let Some(_by_ref_span) = by_ref_span {
583-
span_vec.push(p.span);
584-
}
576+
} else if !has_guard && by_ref_span.is_some() {
577+
span_vec.push(p.span);
585578
}
586579
};
587580

588581
for pat in pats {
589582
pat.walk(|p| {
590-
if let PatKind::Binding(_, _, _, ref sub) = p.node {
583+
if let PatKind::Binding(.., sub) = &p.node {
591584
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
592-
match bm {
593-
ty::BindByValue(..) => {
594-
let pat_ty = cx.tables.node_type(p.hir_id);
595-
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
596-
check_move(cx, p, sub.as_ref().map(|p| &**p), span_vec);
597-
}
585+
if let ty::BindByValue(..) = bm {
586+
let pat_ty = cx.tables.node_type(p.hir_id);
587+
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
588+
check_move(p, sub.as_deref());
598589
}
599-
_ => {}
600590
}
601591
} else {
602592
cx.tcx.sess.delay_span_bug(pat.span, "missing binding mode");
@@ -605,11 +595,10 @@ fn check_legality_of_move_bindings(
605595
true
606596
});
607597
}
608-
if !span_vec.is_empty(){
609-
let span = MultiSpan::from_spans(span_vec.clone());
598+
if !span_vec.is_empty() {
610599
let mut err = struct_span_err!(
611600
cx.tcx.sess,
612-
span,
601+
MultiSpan::from_spans(span_vec.clone()),
613602
E0009,
614603
"cannot bind by-move and by-ref in the same pattern",
615604
);
@@ -627,7 +616,7 @@ fn check_legality_of_move_bindings(
627616
/// because of the way rvalues are handled in the borrow check. (See issue
628617
/// #14587.)
629618
fn check_legality_of_bindings_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
630-
AtBindingPatternVisitor { cx: cx, bindings_allowed: true }.visit_pat(pat);
619+
AtBindingPatternVisitor { cx, bindings_allowed: true }.visit_pat(pat);
631620
}
632621

633622
struct AtBindingPatternVisitor<'a, 'b, 'tcx> {

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
66

77
#![feature(nll)]
88
#![feature(in_band_lifetimes)]
9+
#![feature(inner_deref)]
910
#![feature(slice_patterns)]
1011
#![feature(box_patterns)]
1112
#![feature(box_syntax)]

0 commit comments

Comments
 (0)