11use rustc_hir as hir;
22use rustc_index:: vec:: Idx ;
33use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
4- use rustc_middle:: mir:: { self , Field } ;
4+ use rustc_middle:: mir:: Field ;
55use rustc_middle:: thir:: { FieldPat , Pat , PatKind } ;
66use rustc_middle:: ty:: print:: with_no_trimmed_paths;
77use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
@@ -22,7 +22,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
2222 #[ instrument( level = "debug" , skip( self ) ) ]
2323 pub ( super ) fn const_to_pat (
2424 & self ,
25- cv : mir :: ConstantKind < ' tcx > ,
25+ cv : ty :: Const < ' tcx > ,
2626 id : hir:: HirId ,
2727 span : Span ,
2828 mir_structural_match_violation : bool ,
@@ -152,11 +152,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
152152 ty. is_structural_eq_shallow ( self . infcx . tcx )
153153 }
154154
155- fn to_pat (
156- & mut self ,
157- cv : mir:: ConstantKind < ' tcx > ,
158- mir_structural_match_violation : bool ,
159- ) -> Pat < ' tcx > {
155+ fn to_pat ( & mut self , cv : ty:: Const < ' tcx > , mir_structural_match_violation : bool ) -> Pat < ' tcx > {
160156 trace ! ( self . treat_byte_string_as_slice) ;
161157 // This method is just a wrapper handling a validity check; the heavy lifting is
162158 // performed by the recursive `recur` method, which is not meant to be
@@ -250,7 +246,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
250246
251247 fn field_pats (
252248 & self ,
253- vals : impl Iterator < Item = mir :: ConstantKind < ' tcx > > ,
249+ vals : impl Iterator < Item = ty :: Const < ' tcx > > ,
254250 ) -> Result < Vec < FieldPat < ' tcx > > , FallbackToConstRef > {
255251 vals. enumerate ( )
256252 . map ( |( idx, val) | {
@@ -263,7 +259,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
263259 // Recursive helper for `to_pat`; invoke that (instead of calling this directly).
264260 fn recur (
265261 & self ,
266- cv : mir :: ConstantKind < ' tcx > ,
262+ cv : ty :: Const < ' tcx > ,
267263 mir_structural_match_violation : bool ,
268264 ) -> Result < Pat < ' tcx > , FallbackToConstRef > {
269265 let id = self . id ;
@@ -369,7 +365,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
369365 PatKind :: Wild
370366 }
371367 ty:: Adt ( adt_def, substs) if adt_def. is_enum ( ) => {
372- let destructured = tcx. destructure_mir_constant ( param_env. and ( cv) ) ;
368+ let destructured = tcx. destructure_const ( param_env. and ( cv) ) ;
373369 PatKind :: Variant {
374370 adt_def : * adt_def,
375371 substs,
@@ -380,12 +376,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
380376 }
381377 }
382378 ty:: Tuple ( _) | ty:: Adt ( _, _) => {
383- let destructured = tcx. destructure_mir_constant ( param_env. and ( cv) ) ;
379+ let destructured = tcx. destructure_const ( param_env. and ( cv) ) ;
384380 PatKind :: Leaf { subpatterns : self . field_pats ( destructured. fields . iter ( ) . copied ( ) ) ? }
385381 }
386382 ty:: Array ( ..) => PatKind :: Array {
387383 prefix : tcx
388- . destructure_mir_constant ( param_env. and ( cv) )
384+ . destructure_const ( param_env. and ( cv) )
389385 . fields
390386 . iter ( )
391387 . map ( |val| self . recur ( * val, false ) )
@@ -416,12 +412,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
416412 // arrays.
417413 ty:: Array ( ..) if !self . treat_byte_string_as_slice => {
418414 let old = self . behind_reference . replace ( true ) ;
419- let array = tcx. deref_mir_constant ( self . param_env . and ( cv) ) ;
415+ let array = tcx. deref_const ( self . param_env . and ( cv) ) ;
420416 let val = PatKind :: Deref {
421417 subpattern : Pat {
422418 kind : Box :: new ( PatKind :: Array {
423419 prefix : tcx
424- . destructure_mir_constant ( param_env. and ( array) )
420+ . destructure_const ( param_env. and ( array) )
425421 . fields
426422 . iter ( )
427423 . map ( |val| self . recur ( * val, false ) )
@@ -442,12 +438,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
442438 // pattern.
443439 ty:: Slice ( elem_ty) => {
444440 let old = self . behind_reference . replace ( true ) ;
445- let array = tcx. deref_mir_constant ( self . param_env . and ( cv) ) ;
441+ let array = tcx. deref_const ( self . param_env . and ( cv) ) ;
446442 let val = PatKind :: Deref {
447443 subpattern : Pat {
448444 kind : Box :: new ( PatKind :: Slice {
449445 prefix : tcx
450- . destructure_mir_constant ( param_env. and ( array) )
446+ . destructure_const ( param_env. and ( array) )
451447 . fields
452448 . iter ( )
453449 . map ( |val| self . recur ( * val, false ) )
@@ -516,7 +512,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
516512 // we fall back to a const pattern. If we do not do this, we may end up with
517513 // a !structural-match constant that is not of reference type, which makes it
518514 // very hard to invoke `PartialEq::eq` on it as a fallback.
519- let val = match self . recur ( tcx. deref_mir_constant ( self . param_env . and ( cv) ) , false ) {
515+ let val = match self . recur ( tcx. deref_const ( self . param_env . and ( cv) ) , false ) {
520516 Ok ( subpattern) => PatKind :: Deref { subpattern } ,
521517 Err ( _) => PatKind :: Constant { value : cv } ,
522518 } ;
0 commit comments