@@ -780,8 +780,9 @@ impl<'a> LoweringContext<'a> {
780780 _ => None ,
781781 } ) ,
782782 |this| {
783+ let itctx = ImplTraitContext :: Universal ( parent_id) ;
783784 this. collect_in_band_defs ( parent_id, anonymous_lifetime_mode, |this| {
784- ( this. lower_generics ( generics) , f ( this) )
785+ ( this. lower_generics ( generics, itctx ) , f ( this) )
785786 } )
786787 } ,
787788 ) ;
@@ -1043,7 +1044,11 @@ impl<'a> LoweringContext<'a> {
10431044 } ) ,
10441045 |this| {
10451046 hir:: TyBareFn ( P ( hir:: BareFnTy {
1046- generic_params : this. lower_generic_params ( & f. generic_params , & NodeMap ( ) ) ,
1047+ generic_params : this. lower_generic_params (
1048+ & f. generic_params ,
1049+ & NodeMap ( ) ,
1050+ ImplTraitContext :: Disallowed ,
1051+ ) ,
10471052 unsafety : this. lower_unsafety ( f. unsafety ) ,
10481053 abi : f. abi ,
10491054 decl : this. lower_fn_decl ( & f. decl , None , false ) ,
@@ -1784,7 +1789,12 @@ impl<'a> LoweringContext<'a> {
17841789 }
17851790 }
17861791
1787- fn lower_ty_param ( & mut self , tp : & TyParam , add_bounds : & [ TyParamBound ] ) -> hir:: TyParam {
1792+ fn lower_ty_param (
1793+ & mut self ,
1794+ tp : & TyParam ,
1795+ add_bounds : & [ TyParamBound ] ,
1796+ itctx : ImplTraitContext ,
1797+ ) -> hir:: TyParam {
17881798 let mut name = self . lower_ident ( tp. ident ) ;
17891799
17901800 // Don't expose `Self` (recovered "keyword used as ident" parse error).
@@ -1794,7 +1804,6 @@ impl<'a> LoweringContext<'a> {
17941804 name = Symbol :: gensym ( "Self" ) ;
17951805 }
17961806
1797- let itctx = ImplTraitContext :: Universal ( self . resolver . definitions ( ) . local_def_id ( tp. id ) ) ;
17981807 let mut bounds = self . lower_bounds ( & tp. bounds , itctx) ;
17991808 if !add_bounds. is_empty ( ) {
18001809 bounds = bounds
@@ -1878,6 +1887,7 @@ impl<'a> LoweringContext<'a> {
18781887 & mut self ,
18791888 params : & Vec < GenericParam > ,
18801889 add_bounds : & NodeMap < Vec < TyParamBound > > ,
1890+ itctx : ImplTraitContext ,
18811891 ) -> hir:: HirVec < hir:: GenericParam > {
18821892 params
18831893 . iter ( )
@@ -1888,12 +1898,13 @@ impl<'a> LoweringContext<'a> {
18881898 GenericParam :: Type ( ref ty_param) => hir:: GenericParam :: Type ( self . lower_ty_param (
18891899 ty_param,
18901900 add_bounds. get ( & ty_param. id ) . map_or ( & [ ] [ ..] , |x| & x) ,
1901+ itctx,
18911902 ) ) ,
18921903 } )
18931904 . collect ( )
18941905 }
18951906
1896- fn lower_generics ( & mut self , g : & Generics ) -> hir:: Generics {
1907+ fn lower_generics ( & mut self , g : & Generics , itctx : ImplTraitContext ) -> hir:: Generics {
18971908 // Collect `?Trait` bounds in where clause and move them to parameter definitions.
18981909 // FIXME: This could probably be done with less rightward drift. Also looks like two control
18991910 // paths where report_error is called are also the only paths that advance to after
@@ -1946,7 +1957,7 @@ impl<'a> LoweringContext<'a> {
19461957 }
19471958
19481959 hir:: Generics {
1949- params : self . lower_generic_params ( & g. params , & add_bounds) ,
1960+ params : self . lower_generic_params ( & g. params , & add_bounds, itctx ) ,
19501961 where_clause : self . lower_where_clause ( & g. where_clause ) ,
19511962 span : g. span ,
19521963 }
@@ -1980,6 +1991,7 @@ impl<'a> LoweringContext<'a> {
19801991 bound_generic_params : this. lower_generic_params (
19811992 bound_generic_params,
19821993 & NodeMap ( ) ,
1994+ ImplTraitContext :: Disallowed ,
19831995 ) ,
19841996 bounded_ty : this. lower_ty ( bounded_ty, ImplTraitContext :: Disallowed ) ,
19851997 bounds : bounds
@@ -2063,7 +2075,8 @@ impl<'a> LoweringContext<'a> {
20632075 p : & PolyTraitRef ,
20642076 itctx : ImplTraitContext ,
20652077 ) -> hir:: PolyTraitRef {
2066- let bound_generic_params = self . lower_generic_params ( & p. bound_generic_params , & NodeMap ( ) ) ;
2078+ let bound_generic_params =
2079+ self . lower_generic_params ( & p. bound_generic_params , & NodeMap ( ) , itctx) ;
20672080 let trait_ref = self . with_parent_impl_lifetime_defs (
20682081 & bound_generic_params
20692082 . iter ( )
@@ -2218,7 +2231,7 @@ impl<'a> LoweringContext<'a> {
22182231 ItemKind :: GlobalAsm ( ref ga) => hir:: ItemGlobalAsm ( self . lower_global_asm ( ga) ) ,
22192232 ItemKind :: Ty ( ref t, ref generics) => hir:: ItemTy (
22202233 self . lower_ty ( t, ImplTraitContext :: Disallowed ) ,
2221- self . lower_generics ( generics) ,
2234+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
22222235 ) ,
22232236 ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemEnum (
22242237 hir:: EnumDef {
@@ -2228,15 +2241,21 @@ impl<'a> LoweringContext<'a> {
22282241 . map ( |x| self . lower_variant ( x) )
22292242 . collect ( ) ,
22302243 } ,
2231- self . lower_generics ( generics) ,
2244+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
22322245 ) ,
22332246 ItemKind :: Struct ( ref struct_def, ref generics) => {
22342247 let struct_def = self . lower_variant_data ( struct_def) ;
2235- hir:: ItemStruct ( struct_def, self . lower_generics ( generics) )
2248+ hir:: ItemStruct (
2249+ struct_def,
2250+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2251+ )
22362252 }
22372253 ItemKind :: Union ( ref vdata, ref generics) => {
22382254 let vdata = self . lower_variant_data ( vdata) ;
2239- hir:: ItemUnion ( vdata, self . lower_generics ( generics) )
2255+ hir:: ItemUnion (
2256+ vdata,
2257+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2258+ )
22402259 }
22412260 ItemKind :: Impl (
22422261 unsafety,
@@ -2315,13 +2334,13 @@ impl<'a> LoweringContext<'a> {
23152334 hir:: ItemTrait (
23162335 self . lower_is_auto ( is_auto) ,
23172336 self . lower_unsafety ( unsafety) ,
2318- self . lower_generics ( generics) ,
2337+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
23192338 bounds,
23202339 items,
23212340 )
23222341 }
23232342 ItemKind :: TraitAlias ( ref generics, ref bounds) => hir:: ItemTraitAlias (
2324- self . lower_generics ( generics) ,
2343+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
23252344 self . lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
23262345 ) ,
23272346 ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( ..) => panic ! ( "Shouldn't still be around" ) ,
@@ -2456,7 +2475,7 @@ impl<'a> LoweringContext<'a> {
24562475
24572476 let ( generics, node) = match i. node {
24582477 TraitItemKind :: Const ( ref ty, ref default) => (
2459- this. lower_generics ( & i. generics ) ,
2478+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
24602479 hir:: TraitItemKind :: Const (
24612480 this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
24622481 default
@@ -2497,7 +2516,7 @@ impl<'a> LoweringContext<'a> {
24972516 )
24982517 }
24992518 TraitItemKind :: Type ( ref bounds, ref default) => (
2500- this. lower_generics ( & i. generics ) ,
2519+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25012520 hir:: TraitItemKind :: Type (
25022521 this. lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
25032522 default
@@ -2554,7 +2573,7 @@ impl<'a> LoweringContext<'a> {
25542573 ImplItemKind :: Const ( ref ty, ref expr) => {
25552574 let body_id = this. lower_body ( None , |this| this. lower_expr ( expr) ) ;
25562575 (
2557- this. lower_generics ( & i. generics ) ,
2576+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25582577 hir:: ImplItemKind :: Const (
25592578 this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
25602579 body_id,
@@ -2585,7 +2604,7 @@ impl<'a> LoweringContext<'a> {
25852604 )
25862605 }
25872606 ImplItemKind :: Type ( ref ty) => (
2588- this. lower_generics ( & i. generics ) ,
2607+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25892608 hir:: ImplItemKind :: Type ( this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ) ,
25902609 ) ,
25912610 ImplItemKind :: Macro ( ..) => panic ! ( "Shouldn't exist any more" ) ,
0 commit comments