10000 or-patterns: Push `PatKind/PatternKind::Or` at top level to HIR & HAIR by Centril · Pull Request #64508 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

or-patterns: Push PatKind/PatternKind::Or at top level to HIR & HAIR #64508

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 22 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
146cb8e
or-patterns: remove hack from lowering.
Centril Sep 7, 2019
b2f903c
or-patterns: `hir::Arm::pats` -> `::pat` + `Arm::top_pats_hack`.
Centril Sep 7, 2019
6579d13
or-patterns: normalize HIR pretty priting.
Centril Sep 7, 2019
75fb42a
or-patterns: use `top_pats_hack` to make things compile.
Centril Sep 7, 2019
89bbef3
check_match: misc cleanup.
Centril Sep 15, 2019
4c34693
or-patterns: fix problems in typeck.
Centril Sep 15, 2019
9d1c3c9
simplify `hir::Pat::walk_`.
Centril Sep 15, 2019
cc5fe6d
or-patterns: liveness/`visit_arm`: remove `top_pats_hack`.
Centril Sep 15, 2019
9ca42a5
or-patterns: liveness: generalize + remove `top_pats_hack`.
Centril Sep 15, 2019
57eeb61
or-patterns: remove `Arm::contains_explicit_ref_binding`.
Centril Sep 15, 2019
fb2cfec
or-patterns: euv/`arm_move_mode`: remove `top_pats_hack`.
Centril Sep 15, 2019
d7139f3
or-patterns: euv/`walk_arm`: remove `top_pats_hack`.
Centril Sep 15, 2019
07deb93
or-patterns: middle/dead: make a hack less hacky.
Centril Sep 15, 2019
0dfd706
or-patterns: rvalue_promotion: remove `top_pats_hack`.
Centril Sep 15, 2019
38a5ae9
or-patterns: regionck/visit_arm: remove `top_pats_hack`.
Centril Sep 15, 2019
9b406f1
or-patterns: regionck/`link_match`: remove `top_pats_hack`.
Centril Sep 15, 2019
6bd8c6d
or-patterns: check_match: remove `top_pats_hack` for `check_for_bindi…
Centril Sep 15, 2019
549756b
or-patterns: check_match: nix `top_pats_hack` passed to `check_patter…
Centril Sep 15, 2019
56b055a
or-patterns: HAIR: `Arm.patterns: Vec<Pattern<'_>>` -> `.pattern: Pat…
Centril Sep 16, 2019
05cc3c0
or-patterns: liveness: `is_argument` -> `is_param`.
Centril Sep 16, 2019
370fbcc
or-patterns: #47390: we rely on names to exercise `IndexMap`.
Centril Sep 16, 2019
0918dc4
or-patterns: middle/dead: remove `top_pats_hack`.
Centril Sep 21, 2019
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
Prev Previous commit
Next Next commit
or-patterns: use top_pats_hack to make things compile.
  • Loading branch information
Centril committed Sep 15, 2019
commit 75fb42a11fa91a323e2109a0d42230d96c73e3bb
2 changes: 1 addition & 1 deletion src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_borrowck/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/rvalue_promotion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
0