diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 292643d6d7510..d8c4fdbb46ad0 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -343,7 +343,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // opaque type Foo1: Trait let ty = self.lower_ty( ty, - ImplTraitContext::OtherOpaqueTy { + ImplTraitContext::TypeAliasesOpaqueTy { capturable_lifetimes: &mut FxHashSet::default(), origin: hir::OpaqueTyOrigin::TyAlias, }, @@ -487,7 +487,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let mut capturable_lifetimes; let itctx = if self.sess.features_untracked().impl_trait_in_bindings { capturable_lifetimes = FxHashSet::default(); - ImplTraitContext::OtherOpaqueTy { + ImplTraitContext::TypeAliasesOpaqueTy { capturable_lifetimes: &mut capturable_lifetimes, origin: hir::OpaqueTyOrigin::Misc, } @@ -926,7 +926,7 @@ impl<'hir> LoweringContext<'_, 'hir> { Some(ty) => { let ty = self.lower_ty( ty, - ImplTraitContext::OtherOpaqueTy { + ImplTraitContext::TypeAliasesOpaqueTy { capturable_lifetimes: &mut FxHashSet::default(), origin: hir::OpaqueTyOrigin::TyAlias, }, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 0306196f65a0e..d5284c1a43d38 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -265,7 +265,7 @@ enum ImplTraitContext<'b, 'a> { origin: hir::OpaqueTyOrigin, }, /// Impl trait in type aliases. - OtherOpaqueTy { + TypeAliasesOpaqueTy { /// Set of lifetimes that this opaque type can capture, if it uses /// them. This includes lifetimes bound since we entered this context. /// For example: @@ -310,8 +310,8 @@ impl<'a> ImplTraitContext<'_, 'a> { ReturnPositionOpaqueTy { fn_def_id, origin } => { ReturnPositionOpaqueTy { fn_def_id: *fn_def_id, origin: *origin } } - OtherOpaqueTy { capturable_lifetimes, origin } => { - OtherOpaqueTy { capturable_lifetimes, origin: *origin } + TypeAliasesOpaqueTy { capturable_lifetimes, origin } => { + TypeAliasesOpaqueTy { capturable_lifetimes, origin: *origin } } Disallowed(pos) => Disallowed(*pos), } @@ -1126,7 +1126,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // // fn foo() -> impl Iterator ImplTraitContext::ReturnPositionOpaqueTy { .. } - | ImplTraitContext::OtherOpaqueTy { .. } => (true, itctx), + | ImplTraitContext::TypeAliasesOpaqueTy { .. } => (true, itctx), // We are in the argument position, but within a dyn type: // @@ -1150,7 +1150,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { capturable_lifetimes = FxHashSet::default(); ( true, - ImplTraitContext::OtherOpaqueTy { + ImplTraitContext::TypeAliasesOpaqueTy { capturable_lifetimes: &mut capturable_lifetimes, origin: hir::OpaqueTyOrigin::Misc, }, @@ -1416,11 +1416,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { None, |this| this.lower_param_bounds(bounds, itctx), ), - ImplTraitContext::OtherOpaqueTy { ref capturable_lifetimes, origin } => { + ImplTraitContext::TypeAliasesOpaqueTy { ref capturable_lifetimes, origin } => { // Reset capturable lifetimes, any nested impl trait // types will inherit lifetimes from this opaque type, // so don't need to capture them again. - let nested_itctx = ImplTraitContext::OtherOpaqueTy { + let nested_itctx = ImplTraitContext::TypeAliasesOpaqueTy { capturable_lifetimes: &mut FxHashSet::default(), origin, }; @@ -2321,13 +2321,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { )), _ => None, }); - if let ImplTraitContext::OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx { + if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } = + itctx + { capturable_lifetimes.extend(lt_def_names.clone()); } let res = this.lower_trait_ref(&p.trait_ref, itctx.reborrow()); - if let ImplTraitContext::OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx { + if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } = + itctx + { for param in lt_def_names { capturable_lifetimes.remove(¶m); }