@@ -165,17 +165,23 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
165165 // deconstructed to obtain the constant value and other data.
166166 let mut kind: PatKind < ' tcx > = self . lower_lit ( expr) ;
167167
168- // Unpeel any ascription or inline-const wrapper nodes.
168+ // Unpeel any wrapper nodes, while preserving marker data that will
169+ // need to be reapplied to the range pattern node.
169170 loop {
170171 match kind {
171172 PatKind :: AscribeUserType { ascription, subpattern } => {
172173 ascriptions. push ( ascription) ;
173174 kind = subpattern. kind ;
174175 }
175- PatKind :: ExpandedConstant { is_inline, def_id, subpattern } => {
176- if is_inline {
177- inline_consts. extend ( def_id. as_local ( ) ) ;
178- }
176+ PatKind :: InlineConstMarker { def_id, subpattern } => {
177+ // Preserve inline-const markers, so that THIR unsafeck can
178+ // see const blocks that are part of a range pattern.
179+ inline_consts. push ( def_id) ;
180+ kind = subpattern. kind ;
181+ }
182+ PatKind :: NamedConstMarker { subpattern, .. } => {
183+ // Named-const markers are only used for improved diagnostics that
184+ // aren't relevant to range patterns, so it's OK to discard them.
179185 kind = subpattern. kind ;
180186 }
181187 _ => break ,
@@ -307,12 +313,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
307313 subpattern : Box :: new ( Pat { span, ty, kind } ) ,
308314 } ;
309315 }
310- for def in inline_consts {
311- kind = PatKind :: ExpandedConstant {
312- def_id : def. to_def_id ( ) ,
313- is_inline : true ,
314- subpattern : Box :: new ( Pat { span, ty, kind } ) ,
315- } ;
316+ // If one or both endpoints is an inline-const block, reapply the marker
317+ // nodes so that unsafeck can traverse into the corresponding block body.
318+ for def_id in inline_consts {
319+ let subpattern = Box :: new ( Pat { span, ty, kind } ) ;
320+ kind = PatKind :: InlineConstMarker { def_id, subpattern } ;
316321 }
317322 Ok ( kind)
318323 }
@@ -593,11 +598,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
593598 let args = self . typeck_results . node_args ( id) ;
594599 let c = ty:: Const :: new_unevaluated ( self . tcx , ty:: UnevaluatedConst { def : def_id, args } ) ;
595600 let subpattern = self . const_to_pat ( c, ty, id, span) ;
596- let pattern = Box :: new ( Pat {
597- span,
598- ty,
599- kind : PatKind :: ExpandedConstant { subpattern, def_id, is_inline : false } ,
600- } ) ;
601+ let pattern =
602+ Box :: new ( Pat { span, ty, kind : PatKind :: NamedConstMarker { subpattern, def_id } } ) ;
601603
602604 if !is_associated_const {
603605 return pattern;
@@ -648,7 +650,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
648650
649651 let ct = ty:: UnevaluatedConst { def : def_id. to_def_id ( ) , args } ;
650652 let subpattern = self . const_to_pat ( ty:: Const :: new_unevaluated ( self . tcx , ct) , ty, id, span) ;
651- PatKind :: ExpandedConstant { subpattern, def_id : def_id . to_def_id ( ) , is_inline : true }
653+ PatKind :: InlineConstMarker { subpattern, def_id }
652654 }
653655
654656 /// Converts literals, paths and negation of literals to patterns.
0 commit comments