@@ -161,35 +161,34 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
161
161
) -> Result < Option < PatRangeBoundary < ' tcx > > , ErrorGuaranteed > {
162
162
let Some ( expr) = expr else { return Ok ( None ) } ;
163
163
164
- let ( kind, ascr, inline_const) = match self . lower_lit ( expr) {
165
- PatKind :: ExpandedConstant { subpattern, def_id, is_inline : true } => {
166
- ( subpattern. kind , None , def_id. as_local ( ) )
167
- }
168
- PatKind :: ExpandedConstant { subpattern, is_inline : false , .. } => {
169
- ( subpattern. kind , None , None )
170
- }
171
- PatKind :: AscribeUserType { ascription, subpattern : box Pat { kind, .. } } => {
172
- ( kind, Some ( ascription) , None )
173
- }
174
- kind => ( kind, None , None ) ,
175
- } ;
176
- let value = match kind {
177
- PatKind :: Constant { value } => value,
178
- PatKind :: ExpandedConstant { subpattern, .. }
179
- if let PatKind :: Constant { value } = subpattern. kind =>
180
- {
181
- value
182
- }
183
- _ => {
184
- let msg = format ! (
185
- "found bad range pattern endpoint `{expr:?}` outside of error recovery"
186
- ) ;
187
- return Err ( self . tcx . dcx ( ) . span_delayed_bug ( expr. span , msg) ) ;
164
+ // Lower the endpoint into a temporary `PatKind` that will then be
165
+ // deconstructed to obtain the constant value and other data.
166
+ let mut kind: PatKind < ' tcx > = self . lower_lit ( expr) ;
167
+
168
+ // Unpeel any ascription or inline-const wrapper nodes.
169
+ loop {
170
+ match kind {
171
+ PatKind :: AscribeUserType { ascription, subpattern } => {
172
+ ascriptions. push ( ascription) ;
173
+ kind = subpattern. kind ;
174
+ }
175
+ PatKind :: ExpandedConstant { is_inline, def_id, subpattern } => {
176
+ if is_inline {
177
+ inline_consts. extend ( def_id. as_local ( ) ) ;
178
+ }
179
+ kind = subpattern. kind ;
180
+ }
181
+ _ => break ,
188
182
}
183
+ }
184
+
185
+ // The unpeeled kind should now be a constant, giving us the endpoint value.
186
+ let PatKind :: Constant { value } = kind else {
187
+ let msg =
188
+ format ! ( "found bad range pattern endpoint `{expr:?}` outside of error recovery" ) ;
189
+ return Err ( self . tcx . dcx ( ) . span_delayed_bug ( expr. span , msg) ) ;
189
190
} ;
190
191
191
- ascriptions. extend ( ascr) ;
192
- inline_consts. extend ( inline_const) ;
193
192
Ok ( Some ( PatRangeBoundary :: Finite ( value) ) )
194
193
}
195
194
0 commit comments