@@ -149,15 +149,18 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
149
149
None => Ok ( ( None , None , None ) ) ,
150
150
Some ( expr) => {
151
151
let ( kind, ascr, inline_const) = match self . lower_lit ( expr) {
152
- PatKind :: InlineConstant { subpattern, def } => {
153
- ( subpattern. kind , None , Some ( def) )
152
+ PatKind :: ExpandedConstant { subpattern, def_id, is_inline : true } => {
153
+ ( subpattern. kind , None , def_id. as_local ( ) )
154
+ }
155
+ PatKind :: ExpandedConstant { subpattern, is_inline : false , .. } => {
156
+ ( subpattern. kind , None , None )
154
157
}
155
158
PatKind :: AscribeUserType { ascription, subpattern : box Pat { kind, .. } } => {
156
159
( kind, Some ( ascription) , None )
157
160
}
158
161
kind => ( kind, None , None ) ,
159
162
} ;
160
- let value = if let PatKind :: Constant { value, opt_def : _ } = kind {
163
+ let value = if let PatKind :: Constant { value } = kind {
161
164
value
162
165
} else {
163
166
let msg = format ! (
@@ -251,7 +254,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
251
254
( RangeEnd :: Included , Some ( Ordering :: Less ) ) => { }
252
255
// `x..=y` where `x == y` and `x` and `y` are finite.
253
256
( RangeEnd :: Included , Some ( Ordering :: Equal ) ) if lo. is_finite ( ) && hi. is_finite ( ) => {
254
- kind = PatKind :: Constant { value : lo. as_finite ( ) . unwrap ( ) , opt_def : None } ;
257
+ kind = PatKind :: Constant { value : lo. as_finite ( ) . unwrap ( ) } ;
255
258
}
256
259
// `..=x` where `x == ty::MIN`.
257
260
( RangeEnd :: Included , Some ( Ordering :: Equal ) ) if !lo. is_finite ( ) => { }
@@ -288,7 +291,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
288
291
} ;
289
292
}
290
293
for def in [ lo_inline, hi_inline] . into_iter ( ) . flatten ( ) {
291
- kind = PatKind :: InlineConstant { def, subpattern : Box :: new ( Pat { span, ty, kind } ) } ;
294
+ kind = PatKind :: ExpandedConstant {
295
+ def_id : def. to_def_id ( ) ,
296
+ is_inline : true ,
297
+ subpattern : Box :: new ( Pat { span, ty, kind } ) ,
298
+ } ;
292
299
}
293
300
Ok ( kind)
294
301
}
@@ -562,10 +569,20 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
562
569
563
570
let args = self . typeck_results . node_args ( id) ;
564
571
let c = ty:: Const :: new_unevaluated ( self . tcx , ty:: UnevaluatedConst { def : def_id, args } ) ;
565
- let mut pattern = self . const_to_pat ( c, ty, id, span) ;
566
- if let PatKind :: Constant { value, opt_def : None } = pattern. kind {
567
- pattern. kind = PatKind :: Constant { value, opt_def : Some ( def_id) } ;
568
- }
572
+ let subpattern = self . const_to_pat ( c, ty, id, span) ;
573
+ let pattern = if let hir:: QPath :: Resolved ( None , path) = qpath
574
+ && path. segments . len ( ) == 1
575
+ {
576
+ // We only want to mark constants when referenced as bare names that could have been
577
+ // new bindings if the `const` didn't exist.
578
+ Box :: new ( Pat {
579
+ span,
580
+ ty,
581
+ kind : PatKind :: ExpandedConstant { subpattern, def_id, is_inline : false } ,
582
+ } )
583
+ } else {
584
+ subpattern
585
+ } ;
569
586
570
587
if !is_associated_const {
571
588
return pattern;
@@ -640,7 +657,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
640
657
641
658
let ct = ty:: UnevaluatedConst { def : def_id. to_def_id ( ) , args } ;
642
659
let subpattern = self . const_to_pat ( ty:: Const :: new_unevaluated ( self . tcx , ct) , ty, id, span) ;
643
- PatKind :: InlineConstant { subpattern, def : def_id }
660
+ PatKind :: ExpandedConstant { subpattern, def_id : def_id. to_def_id ( ) , is_inline : true }
644
661
}
645
662
646
663
/// Converts literals, paths and negation of literals to patterns.
0 commit comments