rm ItemKind::OpaqueTy
This introduce an additional collection of opaques on HIR, as they can no longer be listed using the free item list.
This commit is contained in:
parent
4ec7839afa
commit
d6f247f3d5
45 changed files with 306 additions and 368 deletions
|
@ -2749,6 +2749,8 @@ pub struct BareFnTy<'hir> {
|
|||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct OpaqueTy<'hir> {
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
pub generics: &'hir Generics<'hir>,
|
||||
pub bounds: GenericBounds<'hir>,
|
||||
pub origin: OpaqueTyOrigin,
|
||||
|
@ -2762,6 +2764,7 @@ pub struct OpaqueTy<'hir> {
|
|||
/// This mapping associated a captured lifetime (first parameter) with the new
|
||||
/// early-bound lifetime that was generated for the opaque.
|
||||
pub lifetime_mapping: &'hir [(&'hir Lifetime, LocalDefId)],
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
|
@ -2868,7 +2871,7 @@ pub enum TyKind<'hir> {
|
|||
/// possibly parameters) that are actually bound on the `impl Trait`.
|
||||
///
|
||||
/// The last parameter specifies whether this opaque appears in a trait definition.
|
||||
OpaqueDef(ItemId, &'hir [GenericArg<'hir>]),
|
||||
OpaqueDef(&'hir OpaqueTy<'hir>, &'hir [GenericArg<'hir>]),
|
||||
/// A trait object type `Bound1 + Bound2 + Bound3`
|
||||
/// where `Bound` is a trait or a lifetime.
|
||||
TraitObject(
|
||||
|
@ -3337,8 +3340,6 @@ impl<'hir> Item<'hir> {
|
|||
expect_ty_alias, (&'hir Ty<'hir>, &'hir Generics<'hir>),
|
||||
ItemKind::TyAlias(ty, generics), (ty, generics);
|
||||
|
||||
expect_opaque_ty, &OpaqueTy<'hir>, ItemKind::OpaqueTy(ty), ty;
|
||||
|
||||
expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, generics), (def, generics);
|
||||
|
||||
expect_struct, (&VariantData<'hir>, &'hir Generics<'hir>),
|
||||
|
@ -3451,8 +3452,6 @@ pub enum ItemKind<'hir> {
|
|||
GlobalAsm(&'hir InlineAsm<'hir>),
|
||||
/// A type alias, e.g., `type Foo = Bar<u8>`.
|
||||
TyAlias(&'hir Ty<'hir>, &'hir Generics<'hir>),
|
||||
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`.
|
||||
OpaqueTy(&'hir OpaqueTy<'hir>),
|
||||
/// An enum definition, e.g., `enum Foo<A, B> {C<A>, D<B>}`.
|
||||
Enum(EnumDef<'hir>, &'hir Generics<'hir>),
|
||||
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
|
||||
|
@ -3496,7 +3495,6 @@ impl ItemKind<'_> {
|
|||
ItemKind::Fn(_, ref generics, _)
|
||||
| ItemKind::TyAlias(_, ref generics)
|
||||
| ItemKind::Const(_, ref generics, _)
|
||||
| ItemKind::OpaqueTy(OpaqueTy { ref generics, .. })
|
||||
| ItemKind::Enum(_, ref generics)
|
||||
| ItemKind::Struct(_, ref generics)
|
||||
| ItemKind::Union(_, ref generics)
|
||||
|
@ -3519,7 +3517,6 @@ impl ItemKind<'_> {
|
|||
ItemKind::ForeignMod { .. } => "extern block",
|
||||
ItemKind::GlobalAsm(..) => "global asm item",
|
||||
ItemKind::TyAlias(..) => "type alias",
|
||||
ItemKind::OpaqueTy(..) => "opaque type",
|
||||
ItemKind::Enum(..) => "enum",
|
||||
ItemKind::Struct(..) => "struct",
|
||||
ItemKind::Union(..) => "union",
|
||||
|
@ -3806,6 +3803,7 @@ pub enum Node<'hir> {
|
|||
Ty(&'hir Ty<'hir>),
|
||||
AssocItemConstraint(&'hir AssocItemConstraint<'hir>),
|
||||
TraitRef(&'hir TraitRef<'hir>),
|
||||
OpaqueTy(&'hir OpaqueTy<'hir>),
|
||||
Pat(&'hir Pat<'hir>),
|
||||
PatField(&'hir PatField<'hir>),
|
||||
Arm(&'hir Arm<'hir>),
|
||||
|
@ -3871,6 +3869,7 @@ impl<'hir> Node<'hir> {
|
|||
| Node::Crate(..)
|
||||
| Node::Ty(..)
|
||||
| Node::TraitRef(..)
|
||||
| Node::OpaqueTy(..)
|
||||
| Node::Infer(..)
|
||||
| Node::WhereBoundPredicate(..)
|
||||
| Node::ArrayLenInfer(..)
|
||||
|
@ -3996,6 +3995,7 @@ impl<'hir> Node<'hir> {
|
|||
| Node::TraitItem(TraitItem { generics, .. })
|
||||
| Node::ImplItem(ImplItem { generics, .. }) => Some(generics),
|
||||
Node::Item(item) => item.kind.generics(),
|
||||
Node::OpaqueTy(opaque) => Some(opaque.generics),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -4055,6 +4055,7 @@ impl<'hir> Node<'hir> {
|
|||
expect_ty, &'hir Ty<'hir>, Node::Ty(n), n;
|
||||
expect_assoc_item_constraint, &'hir AssocItemConstraint<'hir>, Node::AssocItemConstraint(n), n;
|
||||
expect_trait_ref, &'hir TraitRef<'hir>, Node::TraitRef(n), n;
|
||||
expect_opaque_ty, &'hir OpaqueTy<'hir>, Node::OpaqueTy(n), n;
|
||||
expect_pat, &'hir Pat<'hir>, Node::Pat(n), n;
|
||||
expect_pat_field, &'hir PatField<'hir>, Node::PatField(n), n;
|
||||
expect_arm, &'hir Arm<'hir>, Node::Arm(n), n;
|
||||
|
|
|
@ -111,6 +111,7 @@ impl<'a> FnKind<'a> {
|
|||
pub trait Map<'hir> {
|
||||
/// Retrieves the `Node` corresponding to `id`.
|
||||
fn hir_node(&self, hir_id: HirId) -> Node<'hir>;
|
||||
fn hir_node_by_def_id(&self, def_id: LocalDefId) -> Node<'hir>;
|
||||
fn body(&self, id: BodyId) -> &'hir Body<'hir>;
|
||||
fn item(&self, id: ItemId) -> &'hir Item<'hir>;
|
||||
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>;
|
||||
|
@ -123,6 +124,9 @@ impl<'hir> Map<'hir> for ! {
|
|||
fn hir_node(&self, _: HirId) -> Node<'hir> {
|
||||
*self;
|
||||
}
|
||||
fn hir_node_by_def_id(&self, _: LocalDefId) -> Node<'hir> {
|
||||
*self;
|
||||
}
|
||||
fn body(&self, _: BodyId) -> &'hir Body<'hir> {
|
||||
*self;
|
||||
}
|
||||
|
@ -423,6 +427,9 @@ pub trait Visitor<'v>: Sized {
|
|||
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>) -> Self::Result {
|
||||
walk_poly_trait_ref(self, t)
|
||||
}
|
||||
fn visit_opaque_ty(&mut self, opaque: &'v OpaqueTy<'v>) -> Self::Result {
|
||||
walk_opaque_ty(self, opaque)
|
||||
}
|
||||
fn visit_variant_data(&mut self, s: &'v VariantData<'v>) -> Self::Result {
|
||||
walk_struct_def(self, s)
|
||||
}
|
||||
|
@ -536,11 +543,6 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
|||
try_visit!(visitor.visit_ty(ty));
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
}
|
||||
ItemKind::OpaqueTy(&OpaqueTy { generics, bounds, .. }) => {
|
||||
try_visit!(visitor.visit_id(item.hir_id()));
|
||||
try_visit!(walk_generics(visitor, generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
ItemKind::Enum(ref enum_definition, ref generics) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
|
||||
|
@ -894,8 +896,8 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Resul
|
|||
TyKind::Path(ref qpath) => {
|
||||
try_visit!(visitor.visit_qpath(qpath, typ.hir_id, typ.span));
|
||||
}
|
||||
TyKind::OpaqueDef(item_id, lifetimes) => {
|
||||
try_visit!(visitor.visit_nested_item(item_id));
|
||||
TyKind::OpaqueDef(opaque, lifetimes) => {
|
||||
try_visit!(visitor.visit_opaque_ty(opaque));
|
||||
walk_list!(visitor, visit_generic_arg, lifetimes);
|
||||
}
|
||||
TyKind::Array(ref ty, ref length) => {
|
||||
|
@ -1185,6 +1187,15 @@ pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
|
|||
visitor.visit_trait_ref(&trait_ref.trait_ref)
|
||||
}
|
||||
|
||||
pub fn walk_opaque_ty<'v, V: Visitor<'v>>(visitor: &mut V, opaque: &'v OpaqueTy<'v>) -> V::Result {
|
||||
let &OpaqueTy { hir_id, def_id: _, generics, bounds, origin: _, lifetime_mapping: _, span: _ } =
|
||||
opaque;
|
||||
try_visit!(visitor.visit_id(hir_id));
|
||||
try_visit!(walk_generics(visitor, generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
V::Result::output()
|
||||
}
|
||||
|
||||
pub fn walk_struct_def<'v, V: Visitor<'v>>(
|
||||
visitor: &mut V,
|
||||
struct_definition: &'v VariantData<'v>,
|
||||
|
|
|
@ -34,7 +34,6 @@ pub enum Target {
|
|||
ForeignMod,
|
||||
GlobalAsm,
|
||||
TyAlias,
|
||||
OpaqueTy,
|
||||
Enum,
|
||||
Variant,
|
||||
Struct,
|
||||
|
@ -79,7 +78,6 @@ impl Target {
|
|||
| Target::ForeignMod
|
||||
| Target::GlobalAsm
|
||||
| Target::TyAlias
|
||||
| Target::OpaqueTy
|
||||
| Target::Enum
|
||||
| Target::Variant
|
||||
| Target::Struct
|
||||
|
@ -114,7 +112,6 @@ impl Target {
|
|||
ItemKind::ForeignMod { .. } => Target::ForeignMod,
|
||||
ItemKind::GlobalAsm(..) => Target::GlobalAsm,
|
||||
ItemKind::TyAlias(..) => Target::TyAlias,
|
||||
ItemKind::OpaqueTy(..) => Target::OpaqueTy,
|
||||
ItemKind::Enum(..) => Target::Enum,
|
||||
ItemKind::Struct(..) => Target::Struct,
|
||||
ItemKind::Union(..) => Target::Union,
|
||||
|
@ -137,7 +134,6 @@ impl Target {
|
|||
DefKind::ForeignMod => Target::ForeignMod,
|
||||
DefKind::GlobalAsm => Target::GlobalAsm,
|
||||
DefKind::TyAlias => Target::TyAlias,
|
||||
DefKind::OpaqueTy => Target::OpaqueTy,
|
||||
DefKind::Enum => Target::Enum,
|
||||
DefKind::Struct => Target::Struct,
|
||||
DefKind::Union => Target::Union,
|
||||
|
@ -191,7 +187,6 @@ impl Target {
|
|||
Target::ForeignMod => "foreign module",
|
||||
Target::GlobalAsm => "global asm",
|
||||
Target::TyAlias => "type alias",
|
||||
Target::OpaqueTy => "opaque type",
|
||||
Target::Enum => "enum",
|
||||
Target::Variant => "enum variant",
|
||||
Target::Struct => "struct",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue