@@ -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
@@ -606,11 +615,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
606
615
// const eval path below.
607
616
// FIXME: investigate the performance impact of removing this.
608
617
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
- }
618
+ hir:: ExprKind :: Lit ( lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : false } ) ,
619
+ hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , expr) => match expr. kind {
620
+ hir:: ExprKind :: Lit ( lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : true } ) ,
614
621
_ => None ,
615
622
} ,
616
623
_ => None ,
@@ -646,7 +653,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
646
653
span,
647
654
None ,
648
655
) ;
649
- PatKind :: InlineConstant { subpattern, value : uneval }
656
+ PatKind :: InlineConstant { subpattern, def : def_id }
650
657
} else {
651
658
// If that fails, convert it to an opaque constant pattern.
652
659
match tcx. const_eval_resolve ( self . param_env , uneval, Some ( span) ) {
@@ -828,8 +835,8 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
828
835
PatKind :: Deref { subpattern : subpattern. fold_with ( folder) }
829
836
}
830
837
PatKind :: Constant { value } => PatKind :: Constant { value } ,
831
- PatKind :: InlineConstant { value , subpattern : ref pattern } => {
832
- PatKind :: InlineConstant { value , subpattern : pattern. fold_with ( folder) }
838
+ PatKind :: InlineConstant { def , subpattern : ref pattern } => {
839
+ PatKind :: InlineConstant { def , subpattern : pattern. fold_with ( folder) }
833
840
}
834
841
PatKind :: Range ( ref range) => PatKind :: Range ( range. clone ( ) ) ,
835
842
PatKind :: Slice { ref prefix, ref slice, ref suffix } => PatKind :: Slice {
0 commit comments