@@ -780,8 +780,9 @@ impl<'a> LoweringContext<'a> {
780
780
_ => None ,
781
781
} ) ,
782
782
|this| {
783
+ let itctx = ImplTraitContext :: Universal ( parent_id) ;
783
784
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) )
785
786
} )
786
787
} ,
787
788
) ;
@@ -1043,7 +1044,11 @@ impl<'a> LoweringContext<'a> {
1043
1044
} ) ,
1044
1045
|this| {
1045
1046
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
+ ) ,
1047
1052
unsafety : this. lower_unsafety ( f. unsafety ) ,
1048
1053
abi : f. abi ,
1049
1054
decl : this. lower_fn_decl ( & f. decl , None , false ) ,
@@ -1784,7 +1789,12 @@ impl<'a> LoweringContext<'a> {
1784
1789
}
1785
1790
}
1786
1791
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 {
1788
1798
let mut name = self . lower_ident ( tp. ident ) ;
1789
1799
1790
1800
// Don't expose `Self` (recovered "keyword used as ident" parse error).
@@ -1794,7 +1804,6 @@ impl<'a> LoweringContext<'a> {
1794
1804
name = Symbol :: gensym ( "Self" ) ;
1795
1805
}
1796
1806
1797
- let itctx = ImplTraitContext :: Universal ( self . resolver . definitions ( ) . local_def_id ( tp. id ) ) ;
1798
1807
let mut bounds = self . lower_bounds ( & tp. bounds , itctx) ;
1799
1808
if !add_bounds. is_empty ( ) {
1800
1809
bounds = bounds
@@ -1879,6 +1888,7 @@ impl<'a> LoweringContext<'a> {
1879
1888
& mut self ,
1880
1889
params : & Vec < GenericParam > ,
1881
1890
add_bounds : & NodeMap < Vec < TyParamBound > > ,
1891
+ itctx : ImplTraitContext ,
1882
1892
) -> hir:: HirVec < hir:: GenericParam > {
1883
1893
params
1884
1894
. iter ( )
@@ -1889,12 +1899,13 @@ impl<'a> LoweringContext<'a> {
1889
1899
GenericParam :: Type ( ref ty_param) => hir:: GenericParam :: Type ( self . lower_ty_param (
1890
1900
ty_param,
1891
1901
add_bounds. get ( & ty_param. id ) . map_or ( & [ ] [ ..] , |x| & x) ,
1902
+ itctx,
1892
1903
) ) ,
1893
1904
} )
1894
1905
. collect ( )
1895
1906
}
1896
1907
1897
- fn lower_generics ( & mut self , g : & Generics ) -> hir:: Generics {
1908
+ fn lower_generics ( & mut self , g : & Generics , itctx : ImplTraitContext ) -> hir:: Generics {
1898
1909
// Collect `?Trait` bounds in where clause and move them to parameter definitions.
1899
1910
// FIXME: This could probably be done with less rightward drift. Also looks like two control
1900
1911
// paths where report_error is called are also the only paths that advance to after
@@ -1947,7 +1958,7 @@ impl<'a> LoweringContext<'a> {
1947
1958
}
1948
1959
1949
1960
hir:: Generics {
1950
- params : self . lower_generic_params ( & g. params , & add_bounds) ,
1961
+ params : self . lower_generic_params ( & g. params , & add_bounds, itctx ) ,
1951
1962
where_clause : self . lower_where_clause ( & g. where_clause ) ,
1952
1963
span : g. span ,
1953
1964
}
@@ -1981,6 +1992,7 @@ impl<'a> LoweringContext<'a> {
1981
1992
bound_generic_params : this. lower_generic_params (
1982
1993
bound_generic_params,
1983
1994
& NodeMap ( ) ,
1995
+ ImplTraitContext :: Disallowed ,
1984
1996
) ,
1985
1997
bounded_ty : this. lower_ty ( bounded_ty, ImplTraitContext :: Disallowed ) ,
1986
1998
bounds : bounds
@@ -2064,7 +2076,8 @@ impl<'a> LoweringContext<'a> {
2064
2076
p : & PolyTraitRef ,
2065
2077
itctx : ImplTraitContext ,
2066
2078
) -> 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) ;
2068
2081
let trait_ref = self . with_parent_impl_lifetime_defs (
2069
2082
& bound_generic_params
2070
2083
. iter ( )
@@ -2217,7 +2230,7 @@ impl<'a> LoweringContext<'a> {
2217
2230
ItemKind :: GlobalAsm ( ref ga) => hir:: ItemGlobalAsm ( self . lower_global_asm ( ga) ) ,
2218
2231
ItemKind :: Ty ( ref t, ref generics) => hir:: ItemTy (
2219
2232
self . lower_ty ( t, ImplTraitContext :: Disallowed ) ,
2220
- self . lower_generics ( generics) ,
2233
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2221
2234
) ,
2222
2235
ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemEnum (
2223
2236
hir:: EnumDef {
@@ -2227,15 +2240,21 @@ impl<'a> LoweringContext<'a> {
2227
2240
. map ( |x| self . lower_variant ( x) )
2228
2241
. collect ( ) ,
2229
2242
} ,
2230
- self . lower_generics ( generics) ,
2243
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2231
2244
) ,
2232
2245
ItemKind :: Struct ( ref struct_def, ref generics) => {
2233
2246
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
+ )
2235
2251
}
2236
2252
ItemKind :: Union ( ref vdata, ref generics) => {
2237
2253
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
+ )
2239
2258
}
2240
2259
ItemKind :: Impl (
2241
2260
unsafety,
@@ -2314,13 +2333,13 @@ impl<'a> LoweringContext<'a> {
2314
2333
hir:: ItemTrait (
2315
2334
self . lower_is_auto ( is_auto) ,
2316
2335
self . lower_unsafety ( unsafety) ,
2317
- self . lower_generics ( generics) ,
2336
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2318
2337
bounds,
2319
2338
items,
2320
2339
)
2321
2340
}
2322
2341
ItemKind :: TraitAlias ( ref generics, ref bounds) => hir:: ItemTraitAlias (
2323
- self . lower_generics ( generics) ,
2342
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2324
2343
self . lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
2325
2344
) ,
2326
2345
ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( ..) => panic ! ( "Shouldn't still be around" ) ,
@@ -2455,7 +2474,7 @@ impl<'a> LoweringContext<'a> {
2455
2474
2456
2475
let ( generics, node) = match i. node {
2457
2476
TraitItemKind :: Const ( ref ty, ref default) => (
2458
- this. lower_generics ( & i. generics ) ,
2477
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2459
2478
hir:: TraitItemKind :: Const (
2460
2479
this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
2461
2480
default
@@ -2496,7 +2515,7 @@ impl<'a> LoweringContext<'a> {
2496
2515
)
2497
2516
}
2498
2517
TraitItemKind :: Type ( ref bounds, ref default) => (
2499
- this. lower_generics ( & i. generics ) ,
2518
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2500
2519
hir:: TraitItemKind :: Type (
2501
2520
this. lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
2502
2521
default
@@ -2553,7 +2572,7 @@ impl<'a> LoweringContext<'a> {
2553
2572
ImplItemKind :: Const ( ref ty, ref expr) => {
2554
2573
let body_id = this. lower_body ( None , |this| this. lower_expr ( expr) ) ;
2555
2574
(
2556
- this. lower_generics ( & i. generics ) ,
2575
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2557
2576
hir:: ImplItemKind :: Const (
2558
2577
this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
2559
2578
body_id,
@@ -2584,7 +2603,7 @@ impl<'a> LoweringContext<'a> {
2584
2603
)
2585
2604
}
2586
2605
ImplItemKind :: Type ( ref ty) => (
2587
- this. lower_generics ( & i. generics ) ,
2606
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2588
2607
hir:: ImplItemKind :: Type ( this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ) ,
2589
2608
) ,
2590
2609
ImplItemKind :: Macro ( ..) => panic ! ( "Shouldn't exist any more" ) ,
0 commit comments