1
Fork 0

or-patterns: use top_pats_hack to make things compile.

This commit is contained in:
Mazdak Farrokhzad 2019-09-07 16:01:12 +02:00
parent 6579d136b1
commit 75fb42a11f
11 changed files with 21 additions and 22 deletions

View file

@ -1103,7 +1103,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
visitor.visit_id(arm.hir_id);
walk_list!(visitor, visit_pat, &arm.pats);
visitor.visit_pat(&arm.pat);
if let Some(ref g) = arm.guard {
match g {
Guard::If(ref e) => visitor.visit_expr(e),

View file

@ -170,7 +170,7 @@ impl hir::Arm {
// for #42640 (default match binding modes).
//
// See #44848.
self.pats.iter()
self.top_pats_hack().iter()
.filter_map(|pat| pat.contains_explicit_ref_binding())
.max_by_key(|m| match *m {
hir::MutMutable => 1,

View file

@ -259,8 +259,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
}
fn visit_arm(&mut self, arm: &'tcx hir::Arm) {
if arm.pats.len() == 1 {
let variants = arm.pats[0].necessary_variants();
let pats = arm.top_pats_hack();
if pats.len() == 1 {
let variants = pats[0].necessary_variants();
// Inside the body, ignore constructions of variants
// necessary for the pattern to match. Those construction sites

View file

@ -779,14 +779,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
fn arm_move_mode(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &hir::Arm) -> TrackMatchMode {
let mut mode = Unknown;
for pat in &arm.pats {
for pat in arm.top_pats_hack() {
self.determine_pat_move_mode(discr_cmt.clone(), &pat, &mut mode);
}
mode
}
fn walk_arm(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &hir::Arm, mode: MatchMode) {
for pat in &arm.pats {
for pat in arm.top_pats_hack() {
self.walk_pat(discr_cmt.clone(), &pat, mode);
}

View file

@ -456,7 +456,7 @@ fn visit_local<'tcx>(ir: &mut IrMaps<'tcx>, local: &'tcx hir::Local) {
}
fn visit_arm<'tcx>(ir: &mut IrMaps<'tcx>, arm: &'tcx hir::Arm) {
for pat in &arm.pats {
for pat in arm.top_pats_hack() {
add_from_pat(ir, pat);
}
intravisit::walk_arm(ir, arm);
@ -1080,7 +1080,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// the same bindings, and we also consider the first pattern to be
// the "authoritative" set of ids
let arm_succ =
self.define_bindings_in_arm_pats(arm.pats.first().map(|p| &**p),
self.define_bindings_in_arm_pats(arm.top_pats_hack().first().map(|p| &**p),
guard_succ);
self.merge_from_succ(ln, arm_succ, first_merge);
first_merge = false;
@ -1422,7 +1422,7 @@ fn check_arm<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, arm: &'tcx hir::Arm) {
// patterns so the suggestions to prefix with underscores will apply to those too.
let mut vars: BTreeMap<String, (LiveNode, Variable, HirId, Vec<Span>)> = Default::default();
for pat in &arm.pats {
for pat in arm.top_pats_hack() {
this.arm_pats_bindings(Some(&*pat), |this, ln, var, sp, id| {
let name = this.ir.variable_name(var);
vars.entry(name)

View file

@ -390,7 +390,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
// patterns and the guard (if there is one) in the arm.
let bindings_exit = self.add_dummy_node(&[]);
for pat in &arm.pats {
for pat in arm.top_pats_hack() {
// Visit the pattern, coming from the discriminant exit
let mut pat_exit = self.pat(&pat, discr_exit);

View file

@ -862,7 +862,7 @@ impl ToBorrowKind for hir::Mutability {
fn convert_arm<'a, 'tcx>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm<'tcx> {
Arm {
patterns: arm.pats.iter().map(|p| cx.pattern_from_hir(p)).collect(),
patterns: arm.top_pats_hack().iter().map(|p| cx.pattern_from_hir(p)).collect(),
guard: match arm.guard {
Some(hir::Guard::If(ref e)) => Some(Guard::If(e.to_ref())),
_ => None,

View file

@ -137,7 +137,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
) {
for arm in arms {
// First, check legality of move bindings.
self.check_patterns(arm.guard.is_some(), &arm.pats);
self.check_patterns(arm.guard.is_some(), &arm.top_pats_hack());
// Second, if there is a guard on each arm, make sure it isn't
// assigning or borrowing anything mutably.
@ -146,7 +146,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
}
// Third, perform some lints.
for pat in &arm.pats {
for pat in arm.top_pats_hack() {
check_for_bindings_named_same_as_variants(self, pat);
}
}
@ -156,7 +156,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
let mut have_errors = false;
let inlined_arms : Vec<(Vec<_>, _)> = arms.iter().map(|arm| (
arm.pats.iter().map(|pat| {
arm.top_pats_hack().iter().map(|pat| {
let mut patcx = PatternContext::new(self.tcx,
self.param_env.and(self.identity_substs),
self.tables);

View file

@ -503,7 +503,7 @@ fn check_expr_kind<'a, 'tcx>(
// Compute the most demanding borrow from all the arms'
// patterns and set that on the discriminator.
let mut mut_borrow = false;
for pat in hirvec_arm.iter().flat_map(|arm| &arm.pats) {
for pat in hirvec_arm.iter().flat_map(|arm| arm.top_pats_hack()) {
mut_borrow = v.remove_mut_rvalue_borrow(pat);
}
if mut_borrow {

View file

@ -58,11 +58,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// collection into `Vec`), so we get types for all bindings.
let all_arm_pats_diverge: Vec<_> = arms.iter().map(|arm| {
let mut all_pats_diverge = Diverges::WarnedAlways;
for p in &arm.pats {
self.diverges.set(Diverges::Maybe);
self.check_pat_top(&p, discrim_ty, Some(discrim.span));
all_pats_diverge &= self.diverges.get();
}
self.diverges.set(Diverges::Maybe);
self.check_pat_top(&arm.pat, discrim_ty, Some(discrim.span));
all_pats_diverge &= self.diverges.get();
// As discussed with @eddyb, this is for disabling unreachable_code
// warnings on patterns (they're now subsumed by unreachable_patterns

View file

@ -488,7 +488,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
fn visit_arm(&mut self, arm: &'tcx hir::Arm) {
// see above
for p in &arm.pats {
for p in arm.top_pats_hack() {
self.constrain_bindings_in_pat(p);
}
intravisit::walk_arm(self, arm);
@ -1069,7 +1069,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
let discr_cmt = Rc::new(ignore_err!(self.with_mc(|mc| mc.cat_expr(discr))));
debug!("discr_cmt={:?}", discr_cmt);
for arm in arms {
for root_pat in &arm.pats {
for root_pat in arm.top_pats_hack() {
self.link_pattern(discr_cmt.clone(), &root_pat);
}
}