From 92a372b0204a5f18286ff94648b98e4c0d6d27d2 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 1 Dec 2019 10:46:06 +0100 Subject: [PATCH] Unify `{Impl,Trait}Item` as `AssocItem`. --- src/libsyntax/ast.rs | 39 +++++++++++++++++++++++---------------- src/libsyntax/attr/mod.rs | 2 +- 2 files changed, 24 insertions(+), 17 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, } -pub type TraitItem = ImplItem; +// FIXME(Centril): Remove all of these. +pub type TraitItem = AssocItem; +pub type TraitItemKind = AssocItemKind; +pub type ImplItem = AssocItem; +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, Option>), - Method(FnSig, Option>), - TyAlias(GenericBounds, Option>), - Macro(Mac), -} - -/// Represents anything within an `impl` block. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct ImplItem { +pub struct AssocItem { pub attrs: Vec, pub id: NodeId, pub span: Span, @@ -1634,11 +1627,25 @@ pub struct ImplItem { } /// 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)] -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, Option>), + + /// An associated function. Method(FnSig, Option>), + + /// An associated type. TyAlias(GenericBounds, Option>), + + /// 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 }