@@ -155,11 +155,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
155155 fn lower_pattern_range_endpoint (
156156 & mut self ,
157157 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 ) } ;
163163
164164 let ( kind, ascr, inline_const) = match self . lower_lit ( expr) {
165165 PatKind :: ExpandedConstant { subpattern, def_id, is_inline : true } => {
@@ -187,7 +187,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
187187 return Err ( self . tcx . dcx ( ) . span_delayed_bug ( expr. span , msg) ) ;
188188 }
189189 } ;
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) ) )
191194 }
192195
193196 /// 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> {
250253 self . tcx . dcx ( ) . span_bug ( span, msg) ;
251254 }
252255
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) ;
255262
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 ) ;
258265
259266 let cmp = lo. compare_with ( hi, ty, self . tcx , self . typing_env ) ;
260267 let mut kind = PatKind :: Range ( Box :: new ( PatRange { lo, hi, end, ty } ) ) ;
@@ -295,13 +302,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
295302 // If we are handling a range with associated constants (e.g.
296303 // `Foo::<'a>::A..=Foo::B`), we need to put the ascriptions for the associated
297304 // constants somewhere. Have them on the range pattern.
298- for ascription in [ lo_ascr , hi_ascr ] . into_iter ( ) . flatten ( ) {
305+ for ascription in ascriptions {
299306 kind = PatKind :: AscribeUserType {
300307 ascription,
301308 subpattern : Box :: new ( Pat { span, ty, kind } ) ,
302309 } ;
303310 }
304- for def in [ lo_inline , hi_inline ] . into_iter ( ) . flatten ( ) {
311+ for def in inline_consts {
305312 kind = PatKind :: ExpandedConstant {
306313 def_id : def. to_def_id ( ) ,
307314 is_inline : true ,
0 commit comments