mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: use more mutable APIs
This commit is contained in:
parent
6c21d04307
commit
883dd1568f
3 changed files with 33 additions and 53 deletions
|
@ -13,7 +13,7 @@ use crate::{
|
|||
ast::{
|
||||
self,
|
||||
make::{self, tokens},
|
||||
AstNode, TypeBoundsOwner,
|
||||
AstNode,
|
||||
},
|
||||
ted, AstToken, Direction, InsertPosition, NodeOrToken, SmolStr, SyntaxElement, SyntaxKind,
|
||||
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
||||
|
@ -29,25 +29,6 @@ impl ast::BinExpr {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::Fn {
|
||||
#[must_use]
|
||||
pub fn with_body(&self, body: ast::BlockExpr) -> ast::Fn {
|
||||
let mut to_insert: ArrayVec<SyntaxElement, 2> = ArrayVec::new();
|
||||
let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() {
|
||||
old_body.syntax().clone().into()
|
||||
} else if let Some(semi) = self.semicolon_token() {
|
||||
to_insert.push(make::tokens::single_space().into());
|
||||
semi.into()
|
||||
} else {
|
||||
to_insert.push(make::tokens::single_space().into());
|
||||
to_insert.push(body.syntax().clone().into());
|
||||
return self.insert_children(InsertPosition::Last, to_insert);
|
||||
};
|
||||
to_insert.push(body.syntax().clone().into());
|
||||
self.replace_children(single_node(old_body_or_semi), to_insert)
|
||||
}
|
||||
}
|
||||
|
||||
fn make_multiline<N>(node: N) -> N
|
||||
where
|
||||
N: AstNode + Clone,
|
||||
|
@ -156,21 +137,6 @@ impl ast::RecordExprFieldList {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::TypeAlias {
|
||||
#[must_use]
|
||||
pub fn remove_bounds(&self) -> ast::TypeAlias {
|
||||
let colon = match self.colon_token() {
|
||||
Some(it) => it,
|
||||
None => return self.clone(),
|
||||
};
|
||||
let end = match self.type_bound_list() {
|
||||
Some(it) => it.syntax().clone().into(),
|
||||
None => colon.clone().into(),
|
||||
};
|
||||
self.replace_children(colon.into()..=end, iter::empty())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Path {
|
||||
#[must_use]
|
||||
pub fn with_segment(&self, segment: ast::PathSegment) -> ast::Path {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue