@@ -993,10 +993,8 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
993993
994994 match bound_predicate. skip_binder ( ) {
995995 ty:: ClauseKind :: Trait ( pred) => {
996- let trait_ref = bound_predicate. rebind ( pred. trait_ref ) ;
997-
998996 // Don't print `+ Sized`, but rather `+ ?Sized` if absent.
999- if tcx. is_lang_item ( trait_ref . def_id ( ) , LangItem :: Sized ) {
997+ if tcx. is_lang_item ( pred . def_id ( ) , LangItem :: Sized ) {
1000998 match pred. polarity {
1001999 ty:: PredicatePolarity :: Positive => {
10021000 has_sized_bound = true ;
@@ -1040,12 +1038,15 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10401038 // Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
10411039 let paren_needed = fn_traits. len ( ) > 1 || traits. len ( ) > 0 || !has_sized_bound;
10421040
1043- for ( bound_args, entry) in fn_traits {
1041+ for ( ( bound_args, is_async ) , entry) in fn_traits {
10441042 write ! ( self , "{}" , if first { "" } else { " + " } ) ?;
10451043 write ! ( self , "{}" , if paren_needed { "(" } else { "" } ) ?;
10461044
1047- let trait_def_id =
1048- tcx. fn_trait_kind_to_def_id ( entry. kind ) . expect ( "expected Fn lang items" ) ;
1045+ let trait_def_id = if is_async {
1046+ tcx. async_fn_trait_kind_to_def_id ( entry. kind ) . expect ( "expected AsyncFn lang items" )
1047+ } else {
1048+ tcx. fn_trait_kind_to_def_id ( entry. kind ) . expect ( "expected Fn lang items" )
1049+ } ;
10491050
10501051 if let Some ( return_ty) = entry. return_ty {
10511052 self . wrap_binder ( & bound_args, |args, cx| {
@@ -1209,17 +1210,28 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12091210 ty:: PolyTraitPredicate < ' tcx > ,
12101211 FxIndexMap < DefId , ty:: Binder < ' tcx , Term < ' tcx > > > ,
12111212 > ,
1212- fn_traits : & mut FxIndexMap < ty:: Binder < ' tcx , & ' tcx ty:: List < Ty < ' tcx > > > , OpaqueFnEntry < ' tcx > > ,
1213+ fn_traits : & mut FxIndexMap <
1214+ ( ty:: Binder < ' tcx , & ' tcx ty:: List < Ty < ' tcx > > > , bool ) ,
1215+ OpaqueFnEntry < ' tcx > ,
1216+ > ,
12131217 ) {
12141218 let tcx = self . tcx ( ) ;
12151219 let trait_def_id = trait_pred. def_id ( ) ;
12161220
1221+ let fn_trait_and_async = if let Some ( kind) = tcx. fn_trait_kind_from_def_id ( trait_def_id) {
1222+ Some ( ( kind, false ) )
1223+ } else if let Some ( kind) = tcx. async_fn_trait_kind_from_def_id ( trait_def_id) {
1224+ Some ( ( kind, true ) )
1225+ } else {
1226+ None
1227+ } ;
1228+
12171229 if trait_pred. polarity ( ) == ty:: PredicatePolarity :: Positive
1218- && let Some ( kind) = tcx . fn_trait_kind_from_def_id ( trait_def_id )
1230+ && let Some ( ( kind, is_async ) ) = fn_trait_and_async
12191231 && let ty:: Tuple ( types) = * trait_pred. skip_binder ( ) . trait_ref . args . type_at ( 1 ) . kind ( )
12201232 {
12211233 let entry = fn_traits
1222- . entry ( trait_pred. rebind ( types) )
1234+ . entry ( ( trait_pred. rebind ( types) , is_async ) )
12231235 . or_insert_with ( || OpaqueFnEntry { kind, return_ty : None } ) ;
12241236 if kind. extends ( entry. kind ) {
12251237 entry. kind = kind;
@@ -3148,10 +3160,10 @@ define_print_and_forward_display! {
31483160
31493161 TraitRefPrintSugared <' tcx> {
31503162 if !with_reduced_queries( )
3151- && let Some ( kind ) = cx. tcx( ) . fn_trait_kind_from_def_id ( self . 0 . def_id)
3163+ && cx. tcx( ) . trait_def ( self . 0 . def_id) . paren_sugar
31523164 && let ty:: Tuple ( args) = self . 0 . args. type_at( 1 ) . kind( )
31533165 {
3154- p!( write( "{}" , kind . as_str ( ) ) , "(" ) ;
3166+ p!( write( "{}" , cx . tcx ( ) . item_name ( self . 0 . def_id ) ) , "(" ) ;
31553167 for ( i, arg) in args. iter( ) . enumerate( ) {
31563168 if i > 0 {
31573169 p!( ", " ) ;
0 commit comments