@@ -676,12 +676,14 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
676
676
let mut interpreted_as_const = None ;
677
677
let mut interpreted_as_const_sugg = None ;
678
678
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
685
687
&& let DefKind :: Const = self . tcx . def_kind ( def_id)
686
688
&& let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( pat. span )
687
689
// We filter out paths with multiple path::segments.
@@ -692,11 +694,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
692
694
// When we encounter a constant as the binding name, point at the `const` definition.
693
695
interpreted_as_const = Some ( span) ;
694
696
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
700
698
&& let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( pat. span )
701
699
{
702
700
// If the pattern to match is an integer literal:
0 commit comments