@@ -457,38 +457,41 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
457
457
fn visit_local_decl ( & mut self , local : Local , local_decl : & LocalDecl < ' tcx > ) {
458
458
self . super_local_decl ( local, local_decl) ;
459
459
460
- if let Some ( user_ty) = & local_decl. user_ty {
461
- for ( user_ty, span) in user_ty. projections_and_spans ( ) {
462
- let ty = if !local_decl. is_nonref_binding ( ) {
463
- // If we have a binding of the form `let ref x: T = ..`
464
- // then remove the outermost reference so we can check the
465
- // type annotation for the remaining type.
466
- if let ty:: Ref ( _, rty, _) = local_decl. ty . kind ( ) {
467
- * rty
468
- } else {
469
- bug ! ( "{:?} with ref binding has wrong type {}" , local, local_decl. ty) ;
470
- }
460
+ for ( user_ty, span) in local_decl
461
+ . user_ty
462
+ . as_deref ( )
463
+ . into_iter ( )
464
+ . flat_map ( UserTypeProjections :: projections_and_spans)
465
+ {
466
+ let ty = if !local_decl. is_nonref_binding ( ) {
467
+ // If we have a binding of the form `let ref x: T = ..`
468
+ // then remove the outermost reference so we can check the
469
+ // type annotation for the remaining type.
470
+ if let ty:: Ref ( _, rty, _) = local_decl. ty . kind ( ) {
471
+ * rty
471
472
} else {
472
- local_decl. ty
473
- } ;
474
-
475
- if let Err ( terr) = self . typeck . relate_type_and_user_type (
476
- ty,
477
- ty:: Invariant ,
478
- user_ty,
479
- Locations :: All ( * span) ,
480
- ConstraintCategory :: TypeAnnotation ( AnnotationSource :: Declaration ) ,
481
- ) {
482
- span_mirbug ! (
483
- self ,
484
- local,
485
- "bad user type on variable {:?}: {:?} != {:?} ({:?})" ,
486
- local,
487
- local_decl. ty,
488
- local_decl. user_ty,
489
- terr,
490
- ) ;
473
+ bug ! ( "{:?} with ref binding has wrong type {}" , local, local_decl. ty) ;
491
474
}
475
+ } else {
476
+ local_decl. ty
477
+ } ;
478
+
479
+ if let Err ( terr) = self . typeck . relate_type_and_user_type (
480
+ ty,
481
+ ty:: Invariant ,
482
+ user_ty,
483
+ Locations :: All ( * span) ,
484
+ ConstraintCategory :: TypeAnnotation ( AnnotationSource :: Declaration ) ,
485
+ ) {
486
+ span_mirbug ! (
487
+ self ,
488
+ local,
489
+ "bad user type on variable {:?}: {:?} != {:?} ({:?})" ,
490
+ local,
491
+ local_decl. ty,
492
+ local_decl. user_ty,
493
+ terr,
494
+ ) ;
492
495
}
493
496
}
494
497
}
0 commit comments