about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-01 10:46:06 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-12 17:54:48 +0100
commit92a372b0204a5f18286ff94648b98e4c0d6d27d2 (patch)
tree31c5d5ade0c4222d94d0ba8982988a0c8e473a01 /src/libsyntax
parent39073767a483d10f8b4b2ac2f32bc9573d9dabbf (diff)
downloadrust-92a372b0204a5f18286ff94648b98e4c0d6d27d2.tar.gz
rust-92a372b0204a5f18286ff94648b98e4c0d6d27d2.zip
Unify `{Impl,Trait}Item` as `AssocItem`.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs41
-rw-r--r--src/libsyntax/attr/mod.rs2
2 files changed, 25 insertions, 18 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 89868a9cd29..dd8a7fa8665 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1603,23 +1603,16 @@ pub struct FnSig {
     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,
-/// possibly including a default implementation. A trait item is
-/// either required (meaning it doesn't have an implementation, just a
-/// signature) or provided (meaning it has a default implementation).
+/// Represents associated items.
+/// These include items in `impl` and `trait` definitions.
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
-pub enum TraitItemKind {
-    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 struct AssocItem<K = ImplItemKind> {
     pub attrs: Vec<Attribute>,
     pub id: NodeId,
     pub span: Span,
@@ -1634,11 +1627,25 @@ pub struct ImplItem<K = ImplItemKind> {
 }
 
 /// Represents various kinds of content within an `impl`.
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
-pub enum ImplItemKind  {
+///
+/// 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)]
+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>>),
+
+    /// An associated function.
     Method(FnSig, Option<P<Block>>),
+
+    /// An associated type.
     TyAlias(GenericBounds, Option<P<Ty>>),
+
+    /// A macro expanding to an associated item.
     Macro(Mac),
 }
 
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs
index 079a0f6fafa..13a9ed5f215 100644
--- a/src/libsyntax/attr/mod.rs
+++ b/src/libsyntax/attr/mod.rs
@@ -749,6 +749,6 @@ macro_rules! 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
 }