@@ -149,15 +149,18 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
149149            None  => Ok ( ( None ,  None ,  None ) ) , 
150150            Some ( expr)  => { 
151151                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 ) 
154157                    } 
155158                    PatKind :: AscribeUserType  {  ascription,  subpattern :  box Pat  {  kind,  .. }  }  => { 
156159                        ( kind,  Some ( ascription) ,  None ) 
157160                    } 
158161                    kind => ( kind,  None ,  None ) , 
159162                } ; 
160-                 let  value = if  let  PatKind :: Constant  {  value,   opt_def :  _  }  = kind { 
163+                 let  value = if  let  PatKind :: Constant  {  value }  = kind { 
161164                    value
162165                }  else  { 
163166                    let  msg = format ! ( 
@@ -251,7 +254,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
251254            ( RangeEnd :: Included ,  Some ( Ordering :: Less ) )  => { } 
252255            // `x..=y` where `x == y` and `x` and `y` are finite. 
253256            ( 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 ( )  } ; 
255258            } 
256259            // `..=x` where `x == ty::MIN`. 
257260            ( RangeEnd :: Included ,  Some ( Ordering :: Equal ) )  if  !lo. is_finite ( )  => { } 
@@ -288,7 +291,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
288291            } ; 
289292        } 
290293        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+             } ; 
292299        } 
293300        Ok ( kind) 
294301    } 
@@ -562,10 +569,20 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
562569
563570        let  args = self . typeck_results . node_args ( id) ; 
564571        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+         } ; 
569586
570587        if  !is_associated_const { 
571588            return  pattern; 
@@ -640,7 +657,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
640657
641658        let  ct = ty:: UnevaluatedConst  {  def :  def_id. to_def_id ( ) ,  args } ; 
642659        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  } 
644661    } 
645662
646663    /// Converts literals, paths and negation of literals to patterns. 
0 commit comments