@@ -19,8 +19,9 @@ use rustc_middle::mir::interpret::{get_slice_bytes, ConstValue};
1919use rustc_middle:: mir:: interpret:: { ErrorHandled , LitToConstError , LitToConstInput } ;
2020use rustc_middle:: mir:: { self , UserTypeProjection } ;
2121use 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 } ;
2323use rustc_middle:: ty:: subst:: { GenericArg , SubstsRef } ;
24+ use rustc_middle:: ty:: CanonicalUserTypeAnnotation ;
2425use rustc_middle:: ty:: { self , AdtDef , ConstKind , DefIdTree , Region , Ty , TyCtxt , UserType } ;
2526use rustc_span:: { Span , Symbol } ;
2627
@@ -227,7 +228,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
227228 for end in & [ lo, hi] {
228229 if let Some ( ( _, Some ( ascription) ) ) = end {
229230 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 } ;
231233 }
232234 }
233235
@@ -432,13 +434,14 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
432434
433435 if let Some ( user_ty) = self . user_substs_applied_to_ty_of_hir_id ( hir_id) {
434436 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+ } ;
435442 kind = PatKind :: AscribeUserType {
436443 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 } ,
442445 } ;
443446 }
444447
@@ -499,18 +502,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
499502 }
500503
501504 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+ } ;
504511 Pat {
505512 span,
506513 kind : Box :: new ( PatKind :: AscribeUserType {
507514 subpattern : pattern,
508515 ascription : Ascription {
516+ annotation,
509517 /// Note that use `Contravariant` here. See the
510518 /// `variance` field documentation for details.
511519 variance : ty:: Variance :: Contravariant ,
512- user_ty,
513- user_ty_span : span,
514520 } ,
515521 } ) ,
516522 ty : const_. ty ( ) ,
@@ -645,7 +651,7 @@ impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Option<T> {
645651 }
646652}
647653
648- macro_rules! CloneImpls {
654+ macro_rules! ClonePatternFoldableImpls {
649655 ( <$lt_tcx: tt> $( $ty: ty) ,+) => {
650656 $(
651657 impl <$lt_tcx> PatternFoldable <$lt_tcx> for $ty {
@@ -657,11 +663,11 @@ macro_rules! CloneImpls {
657663 }
658664}
659665
660- CloneImpls ! { <' tcx>
666+ ClonePatternFoldableImpls ! { <' tcx>
661667 Span , Field , Mutability , Symbol , hir:: HirId , usize , ty:: Const <' tcx>,
662668 Region <' tcx>, Ty <' tcx>, BindingMode , AdtDef <' tcx>,
663669 SubstsRef <' tcx>, & ' tcx GenericArg <' tcx>, UserType <' tcx>,
664- UserTypeProjection , PatTyProj <' tcx>
670+ UserTypeProjection , CanonicalUserTypeAnnotation <' tcx>
665671}
666672
667673impl < ' tcx > PatternFoldable < ' tcx > for FieldPat < ' tcx > {
@@ -694,14 +700,10 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
694700 PatKind :: Wild => PatKind :: Wild ,
695701 PatKind :: AscribeUserType {
696702 ref subpattern,
697- ascription : Ascription { variance , ref user_ty , user_ty_span } ,
703+ ascription : Ascription { ref annotation , variance } ,
698704 } => PatKind :: AscribeUserType {
699705 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 } ,
705707 } ,
706708 PatKind :: Binding { mutability, name, mode, var, ty, ref subpattern, is_primary } => {
707709 PatKind :: Binding {
0 commit comments