1
Fork 0

Remove some non-trivial box patterns

These particular patterns make it harder to experiment with alternate
representations for THIR patterns and subpatterns.
This commit is contained in:
Zalathar 2025-02-02 15:58:43 +11:00
parent 849e0364c1
commit d72cc93e4e
2 changed files with 17 additions and 23 deletions

View file

@ -605,19 +605,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Optimize the case of `let x: T = ...` to write directly
// into `x` and then require that `T == typeof(x)`.
PatKind::AscribeUserType {
subpattern:
box Pat {
kind:
PatKind::Binding {
ref subpattern,
ascription: thir::Ascription { ref annotation, variance: _ },
} if let PatKind::Binding {
mode: BindingMode(ByRef::No, _),
var,
subpattern: None,
..
},
..
},
ascription: thir::Ascription { ref annotation, variance: _ },
} => {
} = subpattern.kind =>
{
let place = self.storage_live_binding(
block,
var,

View file

@ -676,12 +676,14 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
let mut interpreted_as_const = None;
let mut interpreted_as_const_sugg = None;
if let PatKind::ExpandedConstant { def_id, is_inline: false, .. }
| PatKind::AscribeUserType {
subpattern:
box Pat { kind: PatKind::ExpandedConstant { def_id, is_inline: false, .. }, .. },
..
} = pat.kind
// These next few matches want to peek through `AscribeUserType` to see
// the underlying pattern.
let mut unpeeled_pat = pat;
while let PatKind::AscribeUserType { ref subpattern, .. } = unpeeled_pat.kind {
unpeeled_pat = subpattern;
}
if let PatKind::ExpandedConstant { def_id, is_inline: false, .. } = unpeeled_pat.kind
&& let DefKind::Const = self.tcx.def_kind(def_id)
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
// We filter out paths with multiple path::segments.
@ -692,11 +694,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
// When we encounter a constant as the binding name, point at the `const` definition.
interpreted_as_const = Some(span);
interpreted_as_const_sugg = Some(InterpretedAsConst { span: pat.span, variable });
} else if let PatKind::Constant { .. }
| PatKind::AscribeUserType {
subpattern: box Pat { kind: PatKind::Constant { .. }, .. },
..
} = pat.kind
} else if let PatKind::Constant { .. } = unpeeled_pat.kind
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
{
// If the pattern to match is an integer literal: