@@ -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
@@ -1879,6 +1888,7 @@ impl<'a> LoweringContext<'a> {
18791888 & mut self ,
18801889 params : & Vec < GenericParam > ,
18811890 add_bounds : & NodeMap < Vec < TyParamBound > > ,
1891+ itctx : ImplTraitContext ,
18821892 ) -> hir:: HirVec < hir:: GenericParam > {
18831893 params
18841894 . iter ( )
@@ -1889,12 +1899,13 @@ impl<'a> LoweringContext<'a> {
18891899 GenericParam :: Type ( ref ty_param) => hir:: GenericParam :: Type ( self . lower_ty_param (
18901900 ty_param,
18911901 add_bounds. get ( & ty_param. id ) . map_or ( & [ ] [ ..] , |x| & x) ,
1902+ itctx,
18921903 ) ) ,
18931904 } )
18941905 . collect ( )
18951906 }
18961907
1897- fn lower_generics ( & mut self , g : & Generics ) -> hir:: Generics {
1908+ fn lower_generics ( & mut self , g : & Generics , itctx : ImplTraitContext ) -> hir:: Generics {
18981909 // Collect `?Trait` bounds in where clause and move them to parameter definitions.
18991910 // FIXME: This could probably be done with less rightward drift. Also looks like two control
19001911 // paths where report_error is called are also the only paths that advance to after
@@ -1947,7 +1958,7 @@ impl<'a> LoweringContext<'a> {
19471958 }
19481959
19491960 hir:: Generics {
1950- params : self . lower_generic_params ( & g. params , & add_bounds) ,
1961+ params : self . lower_generic_params ( & g. params , & add_bounds, itctx ) ,
19511962 where_clause : self . lower_where_clause ( & g. where_clause ) ,
19521963 span : g. span ,
19531964 }
@@ -1981,6 +1992,7 @@ impl<'a> LoweringContext<'a> {
19811992 bound_generic_params : this. lower_generic_params (
19821993 bound_generic_params,
19831994 & NodeMap ( ) ,
1995+ ImplTraitContext :: Disallowed ,
19841996 ) ,
19851997 bounded_ty : this. lower_ty ( bounded_ty, ImplTraitContext :: Disallowed ) ,
19861998 bounds : bounds
@@ -2064,7 +2076,8 @@ impl<'a> LoweringContext<'a> {
20642076 p : & PolyTraitRef ,
20652077 itctx : ImplTraitContext ,
20662078 ) -> hir:: PolyTraitRef {
2067- let bound_generic_params = self . lower_generic_params ( & p. bound_generic_params , & NodeMap ( ) ) ;
2079+ let bound_generic_params =
2080+ self . lower_generic_params ( & p. bound_generic_params , & NodeMap ( ) , itctx) ;
20682081 let trait_ref = self . with_parent_impl_lifetime_defs (
20692082 & bound_generic_params
20702083 . iter ( )
@@ -2217,7 +2230,7 @@ impl<'a> LoweringContext<'a> {
22172230 ItemKind :: GlobalAsm ( ref ga) => hir:: ItemGlobalAsm ( self . lower_global_asm ( ga) ) ,
22182231 ItemKind :: Ty ( ref t, ref generics) => hir:: ItemTy (
22192232 self . lower_ty ( t, ImplTraitContext :: Disallowed ) ,
2220- self . lower_generics ( generics) ,
2233+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
22212234 ) ,
22222235 ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemEnum (
22232236 hir:: EnumDef {
@@ -2227,15 +2240,21 @@ impl<'a> LoweringContext<'a> {
22272240 . map ( |x| self . lower_variant ( x) )
22282241 . collect ( ) ,
22292242 } ,
2230- self . lower_generics ( generics) ,
2243+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
22312244 ) ,
22322245 ItemKind :: Struct ( ref struct_def, ref generics) => {
22332246 let struct_def = self . lower_variant_data ( struct_def) ;
2234- hir:: ItemStruct ( struct_def, self . lower_generics ( generics) )
2247+ hir:: ItemStruct (
2248+ struct_def,
2249+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2250+ )
22352251 }
22362252 ItemKind :: Union ( ref vdata, ref generics) => {
22372253 let vdata = self . lower_variant_data ( vdata) ;
2238- hir:: ItemUnion ( vdata, self . lower_generics ( generics) )
2254+ hir:: ItemUnion (
2255+ vdata,
2256+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2257+ )
22392258 }
22402259 ItemKind :: Impl (
22412260 unsafety,
@@ -2314,13 +2333,13 @@ impl<'a> LoweringContext<'a> {
23142333 hir:: ItemTrait (
23152334 self . lower_is_auto ( is_auto) ,
23162335 self . lower_unsafety ( unsafety) ,
2317- self . lower_generics ( generics) ,
2336+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
23182337 bounds,
23192338 items,
23202339 )
23212340 }
23222341 ItemKind :: TraitAlias ( ref generics, ref bounds) => hir:: ItemTraitAlias (
2323- self . lower_generics ( generics) ,
2342+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
23242343 self . lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
23252344 ) ,
23262345 ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( ..) => panic ! ( "Shouldn't still be around" ) ,
@@ -2455,7 +2474,7 @@ impl<'a> LoweringContext<'a> {
24552474
24562475 let ( generics, node) = match i. node {
24572476 TraitItemKind :: Const ( ref ty, ref default) => (
2458- this. lower_generics ( & i. generics ) ,
2477+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
24592478 hir:: TraitItemKind :: Const (
24602479 this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
24612480 default
@@ -2496,7 +2515,7 @@ impl<'a> LoweringContext<'a> {
24962515 )
24972516 }
24982517 TraitItemKind :: Type ( ref bounds, ref default) => (
2499- this. lower_generics ( & i. generics ) ,
2518+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25002519 hir:: TraitItemKind :: Type (
25012520 this. lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
25022521 default
@@ -2553,7 +2572,7 @@ impl<'a> LoweringContext<'a> {
25532572 ImplItemKind :: Const ( ref ty, ref expr) => {
25542573 let body_id = this. lower_body ( None , |this| this. lower_expr ( expr) ) ;
25552574 (
2556- this. lower_generics ( & i. generics ) ,
2575+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25572576 hir:: ImplItemKind :: Const (
25582577 this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
25592578 body_id,
@@ -2584,7 +2603,7 @@ impl<'a> LoweringContext<'a> {
25842603 )
25852604 }
25862605 ImplItemKind :: Type ( ref ty) => (
2587- this. lower_generics ( & i. generics ) ,
2606+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25882607 hir:: ImplItemKind :: Type ( this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ) ,
25892608 ) ,
25902609 ImplItemKind :: Macro ( ..) => panic ! ( "Shouldn't exist any more" ) ,
0 commit comments