diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-30 18:25:44 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-12 17:54:48 +0100 |
| commit | c4bbe9cbbe9921646cdedb856e34dc951641ed96 (patch) | |
| tree | c71c2d933922bb09df1c005a909463caa90be6f8 /src/libsyntax | |
| parent | 3eebe058e52b749d1a38926390c12900e91b0b2c (diff) | |
| download | rust-c4bbe9cbbe9921646cdedb856e34dc951641ed96.tar.gz rust-c4bbe9cbbe9921646cdedb856e34dc951641ed96.zip | |
Alias `TraitItem` & `ImplItem`.
Allow defaultness on trait items syntactically.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/mut_visit.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 1 |
3 files changed, 8 insertions, 18 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 92ba071a03d..964acfa92b9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1603,25 +1603,13 @@ pub struct FnSig { pub decl: P<FnDecl>, } -/// Represents an item declaration within a trait declaration, +pub type TraitItem = ImplItem<TraitItemKind>; + +/// 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). #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct TraitItem { - pub attrs: Vec<Attribute>, - pub id: NodeId, - pub span: Span, - pub vis: Visibility, - pub ident: Ident, - - pub generics: Generics, - pub kind: TraitItemKind, - /// See `Item::tokens` for what this is. - pub tokens: Option<TokenStream>, -} - -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum TraitItemKind { Const(P<Ty>, Option<P<Expr>>), Method(FnSig, Option<P<Block>>), @@ -1631,7 +1619,7 @@ pub enum TraitItemKind { /// Represents anything within an `impl` block. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct ImplItem { +pub struct ImplItem<K = ImplItemKind> { pub attrs: Vec<Attribute>, pub id: NodeId, pub span: Span, @@ -1640,7 +1628,7 @@ pub struct ImplItem { pub defaultness: Defaultness, pub generics: Generics, - pub kind: ImplItemKind, + pub kind: K, /// See `Item::tokens` for what this is. pub tokens: Option<TokenStream>, } diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index f8795d885d2..9d0a29f2951 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -939,7 +939,8 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) { pub fn noop_flat_map_trait_item<T: MutVisitor>(mut item: TraitItem, visitor: &mut T) -> SmallVec<[TraitItem; 1]> { - let TraitItem { id, ident, vis, attrs, generics, kind, span, tokens: _ } = &mut item; + let TraitItem { id, ident, vis, defaultness: _, attrs, generics, kind, span, tokens: _ } = + &mut item; visitor.visit_id(id); visitor.visit_ident(ident); visitor.visit_vis(vis); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f0c5fb32fb1..2e3ea5e2444 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1550,6 +1550,7 @@ impl<'a> State<'a> { self.hardbreak_if_not_bol(); self.maybe_print_comment(ti.span.lo()); self.print_outer_attributes(&ti.attrs); + self.print_defaultness(ti.defaultness); match ti.kind { ast::TraitItemKind::Const(ref ty, ref default) => { self.print_associated_const( |
