aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index afdfca66e..a2f862869 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -25,15 +25,23 @@ pub use self::{
25/// conversion itself has zero runtime cost: ast and syntax nodes have exactly 25/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
26/// the same representation: a pointer to the tree root and a pointer to the 26/// the same representation: a pointer to the tree root and a pointer to the
27/// node itself. 27/// node itself.
28pub trait AstNode: Clone { 28pub trait AstNode {
29 fn can_cast(kind: SyntaxKind) -> bool; 29 fn can_cast(kind: SyntaxKind) -> bool
30 where
31 Self: Sized;
30 32
31 fn cast(syntax: SyntaxNode) -> Option<Self> 33 fn cast(syntax: SyntaxNode) -> Option<Self>
32 where 34 where
33 Self: Sized; 35 Self: Sized;
36
34 fn syntax(&self) -> &SyntaxNode; 37 fn syntax(&self) -> &SyntaxNode;
35} 38}
36 39
40#[test]
41fn assert_ast_is_object_safe() {
42 fn _f(_: &dyn AstNode, _: &dyn NameOwner) {}
43}
44
37/// Like `AstNode`, but wraps tokens rather than interior nodes. 45/// Like `AstNode`, but wraps tokens rather than interior nodes.
38pub trait AstToken { 46pub trait AstToken {
39 fn cast(token: SyntaxToken) -> Option<Self> 47 fn cast(token: SyntaxToken) -> Option<Self>