@@ -264,8 +264,8 @@ enum ImplTraitContext<'b, 'a> {
264264 /// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
265265 origin : hir:: OpaqueTyOrigin ,
266266 } ,
267- /// Impl trait in type aliases, consts and statics .
268- OtherOpaqueTy {
267+ /// Impl trait in type aliases.
268+ TypeAliasesOpaqueTy {
269269 /// Set of lifetimes that this opaque type can capture, if it uses
270270 /// them. This includes lifetimes bound since we entered this context.
271271 /// For example:
@@ -280,8 +280,6 @@ enum ImplTraitContext<'b, 'a> {
280280 // FIXME(impl_trait): but `required_region_bounds` will ICE later
281281 // anyway.
282282 capturable_lifetimes : & ' b mut FxHashSet < hir:: LifetimeName > ,
283- /// Origin: Either OpaqueTyOrigin::Misc or OpaqueTyOrigin::Binding,
284- origin : hir:: OpaqueTyOrigin ,
285283 } ,
286284 /// `impl Trait` is not accepted in this position.
287285 Disallowed ( ImplTraitPosition ) ,
@@ -310,8 +308,8 @@ impl<'a> ImplTraitContext<'_, 'a> {
310308 ReturnPositionOpaqueTy { fn_def_id, origin } => {
311309 ReturnPositionOpaqueTy { fn_def_id : * fn_def_id, origin : * origin }
312310 }
313- OtherOpaqueTy { capturable_lifetimes, origin } => {
314- OtherOpaqueTy { capturable_lifetimes, origin : * origin }
311+ TypeAliasesOpaqueTy { capturable_lifetimes } => {
312+ TypeAliasesOpaqueTy { capturable_lifetimes }
315313 }
316314 Disallowed ( pos) => Disallowed ( * pos) ,
317315 }
@@ -1126,7 +1124,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11261124 //
11271125 // fn foo() -> impl Iterator<Item = impl Debug>
11281126 ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1129- | ImplTraitContext :: OtherOpaqueTy { .. } => ( true , itctx) ,
1127+ | ImplTraitContext :: TypeAliasesOpaqueTy { .. } => ( true , itctx) ,
11301128
11311129 // We are in the argument position, but within a dyn type:
11321130 //
@@ -1150,9 +1148,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11501148 capturable_lifetimes = FxHashSet :: default ( ) ;
11511149 (
11521150 true ,
1153- ImplTraitContext :: OtherOpaqueTy {
1151+ ImplTraitContext :: TypeAliasesOpaqueTy {
11541152 capturable_lifetimes : & mut capturable_lifetimes,
1155- origin : hir:: OpaqueTyOrigin :: Misc ,
11561153 } ,
11571154 )
11581155 }
@@ -1416,18 +1413,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14161413 None ,
14171414 |this| this. lower_param_bounds ( bounds, itctx) ,
14181415 ) ,
1419- ImplTraitContext :: OtherOpaqueTy { ref capturable_lifetimes, origin } => {
1416+ ImplTraitContext :: TypeAliasesOpaqueTy { ref capturable_lifetimes } => {
14201417 // Reset capturable lifetimes, any nested impl trait
14211418 // types will inherit lifetimes from this opaque type,
14221419 // so don't need to capture them again.
1423- let nested_itctx = ImplTraitContext :: OtherOpaqueTy {
1420+ let nested_itctx = ImplTraitContext :: TypeAliasesOpaqueTy {
14241421 capturable_lifetimes : & mut FxHashSet :: default ( ) ,
1425- origin,
14261422 } ;
14271423 self . lower_opaque_impl_trait (
14281424 span,
14291425 None ,
1430- origin ,
1426+ hir :: OpaqueTyOrigin :: TyAlias ,
14311427 def_node_id,
14321428 Some ( capturable_lifetimes) ,
14331429 |this| this. lower_param_bounds ( bounds, nested_itctx) ,
@@ -1464,25 +1460,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14641460 } ) ,
14651461 ) )
14661462 }
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 ( _) => {
14731464 let mut err = struct_span_err ! (
14741465 self . sess,
14751466 t. span,
14761467 E0562 ,
14771468 "`impl Trait` not allowed outside of {}" ,
1478- allowed_in ,
1469+ "function and method return types" ,
14791470 ) ;
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- }
14861471 err. emit ( ) ;
14871472 hir:: TyKind :: Err
14881473 }
@@ -1767,21 +1752,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17671752 }
17681753
17691754 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 ) ) ) ;
17851759 let init = l. init . as_ref ( ) . map ( |e| self . lower_expr ( e) ) ;
17861760 let hir_id = self . lower_node_id ( l. id ) ;
17871761 self . lower_attrs ( hir_id, & l. attrs ) ;
@@ -2332,13 +2306,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23322306 ) ) ,
23332307 _ => None ,
23342308 } ) ;
2335- if let ImplTraitContext :: OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx {
2309+ if let ImplTraitContext :: TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2310+ itctx
2311+ {
23362312 capturable_lifetimes. extend ( lt_def_names. clone ( ) ) ;
23372313 }
23382314
23392315 let res = this. lower_trait_ref ( & p. trait_ref , itctx. reborrow ( ) ) ;
23402316
2341- if let ImplTraitContext :: OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx {
2317+ if let ImplTraitContext :: TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2318+ itctx
2319+ {
23422320 for param in lt_def_names {
23432321 capturable_lifetimes. remove ( & param) ;
23442322 }
0 commit comments