Skip to content

Commit 549756b

Browse files
committed
or-patterns: check_match: nix top_pats_hack passed to check_patterns.
1 parent 6bd8c6d commit 549756b

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
1414
use rustc::hir::def::*;
1515
use rustc::hir::def_id::DefId;
1616
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
17-
use rustc::hir::ptr::P;
1817
use rustc::hir::{self, Pat, PatKind};
1918

2019
use smallvec::smallvec;
@@ -76,15 +75,15 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
7675
});
7776

7877
// Check legality of move bindings and `@` patterns.
79-
self.check_patterns(false, slice::from_ref(&loc.pat));
78+
self.check_patterns(false, &loc.pat);
8079
}
8180

8281
fn visit_body(&mut self, body: &'tcx hir::Body) {
8382
intravisit::walk_body(self, body);
8483

8584
for param in &body.params {
8685
self.check_irrefutable(&param.pat, "function argument");
87-
self.check_patterns(false, slice::from_ref(&param.pat));
86+
self.check_patterns(false, &param.pat);
8887
}
8988
}
9089
}
@@ -122,11 +121,9 @@ impl PatternContext<'_, '_> {
122121
}
123122

124123
impl<'tcx> MatchVisitor<'_, 'tcx> {
125-
fn check_patterns(&mut self, has_guard: bool, pats: &[P<Pat>]) {
126-
check_legality_of_move_bindings(self, has_guard, pats);
127-
for pat in pats {
128-
check_legality_of_bindings_in_at_patterns(self, pat);
129-
}
124+
fn check_patterns(&mut self, has_guard: bool, pat: &Pat) {
125+
check_legality_of_move_bindings(self, has_guard, pat);
126+
check_legality_of_bindings_in_at_patterns(self, pat);
130127
}
131128

132129
fn check_match(
@@ -137,7 +134,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
137134
) {
138135
for arm in arms {
139136
// First, check legality of move bindings.
140-
self.check_patterns(arm.guard.is_some(), &arm.top_pats_hack());
137+
self.check_patterns(arm.guard.is_some(), &arm.pat);
141138

142139
// Second, if there is a guard on each arm, make sure it isn't
143140
// assigning or borrowing anything mutably.
@@ -543,24 +540,18 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[Pattern<'_>]) -> Vec<Span> {
543540
covered
544541
}
545542

546-
// Legality of move bindings checking
547-
fn check_legality_of_move_bindings(
548-
cx: &mut MatchVisitor<'_, '_>,
549-
has_guard: bool,
550-
pats: &[P<Pat>],
551-
) {
543+
// Check the legality of legality of by-move bindings.
544+
fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: bool, pat: &Pat) {
552545
let mut by_ref_span = None;
553-
for pat in pats {
554-
pat.each_binding(|_, hir_id, span, _path| {
555-
if let Some(&bm) = cx.tables.pat_binding_modes().get(hir_id) {
556-
if let ty::BindByReference(..) = bm {
557-
by_ref_span = Some(span);
558-
}
559-
} else {
560-
cx.tcx.sess.delay_span_bug(pat.span, "missing binding mode");
546+
pat.each_binding(|_, hir_id, span, _| {
547+
if let Some(&bm) = cx.tables.pat_binding_modes().get(hir_id) {
548+
if let ty::BindByReference(..) = bm {
549+
by_ref_span = Some(span);
561550
}
562-
})
563-
}
551+
} else {
552+
cx.tcx.sess.delay_span_bug(pat.span, "missing binding mode");
553+
}
554+
});
564555

565556
let span_vec = &mut Vec::new();
566557
let mut check_move = |p: &Pat, sub: Option<&Pat>| {
@@ -576,23 +567,22 @@ fn check_legality_of_move_bindings(
576567
}
577568
};
578569

579-
for pat in pats {
580-
pat.walk(|p| {
581-
if let PatKind::Binding(.., sub) = &p.node {
582-
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
583-
if let ty::BindByValue(..) = bm {
584-
let pat_ty = cx.tables.node_type(p.hir_id);
585-
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
586-
check_move(p, sub.as_deref());
587-
}
570+
pat.walk(|p| {
571+
if let PatKind::Binding(.., sub) = &p.node {
572+
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
573+
if let ty::BindByValue(..) = bm {
574+
let pat_ty = cx.tables.node_type(p.hir_id);
575+
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
576+
check_move(p, sub.as_deref());
588577
}
589-
} else {
590-
cx.tcx.sess.delay_span_bug(pat.span, "missing binding mode");
591578
}
579+
} else {
580+
cx.tcx.sess.delay_span_bug(pat.span, "missing binding mode");
592581
}
593-
true
594-
});
595-
}
582+
}
583+
true
584+
});
585+
596586
if !span_vec.is_empty() {
597587
let mut err = struct_span_err!(
598588
cx.tcx.sess,
@@ -603,7 +593,7 @@ fn check_legality_of_move_bindings(
603593
if let Some(by_ref_span) = by_ref_span {
604594
err.span_label(by_ref_span, "both by-ref and by-move used");
605595
}
606-
for span in span_vec.iter(){
596+
for span in span_vec.iter() {
607597
err.span_label(*span, "by-move pattern here");
608598
}
609599
err.emit();

0 commit comments

Comments
 (0)