@@ -27,6 +27,7 @@ use rustc_middle::ty::{
27
27
self , AdtDef , CanonicalUserTypeAnnotation , GenericArg , GenericArgsRef , Region , Ty , TyCtxt ,
28
28
TypeVisitableExt , UserType ,
29
29
} ;
30
+ use rustc_span:: def_id:: LocalDefId ;
30
31
use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
31
32
use rustc_target:: abi:: { FieldIdx , Integer } ;
32
33
@@ -88,19 +89,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
88
89
fn lower_pattern_range_endpoint (
89
90
& mut self ,
90
91
expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
91
- ) -> Result < ( Option < mir:: Const < ' tcx > > , Option < Ascription < ' tcx > > ) , ErrorGuaranteed > {
92
+ ) -> Result <
93
+ ( Option < mir:: Const < ' tcx > > , Option < Ascription < ' tcx > > , Option < LocalDefId > ) ,
94
+ ErrorGuaranteed ,
95
+ > {
92
96
match expr {
93
- None => Ok ( ( None , None ) ) ,
97
+ None => Ok ( ( None , None , None ) ) ,
94
98
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
- ) ,
99
+ let ( kind, ascr, inline_const) = match self . lower_lit ( expr) {
100
+ PatKind :: InlineConstant { subpattern, def } => {
101
+ ( subpattern. kind , None , Some ( def) )
102
+ }
100
103
PatKind :: AscribeUserType { ascription, subpattern : box Pat { kind, .. } } => {
101
- ( kind, Some ( ascription) )
104
+ ( kind, Some ( ascription) , None )
102
105
}
103
- kind => ( kind, None ) ,
106
+ kind => ( kind, None , None ) ,
104
107
} ;
105
108
let value = if let PatKind :: Constant { value } = kind {
106
109
value
@@ -110,7 +113,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
110
113
) ;
111
114
return Err ( self . tcx . sess . delay_span_bug ( expr. span , msg) ) ;
112
115
} ;
113
- Ok ( ( Some ( value) , ascr) )
116
+ Ok ( ( Some ( value) , ascr, inline_const ) )
114
117
}
115
118
}
116
119
}
@@ -181,8 +184,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
181
184
return Err ( self . tcx . sess . delay_span_bug ( span, msg) ) ;
182
185
}
183
186
184
- let ( lo, lo_ascr) = self . lower_pattern_range_endpoint ( lo_expr) ?;
185
- let ( hi, hi_ascr) = self . lower_pattern_range_endpoint ( hi_expr) ?;
187
+ let ( lo, lo_ascr, lo_inline ) = self . lower_pattern_range_endpoint ( lo_expr) ?;
188
+ let ( hi, hi_ascr, hi_inline ) = self . lower_pattern_range_endpoint ( hi_expr) ?;
186
189
187
190
let lo = lo. unwrap_or_else ( || {
188
191
// Unwrap is ok because the type is known to be numeric.
@@ -241,6 +244,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
241
244
} ;
242
245
}
243
246
}
247
+ for inline_const in [ lo_inline, hi_inline] {
248
+ if let Some ( def) = inline_const {
249
+ kind =
250
+ PatKind :: InlineConstant { def, subpattern : Box :: new ( Pat { span, ty, kind } ) } ;
251
+ }
252
+ }
244
253
Ok ( kind)
245
254
}
246
255
@@ -603,11 +612,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
603
612
// const eval path below.
604
613
// FIXME: investigate the performance impact of removing this.
605
614
let lit_input = match expr. kind {
606
- hir:: ExprKind :: Lit ( ref lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : false } ) ,
607
- hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , ref expr) => match expr. kind {
608
- hir:: ExprKind :: Lit ( ref lit) => {
609
- Some ( LitToConstInput { lit : & lit. node , ty, neg : true } )
610
- }
615
+ hir:: ExprKind :: Lit ( lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : false } ) ,
616
+ hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , expr) => match expr. kind {
617
+ hir:: ExprKind :: Lit ( lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : true } ) ,
611
618
_ => None ,
612
619
} ,
613
620
_ => None ,
@@ -643,7 +650,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
643
650
span,
644
651
None ,
645
652
) ;
646
- PatKind :: InlineConstant { subpattern, value : uneval }
653
+ PatKind :: InlineConstant { subpattern, def : def_id }
647
654
} else {
648
655
// If that fails, convert it to an opaque constant pattern.
649
656
match tcx. const_eval_resolve ( self . param_env , uneval, Some ( span) ) {
@@ -826,8 +833,8 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
826
833
PatKind :: Deref { subpattern : subpattern. fold_with ( folder) }
827
834
}
828
835
PatKind :: Constant { value } => PatKind :: Constant { value } ,
829
- PatKind :: InlineConstant { value , subpattern : ref pattern } => {
830
- PatKind :: InlineConstant { value , subpattern : pattern. fold_with ( folder) }
836
+ PatKind :: InlineConstant { def , subpattern : ref pattern } => {
837
+ PatKind :: InlineConstant { def , subpattern : pattern. fold_with ( folder) }
831
838
}
832
839
PatKind :: Range ( ref range) => PatKind :: Range ( range. clone ( ) ) ,
833
840
PatKind :: Slice { ref prefix, ref slice, ref suffix } => PatKind :: Slice {
0 commit comments