1
Fork 0

Unify {Impl,Trait}Item as AssocItem.

This commit is contained in:
Mazdak Farrokhzad 2019-12-01 10:46:06 +01:00
parent 39073767a4
commit 92a372b020
2 changed files with 24 additions and 17 deletions

View file

@ -1603,23 +1603,16 @@ pub struct FnSig {
pub decl: P<FnDecl>, pub decl: P<FnDecl>,
} }
pub type TraitItem = ImplItem<TraitItemKind>; // FIXME(Centril): Remove all of these.
pub type TraitItem = AssocItem<AssocItemKind>;
pub type TraitItemKind = AssocItemKind;
pub type ImplItem = AssocItem<AssocItemKind>;
pub type ImplItemKind = AssocItemKind;
/// Represents the kind of an item declaration within a trait declaration, /// Represents associated items.
/// possibly including a default implementation. A trait item is /// These include items in `impl` and `trait` definitions.
/// either required (meaning it doesn't have an implementation, just a
/// signature) or provided (meaning it has a default implementation).
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum TraitItemKind { pub struct AssocItem<K = ImplItemKind> {
Const(P<Ty>, Option<P<Expr>>),
Method(FnSig, Option<P<Block>>),
TyAlias(GenericBounds, Option<P<Ty>>),
Macro(Mac),
}
/// Represents anything within an `impl` block.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct ImplItem<K = ImplItemKind> {
pub attrs: Vec<Attribute>, pub attrs: Vec<Attribute>,
pub id: NodeId, pub id: NodeId,
pub span: Span, pub span: Span,
@ -1634,11 +1627,25 @@ pub struct ImplItem<K = ImplItemKind> {
} }
/// Represents various kinds of content within an `impl`. /// Represents various kinds of content within an `impl`.
///
/// The term "provided" in the variants below refers to the item having a default
/// definition / body. Meanwhile, a "required" item lacks a definition / body.
/// In an implementation, all items must be provided.
/// The `Option`s below denote the bodies, where `Some(_)`
/// means "provided" and conversely `None` means "required".
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum ImplItemKind { pub enum AssocItemKind {
/// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`.
/// If `def` is parsed, then the associated constant is provided, and otherwise required.
Const(P<Ty>, Option<P<Expr>>), Const(P<Ty>, Option<P<Expr>>),
/// An associated function.
Method(FnSig, Option<P<Block>>), Method(FnSig, Option<P<Block>>),
/// An associated type.
TyAlias(GenericBounds, Option<P<Ty>>), TyAlias(GenericBounds, Option<P<Ty>>),
/// A macro expanding to an associated item.
Macro(Mac), Macro(Mac),
} }

View file

@ -749,6 +749,6 @@ macro_rules! derive_has_attrs {
} }
derive_has_attrs! { derive_has_attrs! {
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm, Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::AssocItem, ast::Arm,
ast::Field, ast::FieldPat, ast::Variant, ast::Param ast::Field, ast::FieldPat, ast::Variant, ast::Param
} }