@@ -20,7 +20,9 @@ use rustc_index::Idx;
2020use rustc_middle:: mir:: interpret:: {
2121 ErrorHandled , GlobalId , LitToConstError , LitToConstInput , Scalar ,
2222} ;
23- use rustc_middle:: mir:: { self , BorrowKind , Const , Mutability , UserTypeProjection } ;
23+ use rustc_middle:: mir:: {
24+ self , BorrowKind , Const , Mutability , UnevaluatedConst , UserTypeProjection ,
25+ } ;
2426use rustc_middle:: thir:: { Ascription , BindingMode , FieldPat , LocalVarId , Pat , PatKind , PatRange } ;
2527use rustc_middle:: ty:: layout:: IntegerExt ;
2628use rustc_middle:: ty:: {
@@ -88,19 +90,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
8890 fn lower_pattern_range_endpoint (
8991 & mut self ,
9092 expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
91- ) -> Result < ( Option < mir:: Const < ' tcx > > , Option < Ascription < ' tcx > > ) , ErrorGuaranteed > {
93+ ) -> Result <
94+ ( Option < mir:: Const < ' tcx > > , Option < Ascription < ' tcx > > , Option < UnevaluatedConst < ' tcx > > ) ,
95+ ErrorGuaranteed ,
96+ > {
9297 match expr {
93- None => Ok ( ( None , None ) ) ,
98+ None => Ok ( ( None , None , None ) ) ,
9499 Some ( expr) => {
95- let ( kind, ascr) = match self . lower_lit ( expr) {
96- PatKind :: InlineConstant { subpattern, value } => (
97- PatKind :: Constant { value : Const :: Unevaluated ( value, subpattern. ty ) } ,
98- None ,
99- ) ,
100+ let ( kind, ascr, inline_const) = match self . lower_lit ( expr) {
101+ PatKind :: InlineConstant { subpattern, value } => {
102+ ( subpattern. kind , None , Some ( value) )
103+ }
100104 PatKind :: AscribeUserType { ascription, subpattern : box Pat { kind, .. } } => {
101- ( kind, Some ( ascription) )
105+ ( kind, Some ( ascription) , None )
102106 }
103- kind => ( kind, None ) ,
107+ kind => ( kind, None , None ) ,
104108 } ;
105109 let value = if let PatKind :: Constant { value } = kind {
106110 value
@@ -110,7 +114,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
110114 ) ;
111115 return Err ( self . tcx . sess . delay_span_bug ( expr. span , msg) ) ;
112116 } ;
113- Ok ( ( Some ( value) , ascr) )
117+ Ok ( ( Some ( value) , ascr, inline_const ) )
114118 }
115119 }
116120 }
@@ -181,8 +185,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
181185 return Err ( self . tcx . sess . delay_span_bug ( span, msg) ) ;
182186 }
183187
184- let ( lo, lo_ascr) = self . lower_pattern_range_endpoint ( lo_expr) ?;
185- let ( hi, hi_ascr) = self . lower_pattern_range_endpoint ( hi_expr) ?;
188+ let ( lo, lo_ascr, lo_inline ) = self . lower_pattern_range_endpoint ( lo_expr) ?;
189+ let ( hi, hi_ascr, hi_inline ) = self . lower_pattern_range_endpoint ( hi_expr) ?;
186190
187191 let lo = lo. unwrap_or_else ( || {
188192 // Unwrap is ok because the type is known to be numeric.
@@ -241,6 +245,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
241245 } ;
242246 }
243247 }
248+ for inline_const in [ lo_inline, hi_inline] {
249+ if let Some ( value) = inline_const {
250+ kind =
251+ PatKind :: InlineConstant { value, subpattern : Box :: new ( Pat { span, ty, kind } ) } ;
252+ }
253+ }
244254 Ok ( kind)
245255 }
246256
@@ -606,11 +616,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
606616 // const eval path below.
607617 // FIXME: investigate the performance impact of removing this.
608618 let lit_input = match expr. kind {
609- hir:: ExprKind :: Lit ( ref lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : false } ) ,
610- hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , ref expr) => match expr. kind {
611- hir:: ExprKind :: Lit ( ref lit) => {
612- Some ( LitToConstInput { lit : & lit. node , ty, neg : true } )
613- }
619+ hir:: ExprKind :: Lit ( lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : false } ) ,
620+ hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , expr) => match expr. kind {
621+ hir:: ExprKind :: Lit ( lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : true } ) ,
614622 _ => None ,
615623 } ,
616624 _ => None ,
0 commit comments