@@ -18,6 +18,7 @@ use build::ForGuard::{self, OutsideGuard, RefWithinGuard, ValWithinGuard};
1818use build:: { BlockAnd , BlockAndExtension , Builder } ;
1919use build:: { GuardFrame , GuardFrameLocal , LocalsForNode } ;
2020use hair:: * ;
21+ use hair:: pattern:: PatternTypeProjections ;
2122use rustc:: hir;
2223use rustc:: mir:: * ;
2324use rustc:: ty:: { self , Ty } ;
@@ -415,7 +416,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
415416 let num_patterns = patterns. len ( ) ;
416417 self . visit_bindings (
417418 & patterns[ 0 ] ,
418- None ,
419+ & PatternTypeProjections :: none ( ) ,
419420 & mut |this, mutability, name, mode, var, span, ty, user_ty| {
420421 if visibility_scope. is_none ( ) {
421422 visibility_scope =
@@ -491,7 +492,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
491492 pub ( super ) fn visit_bindings (
492493 & mut self ,
493494 pattern : & Pattern < ' tcx > ,
494- mut pattern_user_ty : Option < ( PatternTypeProjection < ' tcx > , Span ) > ,
495+ pattern_user_ty : & PatternTypeProjections < ' tcx > ,
495496 f : & mut impl FnMut (
496497 & mut Self ,
497498 Mutability ,
@@ -500,7 +501,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
500501 NodeId ,
501502 Span ,
502503 Ty < ' tcx > ,
503- Option < ( PatternTypeProjection < ' tcx > , Span ) > ,
504+ & PatternTypeProjections < ' tcx > ,
504505 ) ,
505506 ) {
506507 match * pattern. kind {
@@ -513,20 +514,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
513514 ref subpattern,
514515 ..
515516 } => {
516- match mode {
517- BindingMode :: ByValue => { }
517+ let pattern_ref_binding; // sidestep temp lifetime limitations.
518+ let binding_user_ty = match mode {
519+ BindingMode :: ByValue => { pattern_user_ty }
518520 BindingMode :: ByRef ( ..) => {
519521 // If this is a `ref` binding (e.g., `let ref
520522 // x: T = ..`), then the type of `x` is not
521- // `T` but rather `&T`, so ignore
522- // `pattern_user_ty` for now.
523- //
524- // FIXME(#47184): extract or handle `pattern_user_ty` somehow
525- pattern_user_ty = None ;
523+ // `T` but rather `&T`.
524+ pattern_ref_binding = pattern_user_ty. ref_binding ( ) ;
525+ & pattern_ref_binding
526526 }
527- }
527+ } ;
528528
529- f ( self , mutability, name, mode, var, pattern. span , ty, pattern_user_ty ) ;
529+ f ( self , mutability, name, mode, var, pattern. span , ty, binding_user_ty ) ;
530530 if let Some ( subpattern) = subpattern. as_ref ( ) {
531531 self . visit_bindings ( subpattern, pattern_user_ty, f) ;
532532 }
@@ -541,33 +541,39 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
541541 ref slice,
542542 ref suffix,
543543 } => {
544- // FIXME(#47184): extract or handle `pattern_user_ty` somehow
545- for subpattern in prefix. iter ( ) . chain ( slice) . chain ( suffix) {
546- self . visit_bindings ( subpattern, None , f) ;
544+ for subpattern in prefix {
545+ self . visit_bindings ( subpattern, & pattern_user_ty. index ( ) , f) ;
546+ }
547+ for subpattern in slice {
548+ self . visit_bindings ( subpattern, & pattern_user_ty. subslice ( ) , f) ;
549+ }
550+ for subpattern in suffix {
551+ self . visit_bindings ( subpattern, & pattern_user_ty. index ( ) , f) ;
547552 }
548553 }
549554 PatternKind :: Constant { .. } | PatternKind :: Range { .. } | PatternKind :: Wild => { }
550555 PatternKind :: Deref { ref subpattern } => {
551- // FIXME(#47184): extract or handle `pattern_user_ty` somehow
552- self . visit_bindings ( subpattern, None , f) ;
556+ self . visit_bindings ( subpattern, & pattern_user_ty. deref ( ) , f) ;
553557 }
554558 PatternKind :: AscribeUserType { ref subpattern, user_ty, user_ty_span } => {
555559 // This corresponds to something like
556560 //
557561 // ```
558562 // let A::<'a>(_): A<'static> = ...;
559563 // ```
560- //
561- // FIXME(#47184): handle `pattern_user_ty` somehow
562- self . visit_bindings ( subpattern, Some ( ( user_ty, user_ty_span) ) , f)
564+ let pattern_user_ty = pattern_user_ty. add_user_type ( user_ty, user_ty_span) ;
565+ self . visit_bindings ( subpattern, & pattern_user_ty, f)
563566 }
564- PatternKind :: Leaf { ref subpatterns }
565- | PatternKind :: Variant {
566- ref subpatterns, ..
567- } => {
568- // FIXME(#47184): extract or handle `pattern_user_ty` somehow
569- for subpattern in subpatterns {
570- self . visit_bindings ( & subpattern. pattern , None , f) ;
567+
568+ PatternKind :: Leaf { ref subpatterns } => {
569+ for ( j, subpattern) in subpatterns. iter ( ) . enumerate ( ) {
570+ self . visit_bindings ( & subpattern. pattern , & pattern_user_ty. leaf ( j) , f) ;
571+ }
572+ }
573+
574+ PatternKind :: Variant { ref subpatterns, .. } => {
575+ for ( j, subpattern) in subpatterns. iter ( ) . enumerate ( ) {
576+ self . visit_bindings ( & subpattern. pattern , & pattern_user_ty. variant ( j) , f) ;
571577 }
572578 }
573579 }
@@ -1470,7 +1476,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
14701476 num_patterns : usize ,
14711477 var_id : NodeId ,
14721478 var_ty : Ty < ' tcx > ,
1473- user_var_ty : Option < ( PatternTypeProjection < ' tcx > , Span ) > ,
1479+ user_var_ty : & PatternTypeProjections < ' tcx > ,
14741480 has_guard : ArmHasGuard ,
14751481 opt_match_place : Option < ( Option < Place < ' tcx > > , Span ) > ,
14761482 pat_span : Span ,
@@ -1489,7 +1495,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
14891495 let local = LocalDecl :: < ' tcx > {
14901496 mutability,
14911497 ty : var_ty,
1492- user_ty : user_var_ty. map ( | ( ut , sp ) | ( ut . user_ty ( ) , sp ) ) ,
1498+ user_ty : user_var_ty. clone ( ) . user_ty ( ) ,
14931499 name : Some ( name) ,
14941500 source_info,
14951501 visibility_scope,
@@ -1522,7 +1528,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
15221528 // See previous comment.
15231529 mutability : Mutability :: Not ,
15241530 ty : tcx. mk_imm_ref ( tcx. types . re_empty , var_ty) ,
1525- user_ty : None ,
1531+ user_ty : UserTypeProjections :: none ( ) ,
15261532 name : Some ( name) ,
15271533 source_info,
15281534 visibility_scope,
0 commit comments