File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ pub struct AstEditor<N: AstNode> {
19
19
}
20
20
21
21
impl < 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
26
AstEditor { original_ast : node. clone ( ) , ast : node }
24
27
}
25
28
@@ -379,7 +382,7 @@ impl AstBuilder<ast::MatchArmList> {
379
382
380
383
fn ast_node_from_file_text < N : AstNode > ( text : & str ) -> N {
381
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
386
res
384
387
}
385
388
Original file line number Diff line number Diff line change @@ -25,15 +25,23 @@ pub use self::{
25
25
/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
26
26
/// the same representation: a pointer to the tree root and a pointer to the
27
27
/// node itself.
28
- pub trait AstNode : Clone {
29
- fn can_cast ( kind : SyntaxKind ) -> bool ;
28
+ pub trait AstNode {
29
+ fn can_cast ( kind : SyntaxKind ) -> bool
30
+ where
31
+ Self : Sized ;
30
32
31
33
fn cast ( syntax : SyntaxNode ) -> Option < Self >
32
34
where
33
35
Self : Sized ;
36
+
34
37
fn syntax ( & self ) -> & SyntaxNode ;
35
38
}
36
39
40
+ #[ test]
41
+ fn assert_ast_is_object_safe ( ) {
42
+ fn _f ( _: & dyn AstNode , _: & dyn NameOwner ) { }
43
+ }
44
+
37
45
/// Like `AstNode`, but wraps tokens rather than interior nodes.
38
46
pub trait AstToken {
39
47
fn cast ( token : SyntaxToken ) -> Option < Self >
You can’t perform that action at this time.
0 commit comments