@@ -309,57 +309,59 @@ impl<'hir> LoweringContext<'_, 'hir> {
309309 //
310310 // type Foo = Foo1
311311 // opaque type Foo1: Trait
312- let ty = self . lower_ty ( ty, ImplTraitContext :: TypeAliasesOpaqueTy ) ;
313312 let mut generics = generics. clone ( ) ;
314313 add_ty_alias_where_clause ( & mut generics, where_clauses, true ) ;
315- let generics = self . lower_generics (
314+ let ( generics, ty ) = self . add_implicit_generics (
316315 & generics,
316+ id,
317317 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
318+ |this| this. lower_ty ( ty, ImplTraitContext :: TypeAliasesOpaqueTy ) ,
318319 ) ;
319320 hir:: ItemKind :: TyAlias ( ty, generics)
320321 }
321322 ItemKind :: TyAlias ( box TyAlias {
322323 ref generics, ref where_clauses, ty : None , ..
323324 } ) => {
324- let ty = self . arena . alloc ( self . ty ( span, hir:: TyKind :: Err ) ) ;
325325 let mut generics = generics. clone ( ) ;
326326 add_ty_alias_where_clause ( & mut generics, * where_clauses, true ) ;
327- let generics = self . lower_generics (
327+ let ( generics, ty ) = self . add_implicit_generics (
328328 & generics,
329+ id,
329330 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
331+ |this| this. arena . alloc ( this. ty ( span, hir:: TyKind :: Err ) ) ,
330332 ) ;
331333 hir:: ItemKind :: TyAlias ( ty, generics)
332334 }
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 (
340337 generics,
338+ id,
341339 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+ }
344348 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)
353356 }
354357 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)
363365 }
364366 ItemKind :: Impl ( box Impl {
365367 unsafety,
@@ -431,34 +433,38 @@ impl<'hir> LoweringContext<'_, 'hir> {
431433 ref bounds,
432434 ref items,
433435 } ) => {
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+ } ,
437451 ) ;
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)
451453 }
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 (
454456 generics,
457+ id,
455458 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+ }
462468 ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
463469 let body = P ( self . lower_mac_args ( body) ) ;
464470 let macro_kind = self . resolver . decl_macro_kind ( self . resolver . local_def_id ( id) ) ;
@@ -789,24 +795,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
789795 ref ty,
790796 ..
791797 } ) => {
792- let ty = ty. as_ref ( ) . map ( |x| {
793- self . lower_ty ( x, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Type ) )
794- } ) ;
795798 let mut generics = generics. clone ( ) ;
796799 add_ty_alias_where_clause ( & mut generics, where_clauses, false ) ;
797- let generics = self . lower_generics (
800+ self . add_implicit_generics (
798801 & generics,
802+ i. id ,
799803 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+ )
810817 }
811818 AssocItemKind :: MacCall ( ..) => panic ! ( "macro item shouldn't exist at this point" ) ,
812819 } ;
@@ -876,21 +883,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
876883 AssocItemKind :: TyAlias ( box TyAlias { generics, where_clauses, ty, .. } ) => {
877884 let mut generics = generics. clone ( ) ;
878885 add_ty_alias_where_clause ( & mut generics, * where_clauses, false ) ;
879- let generics = self . lower_generics (
886+ self . add_implicit_generics (
880887 & generics,
888+ i. id ,
881889 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+ )
894901 }
895902 AssocItemKind :: MacCall ( ..) => panic ! ( "`TyMac` should have been expanded by now" ) ,
896903 } ;
@@ -1370,15 +1377,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
13701377 }
13711378 }
13721379
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-
13821380 pub ( super ) fn lower_generic_bound_predicate (
13831381 & mut self ,
13841382 ident : Ident ,
0 commit comments