Skip to content

Commit d72cc93

Browse files
committed
Remove some non-trivial box patterns
These particular patterns make it harder to experiment with alternate representations for THIR patterns and subpatterns.
1 parent 849e036 commit d72cc93

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

Diff for: compiler/rustc_mir_build/src/builder/matches/mod.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -605,19 +605,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
605605
// Optimize the case of `let x: T = ...` to write directly
606606
// into `x` and then require that `T == typeof(x)`.
607607
PatKind::AscribeUserType {
608-
subpattern:
609-
box Pat {
610-
kind:
611-
PatKind::Binding {
612-
mode: BindingMode(ByRef::No, _),
613-
var,
614-
subpattern: None,
615-
..
616-
},
617-
..
618-
},
608+
ref subpattern,
619609
ascription: thir::Ascription { ref annotation, variance: _ },
620-
} => {
610+
} if let PatKind::Binding {
611+
mode: BindingMode(ByRef::No, _),
612+
var,
613+
subpattern: None,
614+
..
615+
} = subpattern.kind =>
616+
{
621617
let place = self.storage_live_binding(
622618
block,
623619
var,

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,14 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
676676
let mut interpreted_as_const = None;
677677
let mut interpreted_as_const_sugg = None;
678678

679-
if let PatKind::ExpandedConstant { def_id, is_inline: false, .. }
680-
| PatKind::AscribeUserType {
681-
subpattern:
682-
box Pat { kind: PatKind::ExpandedConstant { def_id, is_inline: false, .. }, .. },
683-
..
684-
} = pat.kind
679+
// These next few matches want to peek through `AscribeUserType` to see
680+
// the underlying pattern.
681+
let mut unpeeled_pat = pat;
682+
while let PatKind::AscribeUserType { ref subpattern, .. } = unpeeled_pat.kind {
683+
unpeeled_pat = subpattern;
684+
}
685+
686+
if let PatKind::ExpandedConstant { def_id, is_inline: false, .. } = unpeeled_pat.kind
685687
&& let DefKind::Const = self.tcx.def_kind(def_id)
686688
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
687689
// We filter out paths with multiple path::segments.
@@ -692,11 +694,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
692694
// When we encounter a constant as the binding name, point at the `const` definition.
693695
interpreted_as_const = Some(span);
694696
interpreted_as_const_sugg = Some(InterpretedAsConst { span: pat.span, variable });
695-
} else if let PatKind::Constant { .. }
696-
| PatKind::AscribeUserType {
697-
subpattern: box Pat { kind: PatKind::Constant { .. }, .. },
698-
..
699-
} = pat.kind
697+
} else if let PatKind::Constant { .. } = unpeeled_pat.kind
700698
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
701699
{
702700
// If the pattern to match is an integer literal:

0 commit comments

Comments
 (0)