or-patterns: check_match: nix top_pats_hack
passed to check_patterns
.
This commit is contained in:
parent
6bd8c6d4f4
commit
549756bef8
@ -14,7 +14,6 @@
|
||||
use rustc::hir::def::*;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use rustc::hir::ptr::P;
|
||||
use rustc::hir::{self, Pat, PatKind};
|
||||
|
||||
use smallvec::smallvec;
|
||||
@ -76,7 +75,7 @@ fn visit_local(&mut self, loc: &'tcx hir::Local) {
|
||||
});
|
||||
|
||||
// Check legality of move bindings and `@` patterns.
|
||||
self.check_patterns(false, slice::from_ref(&loc.pat));
|
||||
self.check_patterns(false, &loc.pat);
|
||||
}
|
||||
|
||||
fn visit_body(&mut self, body: &'tcx hir::Body) {
|
||||
@ -84,7 +83,7 @@ fn visit_body(&mut self, body: &'tcx hir::Body) {
|
||||
|
||||
for param in &body.params {
|
||||
self.check_irrefutable(¶m.pat, "function argument");
|
||||
self.check_patterns(false, slice::from_ref(¶m.pat));
|
||||
self.check_patterns(false, ¶m.pat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,12 +121,10 @@ fn span_e0158(&self, span: Span, text: &str) {
|
||||
}
|
||||
|
||||
impl<'tcx> MatchVisitor<'_, 'tcx> {
|
||||
fn check_patterns(&mut self, has_guard: bool, pats: &[P<Pat>]) {
|
||||
check_legality_of_move_bindings(self, has_guard, pats);
|
||||
for pat in pats {
|
||||
fn check_patterns(&mut self, has_guard: bool, pat: &Pat) {
|
||||
check_legality_of_move_bindings(self, has_guard, pat);
|
||||
check_legality_of_bindings_in_at_patterns(self, pat);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_match(
|
||||
&mut self,
|
||||
@ -137,7 +134,7 @@ fn check_match(
|
||||
) {
|
||||
for arm in arms {
|
||||
// First, check legality of move bindings.
|
||||
self.check_patterns(arm.guard.is_some(), &arm.top_pats_hack());
|
||||
self.check_patterns(arm.guard.is_some(), &arm.pat);
|
||||
|
||||
// Second, if there is a guard on each arm, make sure it isn't
|
||||
// assigning or borrowing anything mutably.
|
||||
@ -543,15 +540,10 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[Pattern<'_>]) -> Vec<Span> {
|
||||
covered
|
||||
}
|
||||
|
||||
// Legality of move bindings checking
|
||||
fn check_legality_of_move_bindings(
|
||||
cx: &mut MatchVisitor<'_, '_>,
|
||||
has_guard: bool,
|
||||
pats: &[P<Pat>],
|
||||
) {
|
||||
// Check the legality of legality of by-move bindings.
|
||||
fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: bool, pat: &Pat) {
|
||||
let mut by_ref_span = None;
|
||||
for pat in pats {
|
||||
pat.each_binding(|_, hir_id, span, _path| {
|
||||
pat.each_binding(|_, hir_id, span, _| {
|
||||
if let Some(&bm) = cx.tables.pat_binding_modes().get(hir_id) {
|
||||
if let ty::BindByReference(..) = bm {
|
||||
by_ref_span = Some(span);
|
||||
@ -559,8 +551,7 @@ fn check_legality_of_move_bindings(
|
||||
} else {
|
||||
cx.tcx.sess.delay_span_bug(pat.span, "missing binding mode");
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
let span_vec = &mut Vec::new();
|
||||
let mut check_move = |p: &Pat, sub: Option<&Pat>| {
|
||||
@ -576,7 +567,6 @@ fn check_legality_of_move_bindings(
|
||||
}
|
||||
};
|
||||
|
||||
for pat in pats {
|
||||
pat.walk(|p| {
|
||||
if let PatKind::Binding(.., sub) = &p.node {
|
||||
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
|
||||
@ -592,7 +582,7 @@ fn check_legality_of_move_bindings(
|
||||
}
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
if !span_vec.is_empty() {
|
||||
let mut err = struct_span_err!(
|
||||
cx.tcx.sess,
|
||||
|
Loading…
Reference in New Issue
Block a user