@@ -20,7 +20,9 @@ use rustc_index::Idx;
20
20
use rustc_middle:: mir:: interpret:: {
21
21
ErrorHandled , GlobalId , LitToConstError , LitToConstInput , Scalar ,
22
22
} ;
23
- use rustc_middle:: mir:: { self , BorrowKind , Const , Mutability , UserTypeProjection } ;
23
+ use rustc_middle:: mir:: {
24
+ self , BorrowKind , Const , Mutability , UnevaluatedConst , UserTypeProjection ,
25
+ } ;
24
26
use rustc_middle:: thir:: { Ascription , BindingMode , FieldPat , LocalVarId , Pat , PatKind , PatRange } ;
25
27
use rustc_middle:: ty:: layout:: IntegerExt ;
26
28
use rustc_middle:: ty:: {
@@ -88,19 +90,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
88
90
fn lower_pattern_range_endpoint (
89
91
& mut self ,
90
92
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
+ > {
92
97
match expr {
93
- None => Ok ( ( None , None ) ) ,
98
+ None => Ok ( ( None , None , None ) ) ,
94
99
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
+ }
100
104
PatKind :: AscribeUserType { ascription, subpattern : box Pat { kind, .. } } => {
101
- ( kind, Some ( ascription) )
105
+ ( kind, Some ( ascription) , None )
102
106
}
103
- kind => ( kind, None ) ,
107
+ kind => ( kind, None , None ) ,
104
108
} ;
105
109
let value = if let PatKind :: Constant { value } = kind {
106
110
value
@@ -110,7 +114,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
110
114
) ;
111
115
return Err ( self . tcx . sess . delay_span_bug ( expr. span , msg) ) ;
112
116
} ;
113
- Ok ( ( Some ( value) , ascr) )
117
+ Ok ( ( Some ( value) , ascr, inline_const ) )
114
118
}
115
119
}
116
120
}
@@ -181,8 +185,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
181
185
return Err ( self . tcx . sess . delay_span_bug ( span, msg) ) ;
182
186
}
183
187
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) ?;
186
190
187
191
let lo = lo. unwrap_or_else ( || {
188
192
// Unwrap is ok because the type is known to be numeric.
@@ -241,6 +245,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
241
245
} ;
242
246
}
243
247
}
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
+ }
244
254
Ok ( kind)
245
255
}
246
256
@@ -606,11 +616,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
606
616
// const eval path below.
607
617
// FIXME: investigate the performance impact of removing this.
608
618
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 } ) ,
614
622
_ => None ,
615
623
} ,
616
624
_ => None ,
0 commit comments