@@ -27,6 +27,7 @@ use rustc_middle::ty::{
2727 self , AdtDef , CanonicalUserTypeAnnotation , GenericArg , GenericArgsRef , Region , Ty , TyCtxt ,
2828 TypeVisitableExt , UserType ,
2929} ;
30+ use rustc_span:: def_id:: LocalDefId ;
3031use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
3132use rustc_target:: abi:: { FieldIdx , Integer } ;
3233
@@ -88,19 +89,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
8889 fn lower_pattern_range_endpoint (
8990 & mut self ,
9091 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+ > {
9296 match expr {
93- None => Ok ( ( None , None ) ) ,
97+ None => Ok ( ( None , None , None ) ) ,
9498 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+ }
100103 PatKind :: AscribeUserType { ascription, subpattern : box Pat { kind, .. } } => {
101- ( kind, Some ( ascription) )
104+ ( kind, Some ( ascription) , None )
102105 }
103- kind => ( kind, None ) ,
106+ kind => ( kind, None , None ) ,
104107 } ;
105108 let value = if let PatKind :: Constant { value } = kind {
106109 value
@@ -110,7 +113,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
110113 ) ;
111114 return Err ( self . tcx . sess . delay_span_bug ( expr. span , msg) ) ;
112115 } ;
113- Ok ( ( Some ( value) , ascr) )
116+ Ok ( ( Some ( value) , ascr, inline_const ) )
114117 }
115118 }
116119 }
@@ -181,8 +184,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
181184 return Err ( self . tcx . sess . delay_span_bug ( span, msg) ) ;
182185 }
183186
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) ?;
186189
187190 let lo = lo. unwrap_or_else ( || {
188191 // Unwrap is ok because the type is known to be numeric.
@@ -241,6 +244,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
241244 } ;
242245 }
243246 }
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+ }
244253 Ok ( kind)
245254 }
246255
@@ -606,11 +615,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
606615 // const eval path below.
607616 // FIXME: investigate the performance impact of removing this.
608617 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 } ) ,
614621 _ => None ,
615622 } ,
616623 _ => None ,
@@ -646,7 +653,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
646653 span,
647654 None ,
648655 ) ;
649- PatKind :: InlineConstant { subpattern, value : uneval }
656+ PatKind :: InlineConstant { subpattern, def : def_id }
650657 } else {
651658 // If that fails, convert it to an opaque constant pattern.
652659 match tcx. const_eval_resolve ( self . param_env , uneval, Some ( span) ) {
@@ -828,8 +835,8 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
828835 PatKind :: Deref { subpattern : subpattern. fold_with ( folder) }
829836 }
830837 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) }
833840 }
834841 PatKind :: Range ( ref range) => PatKind :: Range ( range. clone ( ) ) ,
835842 PatKind :: Slice { ref prefix, ref slice, ref suffix } => PatKind :: Slice {
0 commit comments