ast: Fix naming conventions in AST structures
TraitKind -> Trait TyAliasKind -> TyAlias ImplKind -> Impl FnKind -> Fn All `*Kind`s in AST are supposed to be enums. Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order. Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
This commit is contained in:
parent
90a273b785
commit
2834f57c45
28 changed files with 429 additions and 292 deletions
|
@ -2645,34 +2645,42 @@ 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 struct Trait {
|
||||
pub unsafety: Unsafe,
|
||||
pub polarity: ImplPolarity,
|
||||
pub defaultness: Defaultness,
|
||||
pub constness: Const,
|
||||
pub is_auto: IsAuto,
|
||||
pub generics: Generics,
|
||||
pub bounds: GenericBounds,
|
||||
pub items: Vec<P<AssocItem>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct TyAlias {
|
||||
pub defaultness: Defaultness,
|
||||
pub generics: Generics,
|
||||
pub bounds: GenericBounds,
|
||||
pub ty: Option<P<Ty>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct Impl {
|
||||
pub defaultness: Defaultness,
|
||||
pub unsafety: Unsafe,
|
||||
pub generics: Generics,
|
||||
pub constness: Const,
|
||||
pub polarity: ImplPolarity,
|
||||
/// 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>>);
|
||||
pub struct Fn {
|
||||
pub defaultness: Defaultness,
|
||||
pub generics: Generics,
|
||||
pub sig: FnSig,
|
||||
pub body: Option<P<Block>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum ItemKind {
|
||||
|
@ -2695,7 +2703,7 @@ pub enum ItemKind {
|
|||
/// A function declaration (`fn`).
|
||||
///
|
||||
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
|
||||
Fn(Box<FnKind>),
|
||||
Fn(Box<Fn>),
|
||||
/// A module declaration (`mod`).
|
||||
///
|
||||
/// E.g., `mod foo;` or `mod foo { .. }`.
|
||||
|
@ -2711,7 +2719,7 @@ pub enum ItemKind {
|
|||
/// A type alias (`type`).
|
||||
///
|
||||
/// E.g., `type Foo = Bar<u8>;`.
|
||||
TyAlias(Box<TyAliasKind>),
|
||||
TyAlias(Box<TyAlias>),
|
||||
/// An enum definition (`enum`).
|
||||
///
|
||||
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
|
||||
|
@ -2727,7 +2735,7 @@ pub enum ItemKind {
|
|||
/// A trait declaration (`trait`).
|
||||
///
|
||||
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
|
||||
Trait(Box<TraitKind>),
|
||||
Trait(Box<Trait>),
|
||||
/// Trait alias
|
||||
///
|
||||
/// E.g., `trait Foo = Bar + Quux;`.
|
||||
|
@ -2735,7 +2743,7 @@ pub enum ItemKind {
|
|||
/// An implementation.
|
||||
///
|
||||
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
|
||||
Impl(Box<ImplKind>),
|
||||
Impl(Box<Impl>),
|
||||
/// A macro invocation.
|
||||
///
|
||||
/// E.g., `foo!(..)`.
|
||||
|
@ -2782,14 +2790,14 @@ impl ItemKind {
|
|||
|
||||
pub fn generics(&self) -> Option<&Generics> {
|
||||
match self {
|
||||
Self::Fn(box FnKind(_, _, generics, _))
|
||||
| Self::TyAlias(box TyAliasKind(_, generics, ..))
|
||||
Self::Fn(box Fn { generics, .. })
|
||||
| Self::TyAlias(box TyAlias { generics, .. })
|
||||
| Self::Enum(_, generics)
|
||||
| Self::Struct(_, generics)
|
||||
| Self::Union(_, generics)
|
||||
| Self::Trait(box TraitKind(_, _, generics, ..))
|
||||
| Self::Trait(box Trait { generics, .. })
|
||||
| Self::TraitAlias(generics, _)
|
||||
| Self::Impl(box ImplKind { generics, .. }) => Some(generics),
|
||||
| Self::Impl(box Impl { generics, .. }) => Some(generics),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -2812,9 +2820,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(Box<FnKind>),
|
||||
Fn(Box<Fn>),
|
||||
/// An associated type.
|
||||
TyAlias(Box<TyAliasKind>),
|
||||
TyAlias(Box<TyAlias>),
|
||||
/// A macro expanding to associated items.
|
||||
MacCall(MacCall),
|
||||
}
|
||||
|
@ -2825,9 +2833,9 @@ rustc_data_structures::static_assert_size!(AssocItemKind, 72);
|
|||
impl AssocItemKind {
|
||||
pub fn defaultness(&self) -> Defaultness {
|
||||
match *self {
|
||||
Self::Const(def, ..)
|
||||
| Self::Fn(box FnKind(def, ..))
|
||||
| Self::TyAlias(box TyAliasKind(def, ..)) => def,
|
||||
Self::Const(defaultness, ..)
|
||||
| Self::Fn(box Fn { defaultness, .. })
|
||||
| Self::TyAlias(box TyAlias { defaultness, .. }) => defaultness,
|
||||
Self::MacCall(..) => Defaultness::Final,
|
||||
}
|
||||
}
|
||||
|
@ -2864,9 +2872,9 @@ pub enum ForeignItemKind {
|
|||
/// A foreign static item (`static FOO: u8`).
|
||||
Static(P<Ty>, Mutability, Option<P<Expr>>),
|
||||
/// An foreign function.
|
||||
Fn(Box<FnKind>),
|
||||
Fn(Box<Fn>),
|
||||
/// An foreign type.
|
||||
TyAlias(Box<TyAliasKind>),
|
||||
TyAlias(Box<TyAlias>),
|
||||
/// A macro expanding to foreign items.
|
||||
MacCall(MacCall),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue