From bbcca4f735870246c8ed8ce1a29af100e09b0a6f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 22 Aug 2019 15:20:07 +0300 Subject: make ast object safe --- crates/ra_syntax/src/ast.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax') 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::{ /// 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 -- cgit v1.2.3