diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index 5b695242656..076df98f277 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -19,7 +19,10 @@ pub struct AstEditor { } impl AstEditor { - pub fn new(node: N) -> AstEditor { + pub fn new(node: N) -> AstEditor + where + N: Clone, + { AstEditor { original_ast: node.clone(), ast: node } } @@ -379,7 +382,7 @@ impl AstBuilder { fn ast_node_from_file_text(text: &str) -> N { let parse = SourceFile::parse(text); - let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap().to_owned(); + let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); res } diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index afdfca66e31..a2f8628699e 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -25,15 +25,23 @@ 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: Clone { - fn can_cast(kind: SyntaxKind) -> bool; +pub trait AstNode { + fn can_cast(kind: SyntaxKind) -> bool + where + Self: Sized; fn cast(syntax: SyntaxNode) -> Option where Self: Sized; + fn syntax(&self) -> &SyntaxNode; } +#[test] +fn assert_ast_is_object_safe() { + fn _f(_: &dyn AstNode, _: &dyn NameOwner) {} +} + /// Like `AstNode`, but wraps tokens rather than interior nodes. pub trait AstToken { fn cast(token: SyntaxToken) -> Option