@@ -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 ( )
@@ -2216,7 +2229,7 @@ impl<'a> LoweringContext<'a> {
2216
2229
ItemKind :: GlobalAsm ( ref ga) => hir:: ItemGlobalAsm ( self . lower_global_asm ( ga) ) ,
2217
2230
ItemKind :: Ty ( ref t, ref generics) => hir:: ItemTy (
2218
2231
self . lower_ty ( t, ImplTraitContext :: Disallowed ) ,
2219
- self . lower_generics ( generics) ,
2232
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2220
2233
) ,
2221
2234
ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemEnum (
2222
2235
hir:: EnumDef {
@@ -2226,15 +2239,21 @@ impl<'a> LoweringContext<'a> {
2226
2239
. map ( |x| self . lower_variant ( x) )
2227
2240
. collect ( ) ,
2228
2241
} ,
2229
- self . lower_generics ( generics) ,
2242
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2230
2243
) ,
2231
2244
ItemKind :: Struct ( ref struct_def, ref generics) => {
2232
2245
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
+ )
2234
2250
}
2235
2251
ItemKind :: Union ( ref vdata, ref generics) => {
2236
2252
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
+ )
2238
2257
}
2239
2258
ItemKind :: Impl (
2240
2259
unsafety,
@@ -2313,13 +2332,13 @@ impl<'a> LoweringContext<'a> {
2313
2332
hir:: ItemTrait (
2314
2333
self . lower_is_auto ( is_auto) ,
2315
2334
self . lower_unsafety ( unsafety) ,
2316
- self . lower_generics ( generics) ,
2335
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2317
2336
bounds,
2318
2337
items,
2319
2338
)
2320
2339
}
2321
2340
ItemKind :: TraitAlias ( ref generics, ref bounds) => hir:: ItemTraitAlias (
2322
- self . lower_generics ( generics) ,
2341
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2323
2342
self . lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
2324
2343
) ,
2325
2344
ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( ..) => panic ! ( "Shouldn't still be around" ) ,
@@ -2454,7 +2473,7 @@ impl<'a> LoweringContext<'a> {
2454
2473
2455
2474
let ( generics, node) = match i. node {
2456
2475
TraitItemKind :: Const ( ref ty, ref default) => (
2457
- this. lower_generics ( & i. generics ) ,
2476
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2458
2477
hir:: TraitItemKind :: Const (
2459
2478
this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
2460
2479
default
@@ -2495,7 +2514,7 @@ impl<'a> LoweringContext<'a> {
2495
2514
)
2496
2515
}
2497
2516
TraitItemKind :: Type ( ref bounds, ref default) => (
2498
- this. lower_generics ( & i. generics ) ,
2517
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2499
2518
hir:: TraitItemKind :: Type (
2500
2519
this. lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
2501
2520
default
@@ -2552,7 +2571,7 @@ impl<'a> LoweringContext<'a> {
2552
2571
ImplItemKind :: Const ( ref ty, ref expr) => {
2553
2572
let body_id = this. lower_body ( None , |this| this. lower_expr ( expr) ) ;
2554
2573
(
2555
- this. lower_generics ( & i. generics ) ,
2574
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2556
2575
hir:: ImplItemKind :: Const (
2557
2576
this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
2558
2577
body_id,
@@ -2583,7 +2602,7 @@ impl<'a> LoweringContext<'a> {
2583
2602
)
2584
2603
}
2585
2604
ImplItemKind :: Type ( ref ty) => (
2586
- this. lower_generics ( & i. generics ) ,
2605
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2587
2606
hir:: ImplItemKind :: Type ( this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ) ,
2588
2607
) ,
2589
2608
ImplItemKind :: Macro ( ..) => panic ! ( "Shouldn't exist any more" ) ,
0 commit comments