Box the biggest ast::ItemKind variants
This commit is contained in:
@@ -2655,6 +2655,35 @@ impl Default for FnHeader {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct TraitKind(
|
||||
pub IsAuto,
|
||||
pub Unsafe,
|
||||
pub Generics,
|
||||
pub GenericBounds,
|
||||
pub Vec<P<AssocItem>>,
|
||||
);
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct TyAliasKind(pub Defaultness, pub Generics, pub GenericBounds, pub Option<P<Ty>>);
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct ImplKind {
|
||||
pub unsafety: Unsafe,
|
||||
pub polarity: ImplPolarity,
|
||||
pub defaultness: Defaultness,
|
||||
pub constness: Const,
|
||||
pub generics: Generics,
|
||||
|
||||
/// The trait being implemented, if any.
|
||||
pub of_trait: Option<TraitRef>,
|
||||
|
||||
pub self_ty: P<Ty>,
|
||||
pub items: Vec<P<AssocItem>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct FnKind(pub Defaultness, pub FnSig, pub Generics, pub Option<P<Block>>);
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum ItemKind {
|
||||
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
|
||||
@@ -2676,7 +2705,7 @@ pub enum ItemKind {
|
||||
/// A function declaration (`fn`).
|
||||
///
|
||||
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
|
||||
Fn(Defaultness, FnSig, Generics, Option<P<Block>>),
|
||||
Fn(Box<FnKind>),
|
||||
/// A module declaration (`mod`).
|
||||
///
|
||||
/// E.g., `mod foo;` or `mod foo { .. }`.
|
||||
@@ -2690,7 +2719,7 @@ pub enum ItemKind {
|
||||
/// A type alias (`type`).
|
||||
///
|
||||
/// E.g., `type Foo = Bar<u8>;`.
|
||||
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
|
||||
TyAlias(Box<TyAliasKind>),
|
||||
/// An enum definition (`enum`).
|
||||
///
|
||||
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
|
||||
@@ -2706,7 +2735,7 @@ pub enum ItemKind {
|
||||
/// A trait declaration (`trait`).
|
||||
///
|
||||
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
|
||||
Trait(IsAuto, Unsafe, Generics, GenericBounds, Vec<P<AssocItem>>),
|
||||
Trait(Box<TraitKind>),
|
||||
/// Trait alias
|
||||
///
|
||||
/// E.g., `trait Foo = Bar + Quux;`.
|
||||
@@ -2714,19 +2743,7 @@ pub enum ItemKind {
|
||||
/// An implementation.
|
||||
///
|
||||
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
|
||||
Impl {
|
||||
unsafety: Unsafe,
|
||||
polarity: ImplPolarity,
|
||||
defaultness: Defaultness,
|
||||
constness: Const,
|
||||
generics: Generics,
|
||||
|
||||
/// The trait being implemented, if any.
|
||||
of_trait: Option<TraitRef>,
|
||||
|
||||
self_ty: P<Ty>,
|
||||
items: Vec<P<AssocItem>>,
|
||||
},
|
||||
Impl(Box<ImplKind>),
|
||||
/// A macro invocation.
|
||||
///
|
||||
/// E.g., `foo!(..)`.
|
||||
@@ -2770,14 +2787,14 @@ impl ItemKind {
|
||||
|
||||
pub fn generics(&self) -> Option<&Generics> {
|
||||
match self {
|
||||
Self::Fn(_, _, generics, _)
|
||||
| Self::TyAlias(_, generics, ..)
|
||||
Self::Fn(box FnKind(_, _, generics, _))
|
||||
| Self::TyAlias(box TyAliasKind(_, generics, ..))
|
||||
| Self::Enum(_, generics)
|
||||
| Self::Struct(_, generics)
|
||||
| Self::Union(_, generics)
|
||||
| Self::Trait(_, _, generics, ..)
|
||||
| Self::Trait(box TraitKind(_, _, generics, ..))
|
||||
| Self::TraitAlias(generics, _)
|
||||
| Self::Impl { generics, .. } => Some(generics),
|
||||
| Self::Impl(box ImplKind { generics, .. }) => Some(generics),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -2800,9 +2817,9 @@ pub enum AssocItemKind {
|
||||
/// If `def` is parsed, then the constant is provided, and otherwise required.
|
||||
Const(Defaultness, P<Ty>, Option<P<Expr>>),
|
||||
/// An associated function.
|
||||
Fn(Defaultness, FnSig, Generics, Option<P<Block>>),
|
||||
Fn(Box<FnKind>),
|
||||
/// An associated type.
|
||||
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
|
||||
TyAlias(Box<TyAliasKind>),
|
||||
/// A macro expanding to associated items.
|
||||
MacCall(MacCall),
|
||||
}
|
||||
@@ -2810,7 +2827,9 @@ pub enum AssocItemKind {
|
||||
impl AssocItemKind {
|
||||
pub fn defaultness(&self) -> Defaultness {
|
||||
match *self {
|
||||
Self::Const(def, ..) | Self::Fn(def, ..) | Self::TyAlias(def, ..) => def,
|
||||
Self::Const(def, ..)
|
||||
| Self::Fn(box FnKind(def, ..))
|
||||
| Self::TyAlias(box TyAliasKind(def, ..)) => def,
|
||||
Self::MacCall(..) => Defaultness::Final,
|
||||
}
|
||||
}
|
||||
@@ -2820,8 +2839,8 @@ impl From<AssocItemKind> for ItemKind {
|
||||
fn from(assoc_item_kind: AssocItemKind) -> ItemKind {
|
||||
match assoc_item_kind {
|
||||
AssocItemKind::Const(a, b, c) => ItemKind::Const(a, b, c),
|
||||
AssocItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
|
||||
AssocItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
|
||||
AssocItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
|
||||
AssocItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
|
||||
AssocItemKind::MacCall(a) => ItemKind::MacCall(a),
|
||||
}
|
||||
}
|
||||
@@ -2833,8 +2852,8 @@ impl TryFrom<ItemKind> for AssocItemKind {
|
||||
fn try_from(item_kind: ItemKind) -> Result<AssocItemKind, ItemKind> {
|
||||
Ok(match item_kind {
|
||||
ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c),
|
||||
ItemKind::Fn(a, b, c, d) => AssocItemKind::Fn(a, b, c, d),
|
||||
ItemKind::TyAlias(a, b, c, d) => AssocItemKind::TyAlias(a, b, c, d),
|
||||
ItemKind::Fn(fn_kind) => AssocItemKind::Fn(fn_kind),
|
||||
ItemKind::TyAlias(ty_alias_kind) => AssocItemKind::TyAlias(ty_alias_kind),
|
||||
ItemKind::MacCall(a) => AssocItemKind::MacCall(a),
|
||||
_ => return Err(item_kind),
|
||||
})
|
||||
@@ -2846,10 +2865,10 @@ impl TryFrom<ItemKind> for AssocItemKind {
|
||||
pub enum ForeignItemKind {
|
||||
/// A foreign static item (`static FOO: u8`).
|
||||
Static(P<Ty>, Mutability, Option<P<Expr>>),
|
||||
/// A foreign function.
|
||||
Fn(Defaultness, FnSig, Generics, Option<P<Block>>),
|
||||
/// A foreign type.
|
||||
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
|
||||
/// An foreign function.
|
||||
Fn(Box<FnKind>),
|
||||
/// An foreign type.
|
||||
TyAlias(Box<TyAliasKind>),
|
||||
/// A macro expanding to foreign items.
|
||||
MacCall(MacCall),
|
||||
}
|
||||
@@ -2858,8 +2877,8 @@ impl From<ForeignItemKind> for ItemKind {
|
||||
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
|
||||
match foreign_item_kind {
|
||||
ForeignItemKind::Static(a, b, c) => ItemKind::Static(a, b, c),
|
||||
ForeignItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
|
||||
ForeignItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
|
||||
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
|
||||
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
|
||||
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
|
||||
}
|
||||
}
|
||||
@@ -2871,8 +2890,8 @@ impl TryFrom<ItemKind> for ForeignItemKind {
|
||||
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
|
||||
Ok(match item_kind {
|
||||
ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
|
||||
ItemKind::Fn(a, b, c, d) => ForeignItemKind::Fn(a, b, c, d),
|
||||
ItemKind::TyAlias(a, b, c, d) => ForeignItemKind::TyAlias(a, b, c, d),
|
||||
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
|
||||
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
|
||||
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
|
||||
_ => return Err(item_kind),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user