@@ -264,8 +264,8 @@ enum ImplTraitContext<'b, 'a> {
264
264
/// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
265
265
origin : hir:: OpaqueTyOrigin ,
266
266
} ,
267
- /// Impl trait in type aliases, consts and statics .
268
- OtherOpaqueTy {
267
+ /// Impl trait in type aliases.
268
+ TypeAliasesOpaqueTy {
269
269
/// Set of lifetimes that this opaque type can capture, if it uses
270
270
/// them. This includes lifetimes bound since we entered this context.
271
271
/// For example:
@@ -280,8 +280,6 @@ enum ImplTraitContext<'b, 'a> {
280
280
// FIXME(impl_trait): but `required_region_bounds` will ICE later
281
281
// anyway.
282
282
capturable_lifetimes : & ' b mut FxHashSet < hir:: LifetimeName > ,
283
- /// Origin: Either OpaqueTyOrigin::Misc or OpaqueTyOrigin::Binding,
284
- origin : hir:: OpaqueTyOrigin ,
285
283
} ,
286
284
/// `impl Trait` is not accepted in this position.
287
285
Disallowed ( ImplTraitPosition ) ,
@@ -310,8 +308,8 @@ impl<'a> ImplTraitContext<'_, 'a> {
310
308
ReturnPositionOpaqueTy { fn_def_id, origin } => {
311
309
ReturnPositionOpaqueTy { fn_def_id : * fn_def_id, origin : * origin }
312
310
}
313
- OtherOpaqueTy { capturable_lifetimes, origin } => {
314
- OtherOpaqueTy { capturable_lifetimes, origin : * origin }
311
+ TypeAliasesOpaqueTy { capturable_lifetimes } => {
312
+ TypeAliasesOpaqueTy { capturable_lifetimes }
315
313
}
316
314
Disallowed ( pos) => Disallowed ( * pos) ,
317
315
}
@@ -1126,7 +1124,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1126
1124
//
1127
1125
// fn foo() -> impl Iterator<Item = impl Debug>
1128
1126
ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1129
- | ImplTraitContext :: OtherOpaqueTy { .. } => ( true , itctx) ,
1127
+ | ImplTraitContext :: TypeAliasesOpaqueTy { .. } => ( true , itctx) ,
1130
1128
1131
1129
// We are in the argument position, but within a dyn type:
1132
1130
//
@@ -1150,9 +1148,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1150
1148
capturable_lifetimes = FxHashSet :: default ( ) ;
1151
1149
(
1152
1150
true ,
1153
- ImplTraitContext :: OtherOpaqueTy {
1151
+ ImplTraitContext :: TypeAliasesOpaqueTy {
1154
1152
capturable_lifetimes : & mut capturable_lifetimes,
1155
- origin : hir:: OpaqueTyOrigin :: Misc ,
1156
1153
} ,
1157
1154
)
1158
1155
}
@@ -1416,18 +1413,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1416
1413
None ,
1417
1414
|this| this. lower_param_bounds ( bounds, itctx) ,
1418
1415
) ,
1419
- ImplTraitContext :: OtherOpaqueTy { ref capturable_lifetimes, origin } => {
1416
+ ImplTraitContext :: TypeAliasesOpaqueTy { ref capturable_lifetimes } => {
1420
1417
// Reset capturable lifetimes, any nested impl trait
1421
1418
// types will inherit lifetimes from this opaque type,
1422
1419
// so don't need to capture them again.
1423
- let nested_itctx = ImplTraitContext :: OtherOpaqueTy {
1420
+ let nested_itctx = ImplTraitContext :: TypeAliasesOpaqueTy {
1424
1421
capturable_lifetimes : & mut FxHashSet :: default ( ) ,
1425
- origin,
1426
1422
} ;
1427
1423
self . lower_opaque_impl_trait (
1428
1424
span,
1429
1425
None ,
1430
- origin ,
1426
+ hir :: OpaqueTyOrigin :: TyAlias ,
1431
1427
def_node_id,
1432
1428
Some ( capturable_lifetimes) ,
1433
1429
|this| this. lower_param_bounds ( bounds, nested_itctx) ,
@@ -1464,25 +1460,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1464
1460
} ) ,
1465
1461
) )
1466
1462
}
1467
- ImplTraitContext :: Disallowed ( pos) => {
1468
- let allowed_in = if self . sess . features_untracked ( ) . impl_trait_in_bindings {
1469
- "bindings or function and inherent method return types"
1470
- } else {
1471
- "function and inherent method return types"
1472
- } ;
1463
+ ImplTraitContext :: Disallowed ( _) => {
1473
1464
let mut err = struct_span_err ! (
1474
1465
self . sess,
1475
1466
t. span,
1476
1467
E0562 ,
1477
1468
"`impl Trait` not allowed outside of {}" ,
1478
- allowed_in ,
1469
+ "function and method return types" ,
1479
1470
) ;
1480
- if pos == ImplTraitPosition :: Binding && self . sess . is_nightly_build ( ) {
1481
- err. help (
1482
- "add `#![feature(impl_trait_in_bindings)]` to the crate \
1483
- attributes to enable",
1484
- ) ;
1485
- }
1486
1471
err. emit ( ) ;
1487
1472
hir:: TyKind :: Err
1488
1473
}
@@ -1767,21 +1752,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1767
1752
}
1768
1753
1769
1754
fn lower_local ( & mut self , l : & Local ) -> hir:: Local < ' hir > {
1770
- let ty = l. ty . as_ref ( ) . map ( |t| {
1771
- let mut capturable_lifetimes;
1772
- self . lower_ty (
1773
- t,
1774
- if self . sess . features_untracked ( ) . impl_trait_in_bindings {
1775
- capturable_lifetimes = FxHashSet :: default ( ) ;
1776
- ImplTraitContext :: OtherOpaqueTy {
1777
- capturable_lifetimes : & mut capturable_lifetimes,
1778
- origin : hir:: OpaqueTyOrigin :: Binding ,
1779
- }
1780
- } else {
1781
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
1782
- } ,
1783
- )
1784
- } ) ;
1755
+ let ty = l
1756
+ . ty
1757
+ . as_ref ( )
1758
+ . map ( |t| self . lower_ty ( t, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding ) ) ) ;
1785
1759
let init = l. init . as_ref ( ) . map ( |e| self . lower_expr ( e) ) ;
1786
1760
let hir_id = self . lower_node_id ( l. id ) ;
1787
1761
self . lower_attrs ( hir_id, & l. attrs ) ;
@@ -2332,13 +2306,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2332
2306
) ) ,
2333
2307
_ => None ,
2334
2308
} ) ;
2335
- if let ImplTraitContext :: OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx {
2309
+ if let ImplTraitContext :: TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2310
+ itctx
2311
+ {
2336
2312
capturable_lifetimes. extend ( lt_def_names. clone ( ) ) ;
2337
2313
}
2338
2314
2339
2315
let res = this. lower_trait_ref ( & p. trait_ref , itctx. reborrow ( ) ) ;
2340
2316
2341
- if let ImplTraitContext :: OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx {
2317
+ if let ImplTraitContext :: TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2318
+ itctx
2319
+ {
2342
2320
for param in lt_def_names {
2343
2321
capturable_lifetimes. remove ( & param) ;
2344
2322
}
0 commit comments