@@ -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
@@ -1878,6 +1887,7 @@ impl<'a> LoweringContext<'a> {
1878
1887
& mut self ,
1879
1888
params : & Vec < GenericParam > ,
1880
1889
add_bounds : & NodeMap < Vec < TyParamBound > > ,
1890
+ itctx : ImplTraitContext ,
1881
1891
) -> hir:: HirVec < hir:: GenericParam > {
1882
1892
params
1883
1893
. iter ( )
@@ -1888,12 +1898,13 @@ impl<'a> LoweringContext<'a> {
1888
1898
GenericParam :: Type ( ref ty_param) => hir:: GenericParam :: Type ( self . lower_ty_param (
1889
1899
ty_param,
1890
1900
add_bounds. get ( & ty_param. id ) . map_or ( & [ ] [ ..] , |x| & x) ,
1901
+ itctx,
1891
1902
) ) ,
1892
1903
} )
1893
1904
. collect ( )
1894
1905
}
1895
1906
1896
- fn lower_generics ( & mut self , g : & Generics ) -> hir:: Generics {
1907
+ fn lower_generics ( & mut self , g : & Generics , itctx : ImplTraitContext ) -> hir:: Generics {
1897
1908
// Collect `?Trait` bounds in where clause and move them to parameter definitions.
1898
1909
// FIXME: This could probably be done with less rightward drift. Also looks like two control
1899
1910
// paths where report_error is called are also the only paths that advance to after
@@ -1946,7 +1957,7 @@ impl<'a> LoweringContext<'a> {
1946
1957
}
1947
1958
1948
1959
hir:: Generics {
1949
- params : self . lower_generic_params ( & g. params , & add_bounds) ,
1960
+ params : self . lower_generic_params ( & g. params , & add_bounds, itctx ) ,
1950
1961
where_clause : self . lower_where_clause ( & g. where_clause ) ,
1951
1962
span : g. span ,
1952
1963
}
@@ -1980,6 +1991,7 @@ impl<'a> LoweringContext<'a> {
1980
1991
bound_generic_params : this. lower_generic_params (
1981
1992
bound_generic_params,
1982
1993
& NodeMap ( ) ,
1994
+ ImplTraitContext :: Disallowed ,
1983
1995
) ,
1984
1996
bounded_ty : this. lower_ty ( bounded_ty, ImplTraitContext :: Disallowed ) ,
1985
1997
bounds : bounds
@@ -2063,7 +2075,8 @@ impl<'a> LoweringContext<'a> {
2063
2075
p : & PolyTraitRef ,
2064
2076
itctx : ImplTraitContext ,
2065
2077
) -> 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) ;
2067
2080
let trait_ref = self . with_parent_impl_lifetime_defs (
2068
2081
& bound_generic_params
2069
2082
. iter ( )
@@ -2218,7 +2231,7 @@ impl<'a> LoweringContext<'a> {
2218
2231
ItemKind :: GlobalAsm ( ref ga) => hir:: ItemGlobalAsm ( self . lower_global_asm ( ga) ) ,
2219
2232
ItemKind :: Ty ( ref t, ref generics) => hir:: ItemTy (
2220
2233
self . lower_ty ( t, ImplTraitContext :: Disallowed ) ,
2221
- self . lower_generics ( generics) ,
2234
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2222
2235
) ,
2223
2236
ItemKind :: Enum ( ref enum_definition, ref generics) => hir:: ItemEnum (
2224
2237
hir:: EnumDef {
@@ -2228,15 +2241,21 @@ impl<'a> LoweringContext<'a> {
2228
2241
. map ( |x| self . lower_variant ( x) )
2229
2242
. collect ( ) ,
2230
2243
} ,
2231
- self . lower_generics ( generics) ,
2244
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2232
2245
) ,
2233
2246
ItemKind :: Struct ( ref struct_def, ref generics) => {
2234
2247
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
+ )
2236
2252
}
2237
2253
ItemKind :: Union ( ref vdata, ref generics) => {
2238
2254
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
+ )
2240
2259
}
2241
2260
ItemKind :: Impl (
2242
2261
unsafety,
@@ -2315,13 +2334,13 @@ impl<'a> LoweringContext<'a> {
2315
2334
hir:: ItemTrait (
2316
2335
self . lower_is_auto ( is_auto) ,
2317
2336
self . lower_unsafety ( unsafety) ,
2318
- self . lower_generics ( generics) ,
2337
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2319
2338
bounds,
2320
2339
items,
2321
2340
)
2322
2341
}
2323
2342
ItemKind :: TraitAlias ( ref generics, ref bounds) => hir:: ItemTraitAlias (
2324
- self . lower_generics ( generics) ,
2343
+ self . lower_generics ( generics, ImplTraitContext :: Disallowed ) ,
2325
2344
self . lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
2326
2345
) ,
2327
2346
ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( ..) => panic ! ( "Shouldn't still be around" ) ,
@@ -2456,7 +2475,7 @@ impl<'a> LoweringContext<'a> {
2456
2475
2457
2476
let ( generics, node) = match i. node {
2458
2477
TraitItemKind :: Const ( ref ty, ref default) => (
2459
- this. lower_generics ( & i. generics ) ,
2478
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2460
2479
hir:: TraitItemKind :: Const (
2461
2480
this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
2462
2481
default
@@ -2497,7 +2516,7 @@ impl<'a> LoweringContext<'a> {
2497
2516
)
2498
2517
}
2499
2518
TraitItemKind :: Type ( ref bounds, ref default) => (
2500
- this. lower_generics ( & i. generics ) ,
2519
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2501
2520
hir:: TraitItemKind :: Type (
2502
2521
this. lower_bounds ( bounds, ImplTraitContext :: Disallowed ) ,
2503
2522
default
@@ -2554,7 +2573,7 @@ impl<'a> LoweringContext<'a> {
2554
2573
ImplItemKind :: Const ( ref ty, ref expr) => {
2555
2574
let body_id = this. lower_body ( None , |this| this. lower_expr ( expr) ) ;
2556
2575
(
2557
- this. lower_generics ( & i. generics ) ,
2576
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2558
2577
hir:: ImplItemKind :: Const (
2559
2578
this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ,
2560
2579
body_id,
@@ -2585,7 +2604,7 @@ impl<'a> LoweringContext<'a> {
2585
2604
)
2586
2605
}
2587
2606
ImplItemKind :: Type ( ref ty) => (
2588
- this. lower_generics ( & i. generics ) ,
2607
+ this. lower_generics ( & i. generics , ImplTraitContext :: Disallowed ) ,
2589
2608
hir:: ImplItemKind :: Type ( this. lower_ty ( ty, ImplTraitContext :: Disallowed ) ) ,
2590
2609
) ,
2591
2610
ImplItemKind :: Macro ( ..) => panic ! ( "Shouldn't exist any more" ) ,
0 commit comments