Skip to content

Commit 7870434

Browse files
committed
added fmt::Display as a supertrait for AstNode and changed generation.
1 parent 1901794 commit 7870434

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

crates/ra_syntax/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use self::{
3030
/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
3131
/// the same representation: a pointer to the tree root and a pointer to the
3232
/// node itself.
33-
pub trait AstNode {
33+
pub trait AstNode: std::fmt::Display {
3434
fn can_cast(kind: SyntaxKind) -> bool
3535
where
3636
Self: Sized;

xtask/src/codegen/gen_syntax.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ fn generate_ast(grammar: AstSrc<'_>) -> Result<String> {
6868
pub(crate) syntax: SyntaxNode,
6969
}
7070

71+
impl std::fmt::Display for #name {
72+
fn fmt(..) -> std::fmt::Result {
73+
std::fmt::Display::fmt(self.syntax())
74+
}
75+
}
76+
7177
impl AstNode for #name {
7278
fn can_cast(kind: SyntaxKind) -> bool {
7379
match kind {

0 commit comments

Comments
 (0)