|
1 | 1 | use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
|
2 |
| -use super::{ImplTraitContext, ImplTraitPosition, ImplTraitTypeIdVisitor}; |
| 2 | +use super::{ImplTraitContext, ImplTraitPosition}; |
3 | 3 | use crate::Arena;
|
4 | 4 |
|
5 | 5 | use rustc_ast::ast::*;
|
6 | 6 | use rustc_ast::attr;
|
7 | 7 | use rustc_ast::node_id::NodeMap;
|
8 | 8 | use rustc_ast::ptr::P;
|
9 | 9 | use rustc_ast::visit::{self, AssocCtxt, Visitor};
|
| 10 | +use rustc_data_structures::fx::FxHashSet; |
10 | 11 | use rustc_errors::struct_span_err;
|
11 | 12 | use rustc_hir as hir;
|
12 | 13 | use rustc_hir::def::{DefKind, Res};
|
@@ -165,13 +166,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
165 | 166 | }
|
166 | 167 | ItemKind::MacroDef(..) => SmallVec::new(),
|
167 | 168 | ItemKind::Fn(..) | ItemKind::Impl { of_trait: None, .. } => smallvec![i.id],
|
168 |
| - ItemKind::Static(ref ty, ..) | ItemKind::Const(_, ref ty, ..) => { |
169 |
| - let mut ids = smallvec![i.id]; |
170 |
| - if self.sess.features_untracked().impl_trait_in_bindings { |
171 |
| - ImplTraitTypeIdVisitor { ids: &mut ids }.visit_ty(ty); |
172 |
| - } |
173 |
| - ids |
174 |
| - } |
175 | 169 | _ => smallvec![i.id],
|
176 | 170 | };
|
177 | 171 |
|
@@ -292,23 +286,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
292 | 286 | ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
|
293 | 287 | ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
|
294 | 288 | ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
|
295 |
| - ItemKind::TyAlias(_, ref gen, _, Some(ref ty)) => match ty.kind.opaque_top_hack() { |
296 |
| - None => { |
297 |
| - let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); |
298 |
| - let generics = self.lower_generics(gen, ImplTraitContext::disallowed()); |
299 |
| - hir::ItemKind::TyAlias(ty, generics) |
300 |
| - } |
301 |
| - Some(bounds) => { |
302 |
| - let ctx = || ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc); |
303 |
| - let ty = hir::OpaqueTy { |
304 |
| - generics: self.lower_generics(gen, ctx()), |
305 |
| - bounds: self.lower_param_bounds(bounds, ctx()), |
306 |
| - impl_trait_fn: None, |
307 |
| - origin: hir::OpaqueTyOrigin::TypeAlias, |
308 |
| - }; |
309 |
| - hir::ItemKind::OpaqueTy(ty) |
310 |
| - } |
311 |
| - }, |
| 289 | + ItemKind::TyAlias(_, ref gen, _, Some(ref ty)) => { |
| 290 | + // We lower |
| 291 | + // |
| 292 | + // type Foo = impl Trait |
| 293 | + // |
| 294 | + // to |
| 295 | + // |
| 296 | + // type Foo = Foo1 |
| 297 | + // opaque type Foo1: Trait |
| 298 | + let ty = self.lower_ty( |
| 299 | + ty, |
| 300 | + ImplTraitContext::OtherOpaqueTy { |
| 301 | + capturable_lifetimes: &mut FxHashSet::default(), |
| 302 | + origin: hir::OpaqueTyOrigin::Misc, |
| 303 | + }, |
| 304 | + ); |
| 305 | + let generics = self.lower_generics(gen, ImplTraitContext::disallowed()); |
| 306 | + hir::ItemKind::TyAlias(ty, generics) |
| 307 | + } |
312 | 308 | ItemKind::TyAlias(_, ref generics, _, None) => {
|
313 | 309 | let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err));
|
314 | 310 | let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
|
@@ -438,8 +434,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
438 | 434 | span: Span,
|
439 | 435 | body: Option<&Expr>,
|
440 | 436 | ) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
|
| 437 | + let mut capturable_lifetimes; |
441 | 438 | let itctx = if self.sess.features_untracked().impl_trait_in_bindings {
|
442 |
| - ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc) |
| 439 | + capturable_lifetimes = FxHashSet::default(); |
| 440 | + ImplTraitContext::OtherOpaqueTy { |
| 441 | + capturable_lifetimes: &mut capturable_lifetimes, |
| 442 | + origin: hir::OpaqueTyOrigin::Misc, |
| 443 | + } |
443 | 444 | } else {
|
444 | 445 | ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
|
445 | 446 | };
|
@@ -844,16 +845,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
844 | 845 | let ty = self.arena.alloc(self.ty(i.span, hir::TyKind::Err));
|
845 | 846 | hir::ImplItemKind::TyAlias(ty)
|
846 | 847 | }
|
847 |
| - Some(ty) => match ty.kind.opaque_top_hack() { |
848 |
| - None => { |
849 |
| - let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); |
850 |
| - hir::ImplItemKind::TyAlias(ty) |
851 |
| - } |
852 |
| - Some(bs) => { |
853 |
| - let bs = self.lower_param_bounds(bs, ImplTraitContext::disallowed()); |
854 |
| - hir::ImplItemKind::OpaqueTy(bs) |
855 |
| - } |
856 |
| - }, |
| 848 | + Some(ty) => { |
| 849 | + let ty = self.lower_ty( |
| 850 | + ty, |
| 851 | + ImplTraitContext::OtherOpaqueTy { |
| 852 | + capturable_lifetimes: &mut FxHashSet::default(), |
| 853 | + origin: hir::OpaqueTyOrigin::Misc, |
| 854 | + }, |
| 855 | + ); |
| 856 | + hir::ImplItemKind::TyAlias(ty) |
| 857 | + } |
857 | 858 | };
|
858 | 859 | (generics, kind)
|
859 | 860 | }
|
@@ -887,12 +888,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
887 | 888 | defaultness,
|
888 | 889 | kind: match &i.kind {
|
889 | 890 | AssocItemKind::Const(..) => hir::AssocItemKind::Const,
|
890 |
| - AssocItemKind::TyAlias(.., ty) => { |
891 |
| - match ty.as_deref().and_then(|ty| ty.kind.opaque_top_hack()) { |
892 |
| - None => hir::AssocItemKind::Type, |
893 |
| - Some(_) => hir::AssocItemKind::OpaqueTy, |
894 |
| - } |
895 |
| - } |
| 891 | + AssocItemKind::TyAlias(..) => hir::AssocItemKind::Type, |
896 | 892 | AssocItemKind::Fn(_, sig, ..) => {
|
897 | 893 | hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }
|
898 | 894 | }
|
|
0 commit comments