@@ -309,57 +309,59 @@ impl<'hir> LoweringContext<'_, 'hir> {
309
309
//
310
310
// type Foo = Foo1
311
311
// opaque type Foo1: Trait
312
- let ty = self . lower_ty ( ty, ImplTraitContext :: TypeAliasesOpaqueTy ) ;
313
312
let mut generics = generics. clone ( ) ;
314
313
add_ty_alias_where_clause ( & mut generics, where_clauses, true ) ;
315
- let generics = self . lower_generics (
314
+ let ( generics, ty ) = self . add_implicit_generics (
316
315
& generics,
316
+ id,
317
317
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
318
+ |this| this. lower_ty ( ty, ImplTraitContext :: TypeAliasesOpaqueTy ) ,
318
319
) ;
319
320
hir:: ItemKind :: TyAlias ( ty, generics)
320
321
}
321
322
ItemKind :: TyAlias ( box TyAlias {
322
323
ref generics, ref where_clauses, ty : None , ..
323
324
} ) => {
324
- let ty = self . arena . alloc ( self . ty ( span, hir:: TyKind :: Err ) ) ;
325
325
let mut generics = generics. clone ( ) ;
326
326
add_ty_alias_where_clause ( & mut generics, * where_clauses, true ) ;
327
- let generics = self . lower_generics (
327
+ let ( generics, ty ) = self . add_implicit_generics (
328
328
& generics,
329
+ id,
329
330
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
331
+ |this| this. arena . alloc ( this. ty ( span, hir:: TyKind :: Err ) ) ,
330
332
) ;
331
333
hir:: ItemKind :: TyAlias ( ty, generics)
332
334
}
333
- ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemKind :: Enum (
334
- hir:: EnumDef {
335
- variants : self . arena . alloc_from_iter (
336
- enum_definition. variants . iter ( ) . map ( |x| self . lower_variant ( x) ) ,
337
- ) ,
338
- } ,
339
- self . lower_generics (
335
+ ItemKind :: Enum ( ref enum_definition, ref generics) => {
336
+ let ( generics, variants) = self . add_implicit_generics (
340
337
generics,
338
+ id,
341
339
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
342
- ) ,
343
- ) ,
340
+ |this| {
341
+ this. arena . alloc_from_iter (
342
+ enum_definition. variants . iter ( ) . map ( |x| this. lower_variant ( x) ) ,
343
+ )
344
+ } ,
345
+ ) ;
346
+ hir:: ItemKind :: Enum ( hir:: EnumDef { variants } , generics)
347
+ }
344
348
ItemKind :: Struct ( ref struct_def, ref generics) => {
345
- let struct_def = self . lower_variant_data ( hir_id, struct_def) ;
346
- hir:: ItemKind :: Struct (
347
- struct_def,
348
- self . lower_generics (
349
- generics,
350
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
351
- ) ,
352
- )
349
+ let ( generics, struct_def) = self . add_implicit_generics (
350
+ generics,
351
+ id,
352
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
353
+ |this| this. lower_variant_data ( hir_id, struct_def) ,
354
+ ) ;
355
+ hir:: ItemKind :: Struct ( struct_def, generics)
353
356
}
354
357
ItemKind :: Union ( ref vdata, ref generics) => {
355
- let vdata = self . lower_variant_data ( hir_id, vdata) ;
356
- hir:: ItemKind :: Union (
357
- vdata,
358
- self . lower_generics (
359
- generics,
360
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
361
- ) ,
362
- )
358
+ let ( generics, vdata) = self . add_implicit_generics (
359
+ generics,
360
+ id,
361
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
362
+ |this| this. lower_variant_data ( hir_id, vdata) ,
363
+ ) ;
364
+ hir:: ItemKind :: Union ( vdata, generics)
363
365
}
364
366
ItemKind :: Impl ( box Impl {
365
367
unsafety,
@@ -431,34 +433,38 @@ impl<'hir> LoweringContext<'_, 'hir> {
431
433
ref bounds,
432
434
ref items,
433
435
} ) => {
434
- let bounds = self . lower_param_bounds (
435
- bounds,
436
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
436
+ let ( generics, ( unsafety, items, bounds) ) = self . add_implicit_generics (
437
+ generics,
438
+ id,
439
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
440
+ |this| {
441
+ let bounds = this. lower_param_bounds (
442
+ bounds,
443
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
444
+ ) ;
445
+ let items = this. arena . alloc_from_iter (
446
+ items. iter ( ) . map ( |item| this. lower_trait_item_ref ( item) ) ,
447
+ ) ;
448
+ let unsafety = this. lower_unsafety ( unsafety) ;
449
+ ( unsafety, items, bounds)
450
+ } ,
437
451
) ;
438
- let items = self
439
- . arena
440
- . alloc_from_iter ( items. iter ( ) . map ( |item| self . lower_trait_item_ref ( item) ) ) ;
441
- hir:: ItemKind :: Trait (
442
- is_auto,
443
- self . lower_unsafety ( unsafety) ,
444
- self . lower_generics (
445
- generics,
446
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
447
- ) ,
448
- bounds,
449
- items,
450
- )
452
+ hir:: ItemKind :: Trait ( is_auto, unsafety, generics, bounds, items)
451
453
}
452
- ItemKind :: TraitAlias ( ref generics, ref bounds) => hir :: ItemKind :: TraitAlias (
453
- self . lower_generics (
454
+ ItemKind :: TraitAlias ( ref generics, ref bounds) => {
455
+ let ( generics , bounds ) = self . add_implicit_generics (
454
456
generics,
457
+ id,
455
458
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
456
- ) ,
457
- self . lower_param_bounds (
458
- bounds,
459
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
460
- ) ,
461
- ) ,
459
+ |this| {
460
+ this. lower_param_bounds (
461
+ bounds,
462
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
463
+ )
464
+ } ,
465
+ ) ;
466
+ hir:: ItemKind :: TraitAlias ( generics, bounds)
467
+ }
462
468
ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
463
469
let body = P ( self . lower_mac_args ( body) ) ;
464
470
let macro_kind = self . resolver . decl_macro_kind ( self . resolver . local_def_id ( id) ) ;
@@ -789,24 +795,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
789
795
ref ty,
790
796
..
791
797
} ) => {
792
- let ty = ty. as_ref ( ) . map ( |x| {
793
- self . lower_ty ( x, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Type ) )
794
- } ) ;
795
798
let mut generics = generics. clone ( ) ;
796
799
add_ty_alias_where_clause ( & mut generics, where_clauses, false ) ;
797
- let generics = self . lower_generics (
800
+ self . add_implicit_generics (
798
801
& generics,
802
+ i. id ,
799
803
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
800
- ) ;
801
- let kind = hir:: TraitItemKind :: Type (
802
- self . lower_param_bounds (
803
- bounds,
804
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
805
- ) ,
806
- ty,
807
- ) ;
808
-
809
- ( generics, kind)
804
+ |this| {
805
+ let ty = ty. as_ref ( ) . map ( |x| {
806
+ this. lower_ty ( x, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Type ) )
807
+ } ) ;
808
+ hir:: TraitItemKind :: Type (
809
+ this. lower_param_bounds (
810
+ bounds,
811
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
812
+ ) ,
813
+ ty,
814
+ )
815
+ } ,
816
+ )
810
817
}
811
818
AssocItemKind :: MacCall ( ..) => panic ! ( "macro item shouldn't exist at this point" ) ,
812
819
} ;
@@ -876,21 +883,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
876
883
AssocItemKind :: TyAlias ( box TyAlias { generics, where_clauses, ty, .. } ) => {
877
884
let mut generics = generics. clone ( ) ;
878
885
add_ty_alias_where_clause ( & mut generics, * where_clauses, false ) ;
879
- let generics = self . lower_generics (
886
+ self . add_implicit_generics (
880
887
& generics,
888
+ i. id ,
881
889
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
882
- ) ;
883
- let kind = match ty {
884
- None => {
885
- let ty = self . arena . alloc ( self . ty ( i. span , hir:: TyKind :: Err ) ) ;
886
- hir:: ImplItemKind :: TyAlias ( ty)
887
- }
888
- Some ( ty) => {
889
- let ty = self . lower_ty ( ty, ImplTraitContext :: TypeAliasesOpaqueTy ) ;
890
- hir:: ImplItemKind :: TyAlias ( ty)
891
- }
892
- } ;
893
- ( generics, kind)
890
+ |this| match ty {
891
+ None => {
892
+ let ty = this. arena . alloc ( this. ty ( i. span , hir:: TyKind :: Err ) ) ;
893
+ hir:: ImplItemKind :: TyAlias ( ty)
894
+ }
895
+ Some ( ty) => {
896
+ let ty = this. lower_ty ( ty, ImplTraitContext :: TypeAliasesOpaqueTy ) ;
897
+ hir:: ImplItemKind :: TyAlias ( ty)
898
+ }
899
+ } ,
900
+ )
894
901
}
895
902
AssocItemKind :: MacCall ( ..) => panic ! ( "`TyMac` should have been expanded by now" ) ,
896
903
} ;
@@ -1370,15 +1377,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1370
1377
}
1371
1378
}
1372
1379
1373
- pub ( super ) fn lower_generics (
1374
- & mut self ,
1375
- generics : & Generics ,
1376
- itctx : ImplTraitContext ,
1377
- ) -> & ' hir hir:: Generics < ' hir > {
1378
- let generics_ctor = self . lower_generics_mut ( generics, itctx) ;
1379
- generics_ctor. into_generics ( self . arena )
1380
- }
1381
-
1382
1380
pub ( super ) fn lower_generic_bound_predicate (
1383
1381
& mut self ,
1384
1382
ident : Ident ,
0 commit comments