From 787043496aaa05be31162a8cdd0686a13da646cc Mon Sep 17 00:00:00 2001 From: Fireassember Date: Fri, 6 Mar 2020 19:29:30 +0200 Subject: [PATCH] added fmt::Display as a supertrait for AstNode and changed generation. --- crates/ra_syntax/src/ast.rs | 2 +- xtask/src/codegen/gen_syntax.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 4a70c712f0..26fafb469a 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -30,7 +30,7 @@ pub use self::{ /// conversion itself has zero runtime cost: ast and syntax nodes have exactly /// the same representation: a pointer to the tree root and a pointer to the /// node itself. -pub trait AstNode { +pub trait AstNode: std::fmt::Display { fn can_cast(kind: SyntaxKind) -> bool where Self: Sized; diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index db05dcebb0..879f0243ed 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -68,6 +68,12 @@ fn generate_ast(grammar: AstSrc<'_>) -> Result { pub(crate) syntax: SyntaxNode, } + impl std::fmt::Display for #name { + fn fmt(..) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax()) + } + } + impl AstNode for #name { fn can_cast(kind: SyntaxKind) -> bool { match kind {