@@ -477,11 +477,11 @@ impl<'a> LoweringContext<'a> {
477
477
} ) ;
478
478
}
479
479
480
- fn visit_trait_item ( & mut self , item : & ' tcx TraitItem ) {
480
+ fn visit_trait_item ( & mut self , item : & ' tcx AssocItem ) {
481
481
self . lctx . allocate_hir_id_counter ( item. id ) ;
482
482
483
483
match item. kind {
484
- TraitItemKind :: Method ( _, None ) => {
484
+ AssocItemKind :: Fn ( _, None ) => {
485
485
// Ignore patterns in trait methods without bodies
486
486
self . with_hir_id_owner ( None , |this| {
487
487
visit:: walk_trait_item ( this, item)
@@ -493,7 +493,7 @@ impl<'a> LoweringContext<'a> {
493
493
}
494
494
}
495
495
496
- fn visit_impl_item ( & mut self , item : & ' tcx ImplItem ) {
496
+ fn visit_impl_item ( & mut self , item : & ' tcx AssocItem ) {
497
497
self . lctx . allocate_hir_id_counter ( item. id ) ;
498
498
self . with_hir_id_owner ( Some ( item. id ) , |this| {
499
499
visit:: walk_impl_item ( this, item) ;
@@ -1211,7 +1211,7 @@ impl<'a> LoweringContext<'a> {
1211
1211
let ct = self . with_new_scopes ( |this| {
1212
1212
hir:: AnonConst {
1213
1213
hir_id : this. lower_node_id ( node_id) ,
1214
- body : this. lower_const_body ( & path_expr) ,
1214
+ body : this. lower_const_body ( path_expr . span , Some ( & path_expr) ) ,
1215
1215
}
1216
1216
} ) ;
1217
1217
return GenericArg :: Const ( ConstArg {
@@ -1253,6 +1253,14 @@ impl<'a> LoweringContext<'a> {
1253
1253
ty
1254
1254
}
1255
1255
1256
+ fn ty ( & mut self , span : Span , kind : hir:: TyKind ) -> hir:: Ty {
1257
+ hir:: Ty { hir_id : self . next_id ( ) , kind, span }
1258
+ }
1259
+
1260
+ fn ty_tup ( & mut self , span : Span , tys : HirVec < hir:: Ty > ) -> hir:: Ty {
1261
+ self . ty ( span, hir:: TyKind :: Tup ( tys) )
1262
+ }
1263
+
1256
1264
fn lower_ty_direct ( & mut self , t : & Ty , mut itctx : ImplTraitContext < ' _ > ) -> hir:: Ty {
1257
1265
let kind = match t. kind {
1258
1266
TyKind :: Infer => hir:: TyKind :: Infer ,
@@ -1418,7 +1426,13 @@ impl<'a> LoweringContext<'a> {
1418
1426
}
1419
1427
}
1420
1428
TyKind :: Mac ( _) => bug ! ( "`TyKind::Mac` should have been expanded by now" ) ,
1421
- TyKind :: CVarArgs => bug ! ( "`TyKind::CVarArgs` should have been handled elsewhere" ) ,
1429
+ TyKind :: CVarArgs => {
1430
+ self . sess . delay_span_bug (
1431
+ t. span ,
1432
+ "`TyKind::CVarArgs` should have been handled elsewhere" ,
1433
+ ) ;
1434
+ hir:: TyKind :: Err
1435
+ }
1422
1436
} ;
1423
1437
1424
1438
hir:: Ty {
@@ -2084,32 +2098,19 @@ impl<'a> LoweringContext<'a> {
2084
2098
. iter ( )
2085
2099
. map ( |ty| this. lower_ty_direct ( ty, ImplTraitContext :: disallowed ( ) ) )
2086
2100
. collect ( ) ;
2087
- let mk_tup = |this : & mut Self , tys, span| {
2088
- hir:: Ty { kind : hir:: TyKind :: Tup ( tys) , hir_id : this. next_id ( ) , span }
2101
+ let output_ty = match output {
2102
+ FunctionRetTy :: Ty ( ty) => this. lower_ty ( & ty, ImplTraitContext :: disallowed ( ) ) ,
2103
+ FunctionRetTy :: Default ( _) => P ( this. ty_tup ( span, hir:: HirVec :: new ( ) ) ) ,
2104
+ } ;
2105
+ let args = hir_vec ! [ GenericArg :: Type ( this. ty_tup( span, inputs) ) ] ;
2106
+ let binding = hir:: TypeBinding {
2107
+ hir_id : this. next_id ( ) ,
2108
+ ident : Ident :: with_dummy_span ( FN_OUTPUT_NAME ) ,
2109
+ span : output_ty. span ,
2110
+ kind : hir:: TypeBindingKind :: Equality { ty : output_ty } ,
2089
2111
} ;
2090
2112
(
2091
- hir:: GenericArgs {
2092
- args : hir_vec ! [ GenericArg :: Type ( mk_tup( this, inputs, span) ) ] ,
2093
- bindings : hir_vec ! [
2094
- hir:: TypeBinding {
2095
- hir_id: this. next_id( ) ,
2096
- ident: Ident :: with_dummy_span( FN_OUTPUT_NAME ) ,
2097
- kind: hir:: TypeBindingKind :: Equality {
2098
- ty: output
2099
- . as_ref( )
2100
- . map( |ty| this. lower_ty(
2101
- & ty,
2102
- ImplTraitContext :: disallowed( )
2103
- ) )
2104
- . unwrap_or_else( ||
2105
- P ( mk_tup( this, hir:: HirVec :: new( ) , span) )
2106
- ) ,
2107
- } ,
2108
- span: output. as_ref( ) . map_or( span, |ty| ty. span) ,
2109
- }
2110
- ] ,
2111
- parenthesized : true ,
2112
- } ,
2113
+ hir:: GenericArgs { args, bindings : hir_vec ! [ binding] , parenthesized : true } ,
2113
2114
false ,
2114
2115
)
2115
2116
}
@@ -2474,17 +2475,13 @@ impl<'a> LoweringContext<'a> {
2474
2475
} )
2475
2476
) ;
2476
2477
2477
- // Create the `Foo<...>` refernece itself. Note that the `type
2478
+ // Create the `Foo<...>` reference itself. Note that the `type
2478
2479
// Foo = impl Trait` is, internally, created as a child of the
2479
2480
// async fn, so the *type parameters* are inherited. It's
2480
2481
// only the lifetime parameters that we must supply.
2481
2482
let opaque_ty_ref = hir:: TyKind :: Def ( hir:: ItemId { id : opaque_ty_id } , generic_args. into ( ) ) ;
2482
-
2483
- hir:: FunctionRetTy :: Return ( P ( hir:: Ty {
2484
- kind : opaque_ty_ref,
2485
- span : opaque_ty_span,
2486
- hir_id : self . next_id ( ) ,
2487
- } ) )
2483
+ let opaque_ty = self . ty ( opaque_ty_span, opaque_ty_ref) ;
2484
+ hir:: FunctionRetTy :: Return ( P ( opaque_ty) )
2488
2485
}
2489
2486
2490
2487
/// Transforms `-> T` into `Future<Output = T>`
@@ -2496,16 +2493,8 @@ impl<'a> LoweringContext<'a> {
2496
2493
) -> hir:: GenericBound {
2497
2494
// Compute the `T` in `Future<Output = T>` from the return type.
2498
2495
let output_ty = match output {
2499
- FunctionRetTy :: Ty ( ty) => {
2500
- self . lower_ty ( ty, ImplTraitContext :: OpaqueTy ( Some ( fn_def_id) ) )
2501
- }
2502
- FunctionRetTy :: Default ( ret_ty_span) => {
2503
- P ( hir:: Ty {
2504
- hir_id : self . next_id ( ) ,
2505
- kind : hir:: TyKind :: Tup ( hir_vec ! [ ] ) ,
2506
- span : * ret_ty_span,
2507
- } )
2508
- }
2496
+ FunctionRetTy :: Ty ( ty) => self . lower_ty ( ty, ImplTraitContext :: OpaqueTy ( Some ( fn_def_id) ) ) ,
2497
+ FunctionRetTy :: Default ( ret_ty_span) => P ( self . ty_tup ( * ret_ty_span, hir_vec ! [ ] ) ) ,
2509
2498
} ;
2510
2499
2511
2500
// "<Output = T>"
@@ -3017,7 +3006,7 @@ impl<'a> LoweringContext<'a> {
3017
3006
self . with_new_scopes ( |this| {
3018
3007
hir:: AnonConst {
3019
3008
hir_id : this. lower_node_id ( c. id ) ,
3020
- body : this. lower_const_body ( & c. value ) ,
3009
+ body : this. lower_const_body ( c . value . span , Some ( & c. value ) ) ,
3021
3010
}
3022
3011
} )
3023
3012
}
0 commit comments