@@ -576,7 +576,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
576576 initializer_id : ExprId ,
577577 ) -> BlockAnd < ( ) > {
578578 match irrefutable_pat. kind {
579- // Optimize the case of `let x = ...` to write directly into `x`
579+ // Optimize `let x = ...` and `let x: T = ...` to write directly into `x`,
580+ // and then require that `T == typeof(x)` if present.
580581 PatKind :: Binding { mode : BindingMode ( ByRef :: No , _) , var, subpattern : None , .. } => {
581582 let place = self . storage_live_binding (
582583 block,
@@ -592,43 +593,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
592593 let source_info = self . source_info ( irrefutable_pat. span ) ;
593594 self . cfg . push_fake_read ( block, source_info, FakeReadCause :: ForLet ( None ) , place) ;
594595
595- self . schedule_drop_for_binding ( var, irrefutable_pat. span , OutsideGuard ) ;
596- block. unit ( )
597- }
598-
599- // Optimize the case of `let x: T = ...` to write directly
600- // into `x` and then require that `T == typeof(x)`.
601- PatKind :: AscribeUserType {
602- ref subpattern,
603- ascription : thir:: Ascription { ref annotation, variance : _ } ,
604- } if let PatKind :: Binding {
605- mode : BindingMode ( ByRef :: No , _) ,
606- var,
607- subpattern : None ,
608- ..
609- } = subpattern. kind =>
610- {
611- let place = self . storage_live_binding (
612- block,
613- var,
614- irrefutable_pat. span ,
615- false ,
616- OutsideGuard ,
617- ScheduleDrops :: Yes ,
618- ) ;
619- block = self . expr_into_dest ( place, block, initializer_id) . into_block ( ) ;
596+ let ascriptions: & [ _ ] =
597+ try { irrefutable_pat. extra . as_deref ( ) ?. ascriptions . as_slice ( ) }
598+ . unwrap_or_default ( ) ;
599+ for thir:: Ascription { annotation, variance : _ } in ascriptions {
600+ let ty_source_info = self . source_info ( annotation. span ) ;
620601
621- // Inject a fake read, see comments on `FakeReadCause::ForLet`.
622- let pattern_source_info = self . source_info ( irrefutable_pat. span ) ;
623- let cause_let = FakeReadCause :: ForLet ( None ) ;
624- self . cfg . push_fake_read ( block, pattern_source_info, cause_let, place) ;
625-
626- let ty_source_info = self . source_info ( annotation. span ) ;
627-
628- let base = self . canonical_user_type_annotations . push ( annotation. clone ( ) ) ;
629- self . cfg . push (
630- block,
631- Statement :: new (
602+ let base = self . canonical_user_type_annotations . push ( annotation. clone ( ) ) ;
603+ let stmt = Statement :: new (
632604 ty_source_info,
633605 StatementKind :: AscribeUserType (
634606 Box :: new ( ( place, UserTypeProjection { base, projs : Vec :: new ( ) } ) ) ,
@@ -648,8 +620,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
648620 // `<expr>`.
649621 ty:: Invariant ,
650622 ) ,
651- ) ,
652- ) ;
623+ ) ;
624+ self . cfg . push ( block, stmt) ;
625+ }
653626
654627 self . schedule_drop_for_binding ( var, irrefutable_pat. span , OutsideGuard ) ;
655628 block. unit ( )
@@ -884,9 +857,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
884857 // Caution: Pushing user types here is load-bearing even for
885858 // patterns containing no bindings, to ensure that the type ends
886859 // up represented in MIR _somewhere_.
887- let user_tys = match pattern. kind {
888- PatKind :: AscribeUserType { ref ascription, .. } => {
889- let base_user_tys = std:: iter:: once ( ascription)
860+ let user_tys = match pattern. extra . as_deref ( ) {
861+ Some ( PatExtra { ascriptions, .. } ) if !ascriptions. is_empty ( ) => {
862+ let base_user_tys = ascriptions
863+ . iter ( )
890864 . map ( |thir:: Ascription { annotation, variance : _ } | {
891865 // Note that the variance doesn't apply here, as we are tracking the effect
892866 // of user types on any bindings contained with subpattern.
@@ -943,15 +917,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
943917 visit_subpat ( self , subpattern, & ProjectedUserTypesNode :: None , f) ;
944918 }
945919
946- PatKind :: AscribeUserType { ref subpattern, ascription : _ } => {
947- // The ascription was already handled above, so just recurse to the subpattern.
948- visit_subpat ( self , subpattern, user_tys, f)
949- }
950-
951- PatKind :: ExpandedConstant { ref subpattern, .. } => {
952- visit_subpat ( self , subpattern, user_tys, f)
953- }
954-
955920 PatKind :: Leaf { ref subpatterns } => {
956921 for subpattern in subpatterns {
957922 let subpattern_user_tys = user_tys. leaf ( subpattern. field ) ;
0 commit comments