aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/ast_editor.rs7
-rw-r--r--crates/ra_syntax/src/ast.rs12
2 files changed, 15 insertions, 4 deletions
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs
index 5b6952426..076df98f2 100644
--- a/crates/ra_assists/src/ast_editor.rs
+++ b/crates/ra_assists/src/ast_editor.rs
@@ -19,7 +19,10 @@ pub struct AstEditor<N: AstNode> {
19} 19}
20 20
21impl<N: AstNode> AstEditor<N> { 21impl<N: AstNode> AstEditor<N> {
22 pub fn new(node: N) -> AstEditor<N> { 22 pub fn new(node: N) -> AstEditor<N>
23 where
24 N: Clone,
25 {
23 AstEditor { original_ast: node.clone(), ast: node } 26 AstEditor { original_ast: node.clone(), ast: node }
24 } 27 }
25 28
@@ -379,7 +382,7 @@ impl AstBuilder<ast::MatchArmList> {
379 382
380fn ast_node_from_file_text<N: AstNode>(text: &str) -> N { 383fn ast_node_from_file_text<N: AstNode>(text: &str) -> N {
381 let parse = SourceFile::parse(text); 384 let parse = SourceFile::parse(text);
382 let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap().to_owned(); 385 let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap();
383 res 386 res
384} 387}
385 388
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>