@@ -155,11 +155,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
155
155
fn lower_pattern_range_endpoint (
156
156
& mut self ,
157
157
expr : Option < & ' tcx hir:: PatExpr < ' tcx > > ,
158
- ) -> Result <
159
- ( Option < PatRangeBoundary < ' tcx > > , Option < Ascription < ' tcx > > , Option < LocalDefId > ) ,
160
- ErrorGuaranteed ,
161
- > {
162
- let Some ( expr) = expr else { return Ok ( ( None , None , None ) ) } ;
158
+ // Out-parameters collecting extra data to be reapplied by the caller
159
+ ascriptions : & mut Vec < Ascription < ' tcx > > ,
160
+ inline_consts : & mut Vec < LocalDefId > ,
161
+ ) -> Result < Option < PatRangeBoundary < ' tcx > > , ErrorGuaranteed > {
162
+ let Some ( expr) = expr else { return Ok ( None ) } ;
163
163
164
164
let ( kind, ascr, inline_const) = match self . lower_lit ( expr) {
165
165
PatKind :: ExpandedConstant { subpattern, def_id, is_inline : true } => {
@@ -187,7 +187,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
187
187
return Err ( self . tcx . dcx ( ) . span_delayed_bug ( expr. span , msg) ) ;
188
188
}
189
189
} ;
190
- Ok ( ( Some ( PatRangeBoundary :: Finite ( value) ) , ascr, inline_const) )
190
+
191
+ ascriptions. extend ( ascr) ;
192
+ inline_consts. extend ( inline_const) ;
193
+ Ok ( Some ( PatRangeBoundary :: Finite ( value) ) )
191
194
}
192
195
193
196
/// Overflowing literals are linted against in a late pass. This is mostly fine, except when we
@@ -250,11 +253,15 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
250
253
self . tcx . dcx ( ) . span_bug ( span, msg) ;
251
254
}
252
255
253
- let ( lo, lo_ascr, lo_inline) = self . lower_pattern_range_endpoint ( lo_expr) ?;
254
- let ( hi, hi_ascr, hi_inline) = self . lower_pattern_range_endpoint ( hi_expr) ?;
256
+ // Collect extra data while lowering the endpoints, to be reapplied later.
257
+ let mut ascriptions = vec ! [ ] ;
258
+ let mut inline_consts = vec ! [ ] ;
259
+
260
+ let mut lower_endpoint =
261
+ |expr| self . lower_pattern_range_endpoint ( expr, & mut ascriptions, & mut inline_consts) ;
255
262
256
- let lo = lo . unwrap_or ( PatRangeBoundary :: NegInfinity ) ;
257
- let hi = hi . unwrap_or ( PatRangeBoundary :: PosInfinity ) ;
263
+ let lo = lower_endpoint ( lo_expr ) ? . unwrap_or ( PatRangeBoundary :: NegInfinity ) ;
264
+ let hi = lower_endpoint ( hi_expr ) ? . unwrap_or ( PatRangeBoundary :: PosInfinity ) ;
258
265
259
266
let cmp = lo. compare_with ( hi, ty, self . tcx , self . typing_env ) ;
260
267
let mut kind = PatKind :: Range ( Box :: new ( PatRange { lo, hi, end, ty } ) ) ;
@@ -295,13 +302,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
295
302
// If we are handling a range with associated constants (e.g.
296
303
// `Foo::<'a>::A..=Foo::B`), we need to put the ascriptions for the associated
297
304
// constants somewhere. Have them on the range pattern.
298
- for ascription in [ lo_ascr , hi_ascr ] . into_iter ( ) . flatten ( ) {
305
+ for ascription in ascriptions {
299
306
kind = PatKind :: AscribeUserType {
300
307
ascription,
301
308
subpattern : Box :: new ( Pat { span, ty, kind } ) ,
302
309
} ;
303
310
}
304
- for def in [ lo_inline , hi_inline ] . into_iter ( ) . flatten ( ) {
311
+ for def in inline_consts {
305
312
kind = PatKind :: ExpandedConstant {
306
313
def_id : def. to_def_id ( ) ,
307
314
is_inline : true ,
0 commit comments