@@ -1040,12 +1040,15 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10401040 // Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
10411041 let paren_needed = fn_traits. len ( ) > 1 || traits. len ( ) > 0 || !has_sized_bound;
10421042
1043- for ( bound_args, entry) in fn_traits {
1043+ for ( ( bound_args, is_async ) , entry) in fn_traits {
10441044 write ! ( self , "{}" , if first { "" } else { " + " } ) ?;
10451045 write ! ( self , "{}" , if paren_needed { "(" } else { "" } ) ?;
10461046
1047- let trait_def_id =
1048- tcx. fn_trait_kind_to_def_id ( entry. kind ) . expect ( "expected Fn lang items" ) ;
1047+ let trait_def_id = if is_async {
1048+ tcx. async_fn_trait_kind_to_def_id ( entry. kind ) . expect ( "expected AsyncFn lang items" )
1049+ } else {
1050+ tcx. fn_trait_kind_to_def_id ( entry. kind ) . expect ( "expected Fn lang items" )
1051+ } ;
10491052
10501053 if let Some ( return_ty) = entry. return_ty {
10511054 self . wrap_binder ( & bound_args, |args, cx| {
@@ -1209,17 +1212,28 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12091212 ty:: PolyTraitPredicate < ' tcx > ,
12101213 FxIndexMap < DefId , ty:: Binder < ' tcx , Term < ' tcx > > > ,
12111214 > ,
1212- fn_traits : & mut FxIndexMap < ty:: Binder < ' tcx , & ' tcx ty:: List < Ty < ' tcx > > > , OpaqueFnEntry < ' tcx > > ,
1215+ fn_traits : & mut FxIndexMap <
1216+ ( ty:: Binder < ' tcx , & ' tcx ty:: List < Ty < ' tcx > > > , bool ) ,
1217+ OpaqueFnEntry < ' tcx > ,
1218+ > ,
12131219 ) {
12141220 let tcx = self . tcx ( ) ;
12151221 let trait_def_id = trait_pred. def_id ( ) ;
12161222
1223+ let fn_trait_and_async = if let Some ( kind) = tcx. fn_trait_kind_from_def_id ( trait_def_id) {
1224+ Some ( ( kind, false ) )
1225+ } else if let Some ( kind) = tcx. async_fn_trait_kind_from_def_id ( trait_def_id) {
1226+ Some ( ( kind, true ) )
1227+ } else {
1228+ None
1229+ } ;
1230+
12171231 if trait_pred. polarity ( ) == ty:: PredicatePolarity :: Positive
1218- && let Some ( kind) = tcx . fn_trait_kind_from_def_id ( trait_def_id )
1232+ && let Some ( ( kind, is_async ) ) = fn_trait_and_async
12191233 && let ty:: Tuple ( types) = * trait_pred. skip_binder ( ) . trait_ref . args . type_at ( 1 ) . kind ( )
12201234 {
12211235 let entry = fn_traits
1222- . entry ( trait_pred. rebind ( types) )
1236+ . entry ( ( trait_pred. rebind ( types) , is_async ) )
12231237 . or_insert_with ( || OpaqueFnEntry { kind, return_ty : None } ) ;
12241238 if kind. extends ( entry. kind ) {
12251239 entry. kind = kind;
@@ -3148,10 +3162,10 @@ define_print_and_forward_display! {
31483162
31493163 TraitRefPrintSugared <' tcx> {
31503164 if !with_reduced_queries( )
3151- && let Some ( kind ) = cx. tcx( ) . fn_trait_kind_from_def_id ( self . 0 . def_id)
3165+ && cx. tcx( ) . trait_def ( self . 0 . def_id) . paren_sugar
31523166 && let ty:: Tuple ( args) = self . 0 . args. type_at( 1 ) . kind( )
31533167 {
3154- p!( write( "{}" , kind . as_str ( ) ) , "(" ) ;
3168+ p!( write( "{}" , cx . tcx ( ) . item_name ( self . 0 . def_id ) ) , "(" ) ;
31553169 for ( i, arg) in args. iter( ) . enumerate( ) {
31563170 if i > 0 {
31573171 p!( ", " ) ;
0 commit comments