aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-23 13:07:56 +0100
committerGitHub <[email protected]>2019-08-23 13:07:56 +0100
commitc12dce0073c1766f7d2b10a69f8526a8093e70dc (patch)
tree3d0df9bf5c25cdf241426901c78c2b7f9bb8e38b /crates/ra_syntax
parente055cfacdfe3b3451484dae5d6ed08aefba133ca (diff)
parentbbcca4f735870246c8ed8ce1a29af100e09b0a6f (diff)
Merge #1716
1716: make ast object safe r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-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>