1
1
//! This module contains functions for editing syntax trees. As the trees are
2
2
//! immutable, all function here return a fresh copy of the tree, instead of
3
3
//! doing an in-place modification.
4
- use std:: {
5
- fmt, iter,
6
- ops:: { self , RangeInclusive } ,
7
- } ;
4
+ use std:: { fmt, iter, ops} ;
8
5
9
6
use crate :: {
10
7
algo,
11
8
ast:: { self , make, AstNode } ,
12
- ted, AstToken , NodeOrToken , SyntaxElement , SyntaxKind ,
9
+ ted, AstToken , NodeOrToken , SyntaxElement ,
13
10
SyntaxKind :: { ATTR , COMMENT , WHITESPACE } ,
14
11
SyntaxNode , SyntaxToken ,
15
12
} ;
16
13
17
- impl ast:: BinExpr {
18
- #[ must_use]
19
- pub fn replace_op ( & self , op : SyntaxKind ) -> Option < ast:: BinExpr > {
20
- let op_node: SyntaxElement = self . op_details ( ) ?. 0 . into ( ) ;
21
- let to_insert: Option < SyntaxElement > = Some ( make:: token ( op) . into ( ) ) ;
22
- Some ( self . replace_children ( single_node ( op_node) , to_insert) )
23
- }
24
- }
25
-
26
14
impl ast:: UseTree {
27
15
/// Splits off the given prefix, making it the path component of the use tree, appending the rest of the path to all UseTreeList items.
28
16
#[ must_use]
@@ -191,15 +179,6 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
191
179
}
192
180
193
181
pub trait AstNodeEdit : AstNode + Clone + Sized {
194
- #[ must_use]
195
- fn replace_children (
196
- & self ,
197
- to_replace : RangeInclusive < SyntaxElement > ,
198
- to_insert : impl IntoIterator < Item = SyntaxElement > ,
199
- ) -> Self {
200
- let new_syntax = algo:: replace_children ( self . syntax ( ) , to_replace, to_insert) ;
201
- Self :: cast ( new_syntax) . unwrap ( )
202
- }
203
182
fn indent_level ( & self ) -> IndentLevel {
204
183
IndentLevel :: from_node ( self . syntax ( ) )
205
184
}
@@ -220,11 +199,6 @@ pub trait AstNodeEdit: AstNode + Clone + Sized {
220
199
221
200
impl < N : AstNode + Clone > AstNodeEdit for N { }
222
201
223
- fn single_node ( element : impl Into < SyntaxElement > ) -> RangeInclusive < SyntaxElement > {
224
- let element = element. into ( ) ;
225
- element. clone ( ) ..=element
226
- }
227
-
228
202
#[ test]
229
203
fn test_increase_indent ( ) {
230
204
let arm_list = {
0 commit comments