@@ -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 ( )
@@ -2216,7 +2229,7 @@ impl<'a> LoweringContext<'a> {
22162229 ItemKind :: GlobalAsm ( ref ga) => hir:: ItemGlobalAsm ( self . lower_global_asm ( ga) ) ,
22172230 ItemKind :: Ty ( ref t, ref generics) => hir:: ItemTy (
22182231 self . lower_ty ( t, ImplTraitContext :: Disallowed ) ,
2219- self . lower_generics ( generics) ,
2232+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
22202233 ) ,
22212234 ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemEnum (
22222235 hir:: EnumDef {
@@ -2226,15 +2239,21 @@ impl<'a> LoweringContext<'a> {
22262239 . map ( |x| self . lower_variant ( x) )
22272240 . collect ( ) ,
22282241 } ,
2229- self . lower_generics ( generics) ,
2242+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
22302243 ) ,
22312244 ItemKind :: Struct ( ref struct_def, ref generics) => {
22322245 let struct_def = self . lower_variant_data ( struct_def) ;
2233- hir:: ItemStruct ( struct_def, self . lower_generics ( generics) )
2246+ hir:: ItemStruct (
2247+ struct_def,
2248+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2249+ )
22342250 }
22352251 ItemKind :: Union ( ref vdata, ref generics) => {
22362252 let vdata = self . lower_variant_data ( vdata) ;
2237- hir:: ItemUnion ( vdata, self . lower_generics ( generics) )
2253+ hir:: ItemUnion (
2254+ vdata,
2255+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2256+ )
22382257 }
22392258 ItemKind :: Impl (
22402259 unsafety,
@@ -2313,13 +2332,13 @@ impl<'a> LoweringContext<'a> {
23132332 hir:: ItemTrait (
23142333 self . lower_is_auto ( is_auto) ,
23152334 self . lower_unsafety ( unsafety) ,
2316- self . lower_generics ( generics) ,
2335+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
23172336 bounds,
23182337 items,
23192338 )
23202339 }
23212340 ItemKind :: TraitAlias ( ref generics, ref bounds) => hir:: ItemTraitAlias (
2322- self . lower_generics ( generics) ,
2341+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
23232342 self . lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
23242343 ) ,
23252344 ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( ..) => panic ! ( "Shouldn't still be around" ) ,
@@ -2454,7 +2473,7 @@ impl<'a> LoweringContext<'a> {
24542473
24552474 let ( generics, node) = match i. node {
24562475 TraitItemKind :: Const ( ref ty, ref default) => (
2457- this. lower_generics ( & i. generics ) ,
2476+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
24582477 hir:: TraitItemKind :: Const (
24592478 this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
24602479 default
@@ -2495,7 +2514,7 @@ impl<'a> LoweringContext<'a> {
24952514 )
24962515 }
24972516 TraitItemKind :: Type ( ref bounds, ref default) => (
2498- this. lower_generics ( & i. generics ) ,
2517+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
24992518 hir:: TraitItemKind :: Type (
25002519 this. lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
25012520 default
@@ -2552,7 +2571,7 @@ impl<'a> LoweringContext<'a> {
25522571 ImplItemKind :: Const ( ref ty, ref expr) => {
25532572 let body_id = this. lower_body ( None , |this| this. lower_expr ( expr) ) ;
25542573 (
2555- this. lower_generics ( & i. generics ) ,
2574+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25562575 hir:: ImplItemKind :: Const (
25572576 this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
25582577 body_id,
@@ -2583,7 +2602,7 @@ impl<'a> LoweringContext<'a> {
25832602 )
25842603 }
25852604 ImplItemKind :: Type ( ref ty) => (
2586- this. lower_generics ( & i. generics ) ,
2605+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
25872606 hir:: ImplItemKind :: Type ( this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ) ,
25882607 ) ,
25892608 ImplItemKind :: Macro ( ..) => panic ! ( "Shouldn't exist any more" ) ,
0 commit comments