@@ -644,18 +644,23 @@ pub trait PrettyPrinter<'tcx>:
644
644
return Ok ( self ) ;
645
645
}
646
646
647
- let def_key = self . tcx ( ) . def_key ( def_id) ;
648
- if let Some ( name) = def_key. disambiguated_data . data . get_opt_name ( ) {
649
- p ! ( write( "{}" , name) ) ;
650
- // FIXME(eddyb) print this with `print_def_path`.
651
- if !substs. is_empty ( ) {
652
- p ! ( "::" ) ;
653
- p ! ( generic_delimiters( |cx| cx. comma_sep( substs. iter( ) ) ) ) ;
647
+ let parent = self . tcx ( ) . parent ( def_id) . expect ( "opaque types always have a parent" ) ;
648
+ match self . tcx ( ) . def_kind ( parent) {
649
+ DefKind :: TyAlias | DefKind :: AssocTy => {
650
+ if let ty:: Opaque ( d, _) = * self . tcx ( ) . type_of ( parent) . kind ( ) {
651
+ if d == def_id {
652
+ // If the type alias directly starts with the `impl` of the
653
+ // opaque type we're printing, then skip the `::{opaque#1}`.
654
+ p ! ( print_def_path( parent, substs) ) ;
655
+ return Ok ( self ) ;
656
+ }
657
+ }
658
+ // Complex opaque type, e.g. `type Foo = (i32, impl Debug);`
659
+ p ! ( print_def_path( def_id, substs) ) ;
660
+ return Ok ( self ) ;
654
661
}
655
- return Ok ( self ) ;
662
+ _ => return self . pretty_print_opaque_impl_type ( def_id , substs ) ,
656
663
}
657
-
658
- return self . pretty_print_opaque_impl_type ( def_id, substs) ;
659
664
}
660
665
ty:: Str => p ! ( "str" ) ,
661
666
ty:: Generator ( did, substs, movability) => {
@@ -898,15 +903,6 @@ pub trait PrettyPrinter<'tcx>:
898
903
if !first {
899
904
p ! ( ", " ) ;
900
905
}
901
- if let GenericArgKind :: Type ( ty) = ty. unpack ( ) {
902
- if let ty:: Opaque ( d, substs) = * ty. kind ( ) {
903
- if d == def_id {
904
- p ! ( print_def_path( d, substs) ) ;
905
- first = false ;
906
- continue ;
907
- }
908
- }
909
- }
910
906
p ! ( print( trait_ref. rebind( * ty) ) ) ;
911
907
first = false ;
912
908
}
0 commit comments