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:
parent
849e0364c1
commit
d72cc93e4e
2 changed files with 17 additions and 23 deletions
|
@ -605,19 +605,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
// Optimize the case of `let x: T = ...` to write directly
|
// Optimize the case of `let x: T = ...` to write directly
|
||||||
// into `x` and then require that `T == typeof(x)`.
|
// into `x` and then require that `T == typeof(x)`.
|
||||||
PatKind::AscribeUserType {
|
PatKind::AscribeUserType {
|
||||||
subpattern:
|
ref subpattern,
|
||||||
box Pat {
|
ascription: thir::Ascription { ref annotation, variance: _ },
|
||||||
kind:
|
} if let PatKind::Binding {
|
||||||
PatKind::Binding {
|
|
||||||
mode: BindingMode(ByRef::No, _),
|
mode: BindingMode(ByRef::No, _),
|
||||||
var,
|
var,
|
||||||
subpattern: None,
|
subpattern: None,
|
||||||
..
|
..
|
||||||
},
|
} = subpattern.kind =>
|
||||||
..
|
{
|
||||||
},
|
|
||||||
ascription: thir::Ascription { ref annotation, variance: _ },
|
|
||||||
} => {
|
|
||||||
let place = self.storage_live_binding(
|
let place = self.storage_live_binding(
|
||||||
block,
|
block,
|
||||||
var,
|
var,
|
||||||
|
|
|
@ -676,12 +676,14 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
||||||
let mut interpreted_as_const = None;
|
let mut interpreted_as_const = None;
|
||||||
let mut interpreted_as_const_sugg = None;
|
let mut interpreted_as_const_sugg = None;
|
||||||
|
|
||||||
if let PatKind::ExpandedConstant { def_id, is_inline: false, .. }
|
// These next few matches want to peek through `AscribeUserType` to see
|
||||||
| PatKind::AscribeUserType {
|
// the underlying pattern.
|
||||||
subpattern:
|
let mut unpeeled_pat = pat;
|
||||||
box Pat { kind: PatKind::ExpandedConstant { def_id, is_inline: false, .. }, .. },
|
while let PatKind::AscribeUserType { ref subpattern, .. } = unpeeled_pat.kind {
|
||||||
..
|
unpeeled_pat = subpattern;
|
||||||
} = pat.kind
|
}
|
||||||
|
|
||||||
|
if let PatKind::ExpandedConstant { def_id, is_inline: false, .. } = unpeeled_pat.kind
|
||||||
&& let DefKind::Const = self.tcx.def_kind(def_id)
|
&& let DefKind::Const = self.tcx.def_kind(def_id)
|
||||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
|
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
|
||||||
// We filter out paths with multiple path::segments.
|
// 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.
|
// When we encounter a constant as the binding name, point at the `const` definition.
|
||||||
interpreted_as_const = Some(span);
|
interpreted_as_const = Some(span);
|
||||||
interpreted_as_const_sugg = Some(InterpretedAsConst { span: pat.span, variable });
|
interpreted_as_const_sugg = Some(InterpretedAsConst { span: pat.span, variable });
|
||||||
} else if let PatKind::Constant { .. }
|
} else if let PatKind::Constant { .. } = unpeeled_pat.kind
|
||||||
| PatKind::AscribeUserType {
|
|
||||||
subpattern: box Pat { kind: PatKind::Constant { .. }, .. },
|
|
||||||
..
|
|
||||||
} = pat.kind
|
|
||||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
|
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
|
||||||
{
|
{
|
||||||
// If the pattern to match is an integer literal:
|
// If the pattern to match is an integer literal:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue