@@ -399,7 +399,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
399399 let num_patterns = patterns. len ( ) ;
400400 self . visit_bindings (
401401 & patterns[ 0 ] ,
402- & mut |this, mutability, name, mode, var, span, ty| {
402+ None ,
403+ & mut |this, mutability, name, mode, var, span, ty, user_ty| {
403404 if visibility_scope. is_none ( ) {
404405 visibility_scope =
405406 Some ( this. new_source_scope ( scope_span, LintLevel :: Inherited , None ) ) ;
@@ -421,6 +422,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
421422 num_patterns,
422423 var,
423424 ty,
425+ user_ty,
424426 has_guard,
425427 opt_match_place. map ( |( x, y) | ( x. cloned ( ) , y) ) ,
426428 patterns[ 0 ] . span ,
@@ -470,10 +472,21 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
470472 ) ;
471473 }
472474
473- pub fn visit_bindings < F > ( & mut self , pattern : & Pattern < ' tcx > , f : & mut F )
474- where
475- F : FnMut ( & mut Self , Mutability , Name , BindingMode , NodeId , Span , Ty < ' tcx > ) ,
476- {
475+ pub fn visit_bindings (
476+ & mut self ,
477+ pattern : & Pattern < ' tcx > ,
478+ pattern_user_ty : Option < CanonicalTy < ' tcx > > ,
479+ f : & mut impl FnMut (
480+ & mut Self ,
481+ Mutability ,
482+ Name ,
483+ BindingMode ,
484+ NodeId ,
485+ Span ,
486+ Ty < ' tcx > ,
487+ Option < CanonicalTy < ' tcx > > ,
488+ ) ,
489+ ) {
477490 match * pattern. kind {
478491 PatternKind :: Binding {
479492 mutability,
@@ -484,9 +497,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
484497 ref subpattern,
485498 ..
486499 } => {
487- f ( self , mutability, name, mode, var, pattern. span , ty) ;
500+ f ( self , mutability, name, mode, var, pattern. span , ty, pattern_user_ty ) ;
488501 if let Some ( subpattern) = subpattern. as_ref ( ) {
489- self . visit_bindings ( subpattern, f) ;
502+ self . visit_bindings ( subpattern, pattern_user_ty , f) ;
490503 }
491504 }
492505 PatternKind :: Array {
@@ -499,21 +512,34 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
499512 ref slice,
500513 ref suffix,
501514 } => {
515+ // FIXME(#47184): extract or handle `pattern_user_ty` somehow
502516 for subpattern in prefix. iter ( ) . chain ( slice) . chain ( suffix) {
503- self . visit_bindings ( subpattern, f) ;
517+ self . visit_bindings ( subpattern, None , f) ;
504518 }
505519 }
506520 PatternKind :: Constant { .. } | PatternKind :: Range { .. } | PatternKind :: Wild => { }
507- PatternKind :: AscribeUserType { ref subpattern, .. }
508- | PatternKind :: Deref { ref subpattern } => {
509- self . visit_bindings ( subpattern, f) ;
521+ PatternKind :: Deref { ref subpattern } => {
522+ // FIXME(#47184): extract or handle `pattern_user_ty` somehow
523+ self . visit_bindings ( subpattern, None , f) ;
524+ }
525+ PatternKind :: AscribeUserType { ref subpattern, user_ty } => {
526+ // This corresponds to something like
527+ //
528+ // ```
529+ // let (p1: T1): T2 = ...;
530+ // ```
531+ //
532+ // Not presently possible, though maybe someday.
533+ assert ! ( pattern_user_ty. is_none( ) ) ;
534+ self . visit_bindings ( subpattern, Some ( user_ty) , f)
510535 }
511536 PatternKind :: Leaf { ref subpatterns }
512537 | PatternKind :: Variant {
513538 ref subpatterns, ..
514539 } => {
540+ // FIXME(#47184): extract or handle `pattern_user_ty` somehow
515541 for subpattern in subpatterns {
516- self . visit_bindings ( & subpattern. pattern , f) ;
542+ self . visit_bindings ( & subpattern. pattern , None , f) ;
517543 }
518544 }
519545 }
@@ -1375,6 +1401,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
13751401 num_patterns : usize ,
13761402 var_id : NodeId ,
13771403 var_ty : Ty < ' tcx > ,
1404+ user_var_ty : Option < CanonicalTy < ' tcx > > ,
13781405 has_guard : ArmHasGuard ,
13791406 opt_match_place : Option < ( Option < Place < ' tcx > > , Span ) > ,
13801407 pat_span : Span ,
@@ -1392,7 +1419,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
13921419 } ;
13931420 let local = LocalDecl :: < ' tcx > {
13941421 mutability,
1395- ty : var_ty. clone ( ) ,
1422+ ty : var_ty,
1423+ user_ty : user_var_ty,
13961424 name : Some ( name) ,
13971425 source_info,
13981426 visibility_scope,
@@ -1424,6 +1452,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
14241452 // See previous comment.
14251453 mutability : Mutability :: Not ,
14261454 ty : tcx. mk_imm_ref ( tcx. types . re_empty , var_ty) ,
1455+ user_ty : None ,
14271456 name : Some ( name) ,
14281457 source_info,
14291458 visibility_scope,
0 commit comments