@@ -1040,12 +1040,15 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
1040
1040
// Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
1041
1041
let paren_needed = fn_traits. len ( ) > 1 || traits. len ( ) > 0 || !has_sized_bound;
1042
1042
1043
- for ( bound_args, entry) in fn_traits {
1043
+ for ( ( bound_args, is_async ) , entry) in fn_traits {
1044
1044
write ! ( self , "{}" , if first { "" } else { " + " } ) ?;
1045
1045
write ! ( self , "{}" , if paren_needed { "(" } else { "" } ) ?;
1046
1046
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
+ } ;
1049
1052
1050
1053
if let Some ( return_ty) = entry. return_ty {
1051
1054
self . wrap_binder ( & bound_args, |args, cx| {
@@ -1209,17 +1212,28 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
1209
1212
ty:: PolyTraitPredicate < ' tcx > ,
1210
1213
FxIndexMap < DefId , ty:: Binder < ' tcx , Term < ' tcx > > > ,
1211
1214
> ,
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
+ > ,
1213
1219
) {
1214
1220
let tcx = self . tcx ( ) ;
1215
1221
let trait_def_id = trait_pred. def_id ( ) ;
1216
1222
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
+
1217
1231
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
1219
1233
&& let ty:: Tuple ( types) = * trait_pred. skip_binder ( ) . trait_ref . args . type_at ( 1 ) . kind ( )
1220
1234
{
1221
1235
let entry = fn_traits
1222
- . entry ( trait_pred. rebind ( types) )
1236
+ . entry ( ( trait_pred. rebind ( types) , is_async ) )
1223
1237
. or_insert_with ( || OpaqueFnEntry { kind, return_ty : None } ) ;
1224
1238
if kind. extends ( entry. kind ) {
1225
1239
entry. kind = kind;
@@ -3148,10 +3162,10 @@ define_print_and_forward_display! {
3148
3162
3149
3163
TraitRefPrintSugared <' tcx> {
3150
3164
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
3152
3166
&& let ty:: Tuple ( args) = self . 0 . args. type_at( 1 ) . kind( )
3153
3167
{
3154
- p!( write( "{}" , kind . as_str ( ) ) , "(" ) ;
3168
+ p!( write( "{}" , cx . tcx ( ) . item_name ( self . 0 . def_id ) ) , "(" ) ;
3155
3169
for ( i, arg) in args. iter( ) . enumerate( ) {
3156
3170
if i > 0 {
3157
3171
p!( ", " ) ;
0 commit comments