Skip to content

Commit dc17b35

Browse files
committed
internal: remove a remnant of old editing infra
1 parent 90357a9 commit dc17b35

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
lines changed

crates/ide_assists/src/utils.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,22 @@ pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
209209

210210
fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
211211
match expr {
212-
ast::Expr::BinExpr(bin) => match bin.op_kind()? {
213-
ast::BinaryOp::CmpOp(op) => {
214-
let rev_op = match op {
215-
ast::CmpOp::Eq { negated: false } => T![!=],
216-
ast::CmpOp::Eq { negated: true } => T![==],
217-
ast::CmpOp::Ord { ordering: ast::Ordering::Less, strict: true } => T![>=],
218-
ast::CmpOp::Ord { ordering: ast::Ordering::Less, strict: false } => T![>],
219-
ast::CmpOp::Ord { ordering: ast::Ordering::Greater, strict: true } => T![<=],
220-
ast::CmpOp::Ord { ordering: ast::Ordering::Greater, strict: false } => T![<],
221-
};
222-
bin.replace_op(rev_op).map(ast::Expr::from)
223-
}
224-
// Parenthesize other expressions before prefixing `!`
225-
_ => Some(make::expr_prefix(T![!], make::expr_paren(expr.clone()))),
226-
},
212+
ast::Expr::BinExpr(bin) => {
213+
let bin = bin.clone_for_update();
214+
let op_token = bin.op_token()?;
215+
let rev_token = match op_token.kind() {
216+
T![==] => T![!=],
217+
T![!=] => T![==],
218+
T![<] => T![>=],
219+
T![<=] => T![>],
220+
T![>] => T![<=],
221+
T![>=] => T![<],
222+
// Parenthesize other expressions before prefixing `!`
223+
_ => return Some(make::expr_prefix(T![!], make::expr_paren(expr.clone()))),
224+
};
225+
ted::replace(op_token, make::token(rev_token));
226+
Some(bin.into())
227+
}
227228
ast::Expr::MethodCallExpr(mce) => {
228229
let receiver = mce.receiver()?;
229230
let method = mce.name_ref()?;

crates/syntax/src/ast/edit.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
//! This module contains functions for editing syntax trees. As the trees are
22
//! immutable, all function here return a fresh copy of the tree, instead of
33
//! doing an in-place modification.
4-
use std::{
5-
fmt, iter,
6-
ops::{self, RangeInclusive},
7-
};
4+
use std::{fmt, iter, ops};
85

96
use crate::{
107
algo,
118
ast::{self, make, AstNode},
12-
ted, AstToken, NodeOrToken, SyntaxElement, SyntaxKind,
9+
ted, AstToken, NodeOrToken, SyntaxElement,
1310
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
1411
SyntaxNode, SyntaxToken,
1512
};
1613

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-
2614
impl ast::UseTree {
2715
/// Splits off the given prefix, making it the path component of the use tree, appending the rest of the path to all UseTreeList items.
2816
#[must_use]
@@ -191,15 +179,6 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
191179
}
192180

193181
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-
}
203182
fn indent_level(&self) -> IndentLevel {
204183
IndentLevel::from_node(self.syntax())
205184
}
@@ -220,11 +199,6 @@ pub trait AstNodeEdit: AstNode + Clone + Sized {
220199

221200
impl<N: AstNode + Clone> AstNodeEdit for N {}
222201

223-
fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElement> {
224-
let element = element.into();
225-
element.clone()..=element
226-
}
227-
228202
#[test]
229203
fn test_increase_indent() {
230204
let arm_list = {

0 commit comments

Comments
 (0)