1
1
use rustc_hir as hir;
2
2
use rustc_index:: vec:: Idx ;
3
3
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
4
- use rustc_middle:: mir:: { self , Field } ;
4
+ use rustc_middle:: mir:: Field ;
5
5
use rustc_middle:: thir:: { FieldPat , Pat , PatKind } ;
6
6
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
7
7
use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
@@ -22,7 +22,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
22
22
#[ instrument( level = "debug" , skip( self ) ) ]
23
23
pub ( super ) fn const_to_pat (
24
24
& self ,
25
- cv : mir :: ConstantKind < ' tcx > ,
25
+ cv : ty :: Const < ' tcx > ,
26
26
id : hir:: HirId ,
27
27
span : Span ,
28
28
mir_structural_match_violation : bool ,
@@ -152,11 +152,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
152
152
ty. is_structural_eq_shallow ( self . infcx . tcx )
153
153
}
154
154
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 > {
160
156
trace ! ( self . treat_byte_string_as_slice) ;
161
157
// This method is just a wrapper handling a validity check; the heavy lifting is
162
158
// performed by the recursive `recur` method, which is not meant to be
@@ -250,7 +246,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
250
246
251
247
fn field_pats (
252
248
& self ,
253
- vals : impl Iterator < Item = mir :: ConstantKind < ' tcx > > ,
249
+ vals : impl Iterator < Item = ty :: Const < ' tcx > > ,
254
250
) -> Result < Vec < FieldPat < ' tcx > > , FallbackToConstRef > {
255
251
vals. enumerate ( )
256
252
. map ( |( idx, val) | {
@@ -263,7 +259,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
263
259
// Recursive helper for `to_pat`; invoke that (instead of calling this directly).
264
260
fn recur (
265
261
& self ,
266
- cv : mir :: ConstantKind < ' tcx > ,
262
+ cv : ty :: Const < ' tcx > ,
267
263
mir_structural_match_violation : bool ,
268
264
) -> Result < Pat < ' tcx > , FallbackToConstRef > {
269
265
let id = self . id ;
@@ -369,7 +365,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
369
365
PatKind :: Wild
370
366
}
371
367
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) ) ;
373
369
PatKind :: Variant {
374
370
adt_def : * adt_def,
375
371
substs,
@@ -380,12 +376,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
380
376
}
381
377
}
382
378
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) ) ;
384
380
PatKind :: Leaf { subpatterns : self . field_pats ( destructured. fields . iter ( ) . copied ( ) ) ? }
385
381
}
386
382
ty:: Array ( ..) => PatKind :: Array {
387
383
prefix : tcx
388
- . destructure_mir_constant ( param_env. and ( cv) )
384
+ . destructure_const ( param_env. and ( cv) )
389
385
. fields
390
386
. iter ( )
391
387
. map ( |val| self . recur ( * val, false ) )
@@ -416,12 +412,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
416
412
// arrays.
417
413
ty:: Array ( ..) if !self . treat_byte_string_as_slice => {
418
414
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) ) ;
420
416
let val = PatKind :: Deref {
421
417
subpattern : Pat {
422
418
kind : Box :: new ( PatKind :: Array {
423
419
prefix : tcx
424
- . destructure_mir_constant ( param_env. and ( array) )
420
+ . destructure_const ( param_env. and ( array) )
425
421
. fields
426
422
. iter ( )
427
423
. map ( |val| self . recur ( * val, false ) )
@@ -442,12 +438,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
442
438
// pattern.
443
439
ty:: Slice ( elem_ty) => {
444
440
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) ) ;
446
442
let val = PatKind :: Deref {
447
443
subpattern : Pat {
448
444
kind : Box :: new ( PatKind :: Slice {
449
445
prefix : tcx
450
- . destructure_mir_constant ( param_env. and ( array) )
446
+ . destructure_const ( param_env. and ( array) )
451
447
. fields
452
448
. iter ( )
453
449
. map ( |val| self . recur ( * val, false ) )
@@ -516,7 +512,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
516
512
// we fall back to a const pattern. If we do not do this, we may end up with
517
513
// a !structural-match constant that is not of reference type, which makes it
518
514
// 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 ) {
520
516
Ok ( subpattern) => PatKind :: Deref { subpattern } ,
521
517
Err ( _) => PatKind :: Constant { value : cv } ,
522
518
} ;
0 commit comments