@@ -608,8 +608,6 @@ pub trait PrettyPrinter<'tcx>:
608608 }
609609 ty:: Str => p ! ( write( "str" ) ) ,
610610 ty:: Generator ( did, substs, movability) => {
611- let upvar_tys = substs. as_generator ( ) . upvar_tys ( did, self . tcx ( ) ) ;
612- let witness = substs. as_generator ( ) . witness ( did, self . tcx ( ) ) ;
613611 match movability {
614612 hir:: Movability :: Movable => p ! ( write( "[generator" ) ) ,
615613 hir:: Movability :: Static => p ! ( write( "[static generator" ) ) ,
@@ -618,31 +616,47 @@ pub trait PrettyPrinter<'tcx>:
618616 // FIXME(eddyb) should use `def_span`.
619617 if let Some ( hir_id) = self . tcx ( ) . hir ( ) . as_local_hir_id ( did) {
620618 p ! ( write( "@{:?}" , self . tcx( ) . hir( ) . span( hir_id) ) ) ;
621- let mut sep = " " ;
622- for ( & var_id, upvar_ty) in
623- self . tcx ( ) . upvars ( did) . as_ref ( ) . iter ( ) . flat_map ( |v| v. keys ( ) ) . zip ( upvar_tys)
624- {
625- p ! ( write( "{}{}:" , sep, self . tcx( ) . hir( ) . name( var_id) ) , print( upvar_ty) ) ;
626- sep = ", " ;
619+
620+ if substs. as_generator ( ) . is_valid ( ) {
621+ let upvar_tys = substs. as_generator ( ) . upvar_tys ( ) ;
622+ let mut sep = " " ;
623+ for ( & var_id, upvar_ty) in self
624+ . tcx ( )
625+ . upvars ( did)
626+ . as_ref ( )
627+ . iter ( )
628+ . flat_map ( |v| v. keys ( ) )
629+ . zip ( upvar_tys)
630+ {
631+ p ! ( write( "{}{}:" , sep, self . tcx( ) . hir( ) . name( var_id) ) , print( upvar_ty) ) ;
632+ sep = ", " ;
633+ }
627634 }
628635 } else {
629636 // Cross-crate closure types should only be
630637 // visible in codegen bug reports, I imagine.
631638 p ! ( write( "@{:?}" , did) ) ;
632- let mut sep = " " ;
633- for ( index, upvar_ty) in upvar_tys. enumerate ( ) {
634- p ! ( write( "{}{}:" , sep, index) , print( upvar_ty) ) ;
635- sep = ", " ;
639+
640+ if substs. as_generator ( ) . is_valid ( ) {
641+ let upvar_tys = substs. as_generator ( ) . upvar_tys ( ) ;
642+ let mut sep = " " ;
643+ for ( index, upvar_ty) in upvar_tys. enumerate ( ) {
644+ p ! ( write( "{}{}:" , sep, index) , print( upvar_ty) ) ;
645+ sep = ", " ;
646+ }
636647 }
637648 }
638649
639- p ! ( write( " " ) , print( witness) , write( "]" ) )
650+ if substs. as_generator ( ) . is_valid ( ) {
651+ p ! ( write( " " ) , print( substs. as_generator( ) . witness( ) ) ) ;
652+ }
653+
654+ p ! ( write( "]" ) )
640655 }
641656 ty:: GeneratorWitness ( types) => {
642657 p ! ( in_binder( & types) ) ;
643658 }
644659 ty:: Closure ( did, substs) => {
645- let upvar_tys = substs. as_closure ( ) . upvar_tys ( did, self . tcx ( ) ) ;
646660 p ! ( write( "[closure" ) ) ;
647661
648662 // FIXME(eddyb) should use `def_span`.
@@ -652,30 +666,40 @@ pub trait PrettyPrinter<'tcx>:
652666 } else {
653667 p ! ( write( "@{:?}" , self . tcx( ) . hir( ) . span( hir_id) ) ) ;
654668 }
655- let mut sep = " " ;
656- for ( & var_id, upvar_ty) in
657- self . tcx ( ) . upvars ( did) . as_ref ( ) . iter ( ) . flat_map ( |v| v. keys ( ) ) . zip ( upvar_tys)
658- {
659- p ! ( write( "{}{}:" , sep, self . tcx( ) . hir( ) . name( var_id) ) , print( upvar_ty) ) ;
660- sep = ", " ;
669+
670+ if substs. as_closure ( ) . is_valid ( ) {
671+ let upvar_tys = substs. as_closure ( ) . upvar_tys ( ) ;
672+ let mut sep = " " ;
673+ for ( & var_id, upvar_ty) in self
674+ . tcx ( )
675+ . upvars ( did)
676+ . as_ref ( )
677+ . iter ( )
678+ . flat_map ( |v| v. keys ( ) )
679+ . zip ( upvar_tys)
680+ {
681+ p ! ( write( "{}{}:" , sep, self . tcx( ) . hir( ) . name( var_id) ) , print( upvar_ty) ) ;
682+ sep = ", " ;
683+ }
661684 }
662685 } else {
663686 // Cross-crate closure types should only be
664687 // visible in codegen bug reports, I imagine.
665688 p ! ( write( "@{:?}" , did) ) ;
666- let mut sep = " " ;
667- for ( index, upvar_ty) in upvar_tys. enumerate ( ) {
668- p ! ( write( "{}{}:" , sep, index) , print( upvar_ty) ) ;
669- sep = ", " ;
689+
690+ if substs. as_closure ( ) . is_valid ( ) {
691+ let upvar_tys = substs. as_closure ( ) . upvar_tys ( ) ;
692+ let mut sep = " " ;
693+ for ( index, upvar_ty) in upvar_tys. enumerate ( ) {
694+ p ! ( write( "{}{}:" , sep, index) , print( upvar_ty) ) ;
695+ sep = ", " ;
696+ }
670697 }
671698 }
672699
673- if self . tcx ( ) . sess . verbose ( ) {
674- p ! ( write(
675- " closure_kind_ty={:?} closure_sig_ty={:?}" ,
676- substs. as_closure( ) . kind_ty( did, self . tcx( ) ) ,
677- substs. as_closure( ) . sig_ty( did, self . tcx( ) )
678- ) ) ;
700+ if self . tcx ( ) . sess . verbose ( ) && substs. as_closure ( ) . is_valid ( ) {
701+ p ! ( write( " closure_kind_ty=" ) , print( substs. as_closure( ) . kind_ty( ) ) ) ;
702+ p ! ( write( " closure_sig_ty=" ) , print( substs. as_closure( ) . sig_ty( ) ) ) ;
679703 }
680704
681705 p ! ( write( "]" ) )
0 commit comments