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