@@ -399,7 +399,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
399
399
let num_patterns = patterns. len ( ) ;
400
400
self . visit_bindings (
401
401
& patterns[ 0 ] ,
402
- & mut |this, mutability, name, mode, var, span, ty| {
402
+ None ,
403
+ & mut |this, mutability, name, mode, var, span, ty, user_ty| {
403
404
if visibility_scope. is_none ( ) {
404
405
visibility_scope =
405
406
Some ( this. new_source_scope ( scope_span, LintLevel :: Inherited , None ) ) ;
@@ -421,6 +422,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
421
422
num_patterns,
422
423
var,
423
424
ty,
425
+ user_ty,
424
426
has_guard,
425
427
opt_match_place. map ( |( x, y) | ( x. cloned ( ) , y) ) ,
426
428
patterns[ 0 ] . span ,
@@ -470,10 +472,21 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
470
472
) ;
471
473
}
472
474
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
+ ) {
477
490
match * pattern. kind {
478
491
PatternKind :: Binding {
479
492
mutability,
@@ -484,9 +497,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
484
497
ref subpattern,
485
498
..
486
499
} => {
487
- f ( self , mutability, name, mode, var, pattern. span , ty) ;
500
+ f ( self , mutability, name, mode, var, pattern. span , ty, pattern_user_ty ) ;
488
501
if let Some ( subpattern) = subpattern. as_ref ( ) {
489
- self . visit_bindings ( subpattern, f) ;
502
+ self . visit_bindings ( subpattern, pattern_user_ty , f) ;
490
503
}
491
504
}
492
505
PatternKind :: Array {
@@ -499,21 +512,34 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
499
512
ref slice,
500
513
ref suffix,
501
514
} => {
515
+ // FIXME(#47184): extract or handle `pattern_user_ty` somehow
502
516
for subpattern in prefix. iter ( ) . chain ( slice) . chain ( suffix) {
503
- self . visit_bindings ( subpattern, f) ;
517
+ self . visit_bindings ( subpattern, None , f) ;
504
518
}
505
519
}
506
520
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)
510
535
}
511
536
PatternKind :: Leaf { ref subpatterns }
512
537
| PatternKind :: Variant {
513
538
ref subpatterns, ..
514
539
} => {
540
+ // FIXME(#47184): extract or handle `pattern_user_ty` somehow
515
541
for subpattern in subpatterns {
516
- self . visit_bindings ( & subpattern. pattern , f) ;
542
+ self . visit_bindings ( & subpattern. pattern , None , f) ;
517
543
}
518
544
}
519
545
}
@@ -1375,6 +1401,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1375
1401
num_patterns : usize ,
1376
1402
var_id : NodeId ,
1377
1403
var_ty : Ty < ' tcx > ,
1404
+ user_var_ty : Option < CanonicalTy < ' tcx > > ,
1378
1405
has_guard : ArmHasGuard ,
1379
1406
opt_match_place : Option < ( Option < Place < ' tcx > > , Span ) > ,
1380
1407
pat_span : Span ,
@@ -1392,7 +1419,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1392
1419
} ;
1393
1420
let local = LocalDecl :: < ' tcx > {
1394
1421
mutability,
1395
- ty : var_ty. clone ( ) ,
1422
+ ty : var_ty,
1423
+ user_ty : user_var_ty,
1396
1424
name : Some ( name) ,
1397
1425
source_info,
1398
1426
visibility_scope,
@@ -1424,6 +1452,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1424
1452
// See previous comment.
1425
1453
mutability : Mutability :: Not ,
1426
1454
ty : tcx. mk_imm_ref ( tcx. types . re_empty , var_ty) ,
1455
+ user_ty : None ,
1427
1456
name : Some ( name) ,
1428
1457
source_info,
1429
1458
visibility_scope,
0 commit comments