Skip to content

Commit 92a372b

Browse files
committed
Unify {Impl,Trait}Item as AssocItem.
1 parent 3907376 commit 92a372b

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

src/libsyntax/ast.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,23 +1603,16 @@ pub struct FnSig {
16031603
pub decl: P<FnDecl>,
16041604
}
16051605

1606-
pub type TraitItem = ImplItem<TraitItemKind>;
1606+
// FIXME(Centril): Remove all of these.
1607+
pub type TraitItem = AssocItem<AssocItemKind>;
1608+
pub type TraitItemKind = AssocItemKind;
1609+
pub type ImplItem = AssocItem<AssocItemKind>;
1610+
pub type ImplItemKind = AssocItemKind;
16071611

1608-
/// Represents the kind of an item declaration within a trait declaration,
1609-
/// possibly including a default implementation. A trait item is
1610-
/// either required (meaning it doesn't have an implementation, just a
1611-
/// signature) or provided (meaning it has a default implementation).
1612+
/// Represents associated items.
1613+
/// These include items in `impl` and `trait` definitions.
16121614
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1613-
pub enum TraitItemKind {
1614-
Const(P<Ty>, Option<P<Expr>>),
1615-
Method(FnSig, Option<P<Block>>),
1616-
TyAlias(GenericBounds, Option<P<Ty>>),
1617-
Macro(Mac),
1618-
}
1619-
1620-
/// Represents anything within an `impl` block.
1621-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1622-
pub struct ImplItem<K = ImplItemKind> {
1615+
pub struct AssocItem<K = ImplItemKind> {
16231616
pub attrs: Vec<Attribute>,
16241617
pub id: NodeId,
16251618
pub span: Span,
@@ -1634,11 +1627,25 @@ pub struct ImplItem<K = ImplItemKind> {
16341627
}
16351628

16361629
/// Represents various kinds of content within an `impl`.
1637-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1638-
pub enum ImplItemKind {
1630+
///
1631+
/// The term "provided" in the variants below refers to the item having a default
1632+
/// definition / body. Meanwhile, a "required" item lacks a definition / body.
1633+
/// In an implementation, all items must be provided.
1634+
/// The `Option`s below denote the bodies, where `Some(_)`
1635+
/// means "provided" and conversely `None` means "required".
1636+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1637+
pub enum AssocItemKind {
1638+
/// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`.
1639+
/// If `def` is parsed, then the associated constant is provided, and otherwise required.
16391640
Const(P<Ty>, Option<P<Expr>>),
1641+
1642+
/// An associated function.
16401643
Method(FnSig, Option<P<Block>>),
1644+
1645+
/// An associated type.
16411646
TyAlias(GenericBounds, Option<P<Ty>>),
1647+
1648+
/// A macro expanding to an associated item.
16421649
Macro(Mac),
16431650
}
16441651

src/libsyntax/attr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,6 @@ macro_rules! derive_has_attrs {
749749
}
750750

751751
derive_has_attrs! {
752-
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm,
752+
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::AssocItem, ast::Arm,
753753
ast::Field, ast::FieldPat, ast::Variant, ast::Param
754754
}

0 commit comments

Comments
 (0)