@@ -19,8 +19,9 @@ use rustc_middle::mir::interpret::{get_slice_bytes, ConstValue};
19
19
use rustc_middle:: mir:: interpret:: { ErrorHandled , LitToConstError , LitToConstInput } ;
20
20
use rustc_middle:: mir:: { self , UserTypeProjection } ;
21
21
use rustc_middle:: mir:: { BorrowKind , Field , Mutability } ;
22
- use rustc_middle:: thir:: { Ascription , BindingMode , FieldPat , Pat , PatKind , PatRange , PatTyProj } ;
22
+ use rustc_middle:: thir:: { Ascription , BindingMode , FieldPat , Pat , PatKind , PatRange } ;
23
23
use rustc_middle:: ty:: subst:: { GenericArg , SubstsRef } ;
24
+ use rustc_middle:: ty:: CanonicalUserTypeAnnotation ;
24
25
use rustc_middle:: ty:: { self , AdtDef , ConstKind , DefIdTree , Region , Ty , TyCtxt , UserType } ;
25
26
use rustc_span:: { Span , Symbol } ;
26
27
@@ -227,7 +228,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
227
228
for end in & [ lo, hi] {
228
229
if let Some ( ( _, Some ( ascription) ) ) = end {
229
230
let subpattern = Pat { span : pat. span , ty, kind : Box :: new ( kind) } ;
230
- kind = PatKind :: AscribeUserType { ascription : * ascription, subpattern } ;
231
+ kind =
232
+ PatKind :: AscribeUserType { ascription : ascription. clone ( ) , subpattern } ;
231
233
}
232
234
}
233
235
@@ -432,13 +434,14 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
432
434
433
435
if let Some ( user_ty) = self . user_substs_applied_to_ty_of_hir_id ( hir_id) {
434
436
debug ! ( "lower_variant_or_leaf: kind={:?} user_ty={:?} span={:?}" , kind, user_ty, span) ;
437
+ let annotation = CanonicalUserTypeAnnotation {
438
+ user_ty,
439
+ span,
440
+ inferred_ty : self . typeck_results . node_type ( hir_id) ,
441
+ } ;
435
442
kind = PatKind :: AscribeUserType {
436
443
subpattern : Pat { span, ty, kind : Box :: new ( kind) } ,
437
- ascription : Ascription {
438
- user_ty : PatTyProj :: from_user_type ( user_ty) ,
439
- user_ty_span : span,
440
- variance : ty:: Variance :: Covariant ,
441
- } ,
444
+ ascription : Ascription { annotation, variance : ty:: Variance :: Covariant } ,
442
445
} ;
443
446
}
444
447
@@ -499,18 +502,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
499
502
}
500
503
501
504
let user_provided_types = self . typeck_results ( ) . user_provided_types ( ) ;
502
- if let Some ( u_ty) = user_provided_types. get ( id) {
503
- let user_ty = PatTyProj :: from_user_type ( * u_ty) ;
505
+ if let Some ( & user_ty) = user_provided_types. get ( id) {
506
+ let annotation = CanonicalUserTypeAnnotation {
507
+ user_ty,
508
+ span,
509
+ inferred_ty : self . typeck_results ( ) . node_type ( id) ,
510
+ } ;
504
511
Pat {
505
512
span,
506
513
kind : Box :: new ( PatKind :: AscribeUserType {
507
514
subpattern : pattern,
508
515
ascription : Ascription {
516
+ annotation,
509
517
/// Note that use `Contravariant` here. See the
510
518
/// `variance` field documentation for details.
511
519
variance : ty:: Variance :: Contravariant ,
512
- user_ty,
513
- user_ty_span : span,
514
520
} ,
515
521
} ) ,
516
522
ty : const_. ty ( ) ,
@@ -645,7 +651,7 @@ impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Option<T> {
645
651
}
646
652
}
647
653
648
- macro_rules! CloneImpls {
654
+ macro_rules! ClonePatternFoldableImpls {
649
655
( <$lt_tcx: tt> $( $ty: ty) ,+) => {
650
656
$(
651
657
impl <$lt_tcx> PatternFoldable <$lt_tcx> for $ty {
@@ -657,11 +663,11 @@ macro_rules! CloneImpls {
657
663
}
658
664
}
659
665
660
- CloneImpls ! { <' tcx>
666
+ ClonePatternFoldableImpls ! { <' tcx>
661
667
Span , Field , Mutability , Symbol , hir:: HirId , usize , ty:: Const <' tcx>,
662
668
Region <' tcx>, Ty <' tcx>, BindingMode , AdtDef <' tcx>,
663
669
SubstsRef <' tcx>, & ' tcx GenericArg <' tcx>, UserType <' tcx>,
664
- UserTypeProjection , PatTyProj <' tcx>
670
+ UserTypeProjection , CanonicalUserTypeAnnotation <' tcx>
665
671
}
666
672
667
673
impl < ' tcx > PatternFoldable < ' tcx > for FieldPat < ' tcx > {
@@ -694,14 +700,10 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
694
700
PatKind :: Wild => PatKind :: Wild ,
695
701
PatKind :: AscribeUserType {
696
702
ref subpattern,
697
- ascription : Ascription { variance , ref user_ty , user_ty_span } ,
703
+ ascription : Ascription { ref annotation , variance } ,
698
704
} => PatKind :: AscribeUserType {
699
705
subpattern : subpattern. fold_with ( folder) ,
700
- ascription : Ascription {
701
- user_ty : user_ty. fold_with ( folder) ,
702
- variance,
703
- user_ty_span,
704
- } ,
706
+ ascription : Ascription { annotation : annotation. fold_with ( folder) , variance } ,
705
707
} ,
706
708
PatKind :: Binding { mutability, name, mode, var, ty, ref subpattern, is_primary } => {
707
709
PatKind :: Binding {
0 commit comments