@@ -863,7 +863,7 @@ impl<'a> LoweringContext<'a> {
863
863
864
864
let capture_clause = self . lower_capture_clause ( capture_clause) ;
865
865
let closure_hir_id = self . lower_node_id ( closure_node_id) . hir_id ;
866
- let decl = self . lower_fn_decl ( & decl, None , /* impl trait allowed */ false , false ) ;
866
+ let decl = self . lower_fn_decl ( & decl, None , /* impl trait allowed */ false , None ) ;
867
867
let generator = hir:: Expr {
868
868
id : closure_node_id,
869
869
hir_id : closure_hir_id,
@@ -1106,7 +1106,7 @@ impl<'a> LoweringContext<'a> {
1106
1106
) ,
1107
1107
unsafety : this. lower_unsafety ( f. unsafety ) ,
1108
1108
abi : f. abi ,
1109
- decl : this. lower_fn_decl ( & f. decl , None , false , false ) ,
1109
+ decl : this. lower_fn_decl ( & f. decl , None , false , None ) ,
1110
1110
arg_names : this. lower_fn_args_to_names ( & f. decl ) ,
1111
1111
} ) )
1112
1112
} ,
@@ -1176,7 +1176,7 @@ impl<'a> LoweringContext<'a> {
1176
1176
|this| this. lower_param_bounds ( bounds, itctx) ,
1177
1177
)
1178
1178
}
1179
- ImplTraitContext :: Universal ( def_id ) => {
1179
+ ImplTraitContext :: Universal ( _def_id ) => {
1180
1180
self . lower_node_id ( def_node_id) ;
1181
1181
// Add a definition for the in-band TyParam
1182
1182
let def_index = self
@@ -1866,18 +1866,18 @@ impl<'a> LoweringContext<'a> {
1866
1866
// decl: the unlowered (ast) function declaration.
1867
1867
// fn_def_id: if `Some`, impl Trait arguments are lowered into generic parameters on the
1868
1868
// given DefId, otherwise impl Trait is disallowed. Must be `Some` if
1869
- // make_ret_async is true .
1869
+ // make_ret_async is also `Some` .
1870
1870
// impl_trait_return_allow: determines whether impl Trait can be used in return position.
1871
1871
// This guards against trait declarations and implementations where impl Trait is
1872
1872
// disallowed.
1873
- // make_ret_async: if enabled , converts `-> T` into `-> impl Future<Output = T>` in the
1873
+ // make_ret_async: if `Some` , converts `-> T` into `-> impl Future<Output = T>` in the
1874
1874
// return type. This is used for `async fn` declarations.
1875
1875
fn lower_fn_decl (
1876
1876
& mut self ,
1877
1877
decl : & FnDecl ,
1878
1878
fn_def_id : Option < DefId > ,
1879
1879
impl_trait_return_allow : bool ,
1880
- make_ret_async : bool ,
1880
+ make_ret_async : Option < NodeId > ,
1881
1881
) -> P < hir:: FnDecl > {
1882
1882
let inputs = decl. inputs
1883
1883
. iter ( )
@@ -1890,9 +1890,9 @@ impl<'a> LoweringContext<'a> {
1890
1890
} )
1891
1891
. collect :: < HirVec < _ > > ( ) ;
1892
1892
1893
- let output = if make_ret_async {
1893
+ let output = if let Some ( ret_id ) = make_ret_async {
1894
1894
self . lower_async_fn_ret_ty (
1895
- & inputs, & decl. output , fn_def_id. expect ( "make_ret_async but no fn_def_id" ) )
1895
+ & inputs, & decl. output , fn_def_id. expect ( "make_ret_async but no fn_def_id" ) , ret_id )
1896
1896
} else {
1897
1897
match decl. output {
1898
1898
FunctionRetTy :: Ty ( ref ty) => match fn_def_id {
@@ -1928,6 +1928,7 @@ impl<'a> LoweringContext<'a> {
1928
1928
inputs : & [ P < hir:: Ty > ] ,
1929
1929
output : & FunctionRetTy ,
1930
1930
fn_def_id : DefId ,
1931
+ return_impl_trait_id : NodeId ,
1931
1932
) -> hir:: FunctionRetTy {
1932
1933
// Get lifetimes used in the input arguments to the function. Our output type must also
1933
1934
// have the same lifetime. FIXME(cramertj) multiple different lifetimes are not allowed
@@ -2079,7 +2080,7 @@ impl<'a> LoweringContext<'a> {
2079
2080
} ;
2080
2081
2081
2082
let impl_trait_ty = self . lower_existential_impl_trait (
2082
- span, fn_def_id, |this| {
2083
+ span, fn_def_id, return_impl_trait_id , |this| {
2083
2084
let output_ty = match output {
2084
2085
FunctionRetTy :: Ty ( ty) =>
2085
2086
this. lower_ty ( ty, ImplTraitContext :: Existential ( fn_def_id) ) ,
@@ -2564,9 +2565,9 @@ impl<'a> LoweringContext<'a> {
2564
2565
// only cares about the input argument patterns in the function
2565
2566
// declaration (decl), not the return types.
2566
2567
let body_id = this. lower_body ( Some ( decl) , |this| {
2567
- if let IsAsync :: Async ( async_node_id ) = header. asyncness {
2568
+ if let IsAsync :: Async { closure_id , .. } = header. asyncness {
2568
2569
let async_expr = this. make_async_expr (
2569
- CaptureBy :: Value , async_node_id , None ,
2570
+ CaptureBy :: Value , closure_id , None ,
2570
2571
|this| {
2571
2572
let body = this. lower_block ( body, false ) ;
2572
2573
this. expr_block ( body, ThinVec :: new ( ) )
@@ -2578,12 +2579,17 @@ impl<'a> LoweringContext<'a> {
2578
2579
}
2579
2580
} ) ;
2580
2581
2582
+ let asyncness = match header. asyncness {
2583
+ IsAsync :: Async { return_impl_trait_id, .. } => Some ( return_impl_trait_id) ,
2584
+ IsAsync :: NotAsync => None ,
2585
+ } ;
2586
+
2581
2587
let ( generics, fn_decl) = this. add_in_band_defs (
2582
2588
generics,
2583
2589
fn_def_id,
2584
2590
AnonymousLifetimeMode :: PassThrough ,
2585
2591
|this| this. lower_fn_decl (
2586
- decl, Some ( fn_def_id) , true , header . asyncness . is_async ( ) )
2592
+ decl, Some ( fn_def_id) , true , asyncness)
2587
2593
) ;
2588
2594
2589
2595
hir:: ItemFn (
@@ -2906,7 +2912,7 @@ impl<'a> LoweringContext<'a> {
2906
2912
AnonymousLifetimeMode :: PassThrough ,
2907
2913
|this| {
2908
2914
hir:: TraitItemKind :: Method (
2909
- this. lower_method_sig ( sig, trait_item_def_id, false , false ) ,
2915
+ this. lower_method_sig ( sig, trait_item_def_id, false , None ) ,
2910
2916
hir:: TraitMethod :: Required ( names) ,
2911
2917
)
2912
2918
} ,
@@ -2924,7 +2930,7 @@ impl<'a> LoweringContext<'a> {
2924
2930
AnonymousLifetimeMode :: PassThrough ,
2925
2931
|this| {
2926
2932
hir:: TraitItemKind :: Method (
2927
- this. lower_method_sig ( sig, trait_item_def_id, false , false ) ,
2933
+ this. lower_method_sig ( sig, trait_item_def_id, false , None ) ,
2928
2934
hir:: TraitMethod :: Provided ( body_id) ,
2929
2935
)
2930
2936
} ,
@@ -2995,9 +3001,9 @@ impl<'a> LoweringContext<'a> {
2995
3001
}
2996
3002
ImplItemKind :: Method ( ref sig, ref body) => {
2997
3003
let body_id = self . lower_body ( Some ( & sig. decl ) , |this| {
2998
- if let IsAsync :: Async ( async_node_id ) = sig. header . asyncness {
3004
+ if let IsAsync :: Async { closure_id , .. } = sig. header . asyncness {
2999
3005
let async_expr = this. make_async_expr (
3000
- CaptureBy :: Value , async_node_id , None ,
3006
+ CaptureBy :: Value , closure_id , None ,
3001
3007
|this| {
3002
3008
let body = this. lower_block ( body, false ) ;
3003
3009
this. expr_block ( body, ThinVec :: new ( ) )
@@ -3010,6 +3016,11 @@ impl<'a> LoweringContext<'a> {
3010
3016
} ) ;
3011
3017
let impl_trait_return_allow = !self . is_in_trait_impl ;
3012
3018
3019
+ let asyncness = match sig. header . asyncness {
3020
+ IsAsync :: Async { return_impl_trait_id, .. } => Some ( return_impl_trait_id) ,
3021
+ IsAsync :: NotAsync => None ,
3022
+ } ;
3023
+
3013
3024
self . add_in_band_defs (
3014
3025
& i. generics ,
3015
3026
impl_item_def_id,
@@ -3020,7 +3031,7 @@ impl<'a> LoweringContext<'a> {
3020
3031
sig,
3021
3032
impl_item_def_id,
3022
3033
impl_trait_return_allow,
3023
- sig . header . asyncness . is_async ( ) ,
3034
+ asyncness,
3024
3035
) ,
3025
3036
body_id,
3026
3037
)
@@ -3100,8 +3111,8 @@ impl<'a> LoweringContext<'a> {
3100
3111
path_span : Span ,
3101
3112
path_segment : & ' v PathSegment ,
3102
3113
) {
3103
- if let Some ( ref p) = path_segment. parameters {
3104
- if let PathParameters :: Parenthesized ( .. ) = * * p {
3114
+ if let Some ( ref p) = path_segment. args {
3115
+ if let GenericArgs :: Parenthesized ( _ ) = * * p {
3105
3116
return ;
3106
3117
}
3107
3118
}
@@ -3123,15 +3134,21 @@ impl<'a> LoweringContext<'a> {
3123
3134
vec
3124
3135
}
3125
3136
ItemKind :: MacroDef ( ..) => SmallVector :: new ( ) ,
3126
- ItemKind :: Fn ( ref decl, ..) => {
3137
+ ItemKind :: Fn ( ref decl, ref header , ..) => {
3127
3138
let mut ids = SmallVector :: one ( hir:: ItemId { id : i. id } ) ;
3139
+ if let IsAsync :: Async { return_impl_trait_id, .. } = header. asyncness {
3140
+ ids. push ( hir:: ItemId { id : return_impl_trait_id } ) ;
3141
+ }
3128
3142
self . lower_impl_trait_ids ( decl, & mut ids) ;
3129
3143
ids
3130
3144
} ,
3131
3145
ItemKind :: Impl ( .., ref items) => {
3132
3146
let mut ids = SmallVector :: one ( hir:: ItemId { id : i. id } ) ;
3133
3147
for item in items {
3134
3148
if let ImplItemKind :: Method ( ref sig, _) = item. node {
3149
+ if let IsAsync :: Async { return_impl_trait_id, .. } = sig. header . asyncness {
3150
+ ids. push ( hir:: ItemId { id : return_impl_trait_id } ) ;
3151
+ }
3135
3152
self . lower_impl_trait_ids ( & sig. decl , & mut ids) ;
3136
3153
}
3137
3154
}
@@ -3214,7 +3231,7 @@ impl<'a> LoweringContext<'a> {
3214
3231
|this| {
3215
3232
(
3216
3233
// Disallow impl Trait in foreign items
3217
- this. lower_fn_decl ( fdec, None , false , false ) ,
3234
+ this. lower_fn_decl ( fdec, None , false , None ) ,
3218
3235
this. lower_fn_args_to_names ( fdec) ,
3219
3236
)
3220
3237
} ,
@@ -3238,7 +3255,7 @@ impl<'a> LoweringContext<'a> {
3238
3255
sig : & MethodSig ,
3239
3256
fn_def_id : DefId ,
3240
3257
impl_trait_return_allow : bool ,
3241
- is_async : bool ,
3258
+ is_async : Option < NodeId > ,
3242
3259
) -> hir:: MethodSig {
3243
3260
hir:: MethodSig {
3244
3261
header : self . lower_fn_header ( sig. header ) ,
@@ -3278,7 +3295,7 @@ impl<'a> LoweringContext<'a> {
3278
3295
3279
3296
fn lower_asyncness ( & mut self , a : IsAsync ) -> hir:: IsAsync {
3280
3297
match a {
3281
- IsAsync :: Async ( _ ) => hir:: IsAsync :: Async ,
3298
+ IsAsync :: Async { .. } => hir:: IsAsync :: Async ,
3282
3299
IsAsync :: NotAsync => hir:: IsAsync :: NotAsync ,
3283
3300
}
3284
3301
}
@@ -3581,7 +3598,7 @@ impl<'a> LoweringContext<'a> {
3581
3598
ExprKind :: Closure (
3582
3599
capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span
3583
3600
) => {
3584
- if let IsAsync :: Async ( async_closure_node_id) = asyncness {
3601
+ if let IsAsync :: Async { async_closure_node_id, .. } = asyncness {
3585
3602
let outer_decl = FnDecl {
3586
3603
inputs : decl. inputs . clone ( ) ,
3587
3604
output : FunctionRetTy :: Default ( fn_decl_span) ,
@@ -3590,7 +3607,7 @@ impl<'a> LoweringContext<'a> {
3590
3607
// We need to lower the declaration outside the new scope, because we
3591
3608
// have to conserve the state of being inside a loop condition for the
3592
3609
// closure argument types.
3593
- let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , false ) ;
3610
+ let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , None ) ;
3594
3611
3595
3612
self . with_new_scopes ( |this| {
3596
3613
// FIXME(cramertj) allow `async` non-`move` closures with
@@ -3617,7 +3634,7 @@ impl<'a> LoweringContext<'a> {
3617
3634
Some ( & * * ty)
3618
3635
} else { None } ;
3619
3636
let async_body = this. make_async_expr (
3620
- capture_clause, async_closure_node_id , async_ret_ty,
3637
+ capture_clause, closure_id , async_ret_ty,
3621
3638
|this| {
3622
3639
this. with_new_scopes ( |this| this. lower_expr ( body) )
3623
3640
} ) ;
@@ -3633,7 +3650,7 @@ impl<'a> LoweringContext<'a> {
3633
3650
} )
3634
3651
} else {
3635
3652
// Lower outside new scope to preserve `is_in_loop_condition`.
3636
- let fn_decl = self . lower_fn_decl ( decl, None , false , false ) ;
3653
+ let fn_decl = self . lower_fn_decl ( decl, None , false , None ) ;
3637
3654
3638
3655
self . with_new_scopes ( |this| {
3639
3656
let mut is_generator = false ;
0 commit comments