Merge #9892
9892: internal: remove a remnant of old editing infra r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
c1a7169bf0
@ -61,7 +61,7 @@ mod handlers {
|
||||
mod convert_into_to_from;
|
||||
mod convert_iter_for_each_to_for;
|
||||
mod convert_tuple_struct_to_named_struct;
|
||||
mod early_return;
|
||||
mod convert_to_guarded_return;
|
||||
mod expand_glob_import;
|
||||
mod extract_function;
|
||||
mod extract_struct_from_enum_variant;
|
||||
@ -126,14 +126,14 @@ pub(crate) fn all() -> &'static [Handler] {
|
||||
apply_demorgan::apply_demorgan,
|
||||
auto_import::auto_import,
|
||||
change_visibility::change_visibility,
|
||||
convert_bool_then::convert_if_to_bool_then,
|
||||
convert_bool_then::convert_bool_then_to_if,
|
||||
convert_bool_then::convert_if_to_bool_then,
|
||||
convert_comment_block::convert_comment_block,
|
||||
convert_integer_literal::convert_integer_literal,
|
||||
convert_into_to_from::convert_into_to_from,
|
||||
convert_iter_for_each_to_for::convert_iter_for_each_to_for,
|
||||
convert_to_guarded_return::convert_to_guarded_return,
|
||||
convert_tuple_struct_to_named_struct::convert_tuple_struct_to_named_struct,
|
||||
early_return::convert_to_guarded_return,
|
||||
expand_glob_import::expand_glob_import,
|
||||
extract_struct_from_enum_variant::extract_struct_from_enum_variant,
|
||||
extract_type_alias::extract_type_alias,
|
||||
@ -144,7 +144,6 @@ pub(crate) fn all() -> &'static [Handler] {
|
||||
flip_trait_bound::flip_trait_bound,
|
||||
generate_default_from_enum_variant::generate_default_from_enum_variant,
|
||||
generate_default_from_new::generate_default_from_new,
|
||||
generate_is_empty_from_len::generate_is_empty_from_len,
|
||||
generate_deref::generate_deref,
|
||||
generate_derive::generate_derive,
|
||||
generate_enum_is_method::generate_enum_is_method,
|
||||
@ -152,11 +151,9 @@ pub(crate) fn all() -> &'static [Handler] {
|
||||
generate_enum_projection_method::generate_enum_try_into_method,
|
||||
generate_from_impl_for_enum::generate_from_impl_for_enum,
|
||||
generate_function::generate_function,
|
||||
generate_getter::generate_getter,
|
||||
generate_getter::generate_getter_mut,
|
||||
generate_impl::generate_impl,
|
||||
generate_is_empty_from_len::generate_is_empty_from_len,
|
||||
generate_new::generate_new,
|
||||
generate_setter::generate_setter,
|
||||
infer_function_return_type::infer_function_return_type,
|
||||
inline_call::inline_call,
|
||||
inline_local_variable::inline_local_variable,
|
||||
@ -204,6 +201,10 @@ pub(crate) fn all() -> &'static [Handler] {
|
||||
//
|
||||
extract_variable::extract_variable,
|
||||
extract_function::extract_function,
|
||||
//
|
||||
generate_getter::generate_getter,
|
||||
generate_getter::generate_getter_mut,
|
||||
generate_setter::generate_setter,
|
||||
// Are you sure you want to add new assist here, and not to the
|
||||
// sorted list above?
|
||||
]
|
||||
|
@ -209,21 +209,22 @@ pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
|
||||
|
||||
fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
|
||||
match expr {
|
||||
ast::Expr::BinExpr(bin) => match bin.op_kind()? {
|
||||
ast::BinaryOp::CmpOp(op) => {
|
||||
let rev_op = match op {
|
||||
ast::CmpOp::Eq { negated: false } => T![!=],
|
||||
ast::CmpOp::Eq { negated: true } => T![==],
|
||||
ast::CmpOp::Ord { ordering: ast::Ordering::Less, strict: true } => T![>=],
|
||||
ast::CmpOp::Ord { ordering: ast::Ordering::Less, strict: false } => T![>],
|
||||
ast::CmpOp::Ord { ordering: ast::Ordering::Greater, strict: true } => T![<=],
|
||||
ast::CmpOp::Ord { ordering: ast::Ordering::Greater, strict: false } => T![<],
|
||||
};
|
||||
bin.replace_op(rev_op).map(ast::Expr::from)
|
||||
}
|
||||
// Parenthesize other expressions before prefixing `!`
|
||||
_ => Some(make::expr_prefix(T![!], make::expr_paren(expr.clone()))),
|
||||
},
|
||||
ast::Expr::BinExpr(bin) => {
|
||||
let bin = bin.clone_for_update();
|
||||
let op_token = bin.op_token()?;
|
||||
let rev_token = match op_token.kind() {
|
||||
T![==] => T![!=],
|
||||
T![!=] => T![==],
|
||||
T![<] => T![>=],
|
||||
T![<=] => T![>],
|
||||
T![>] => T![<=],
|
||||
T![>=] => T![<],
|
||||
// Parenthesize other expressions before prefixing `!`
|
||||
_ => return Some(make::expr_prefix(T![!], make::expr_paren(expr.clone()))),
|
||||
};
|
||||
ted::replace(op_token, make::token(rev_token));
|
||||
Some(bin.into())
|
||||
}
|
||||
ast::Expr::MethodCallExpr(mce) => {
|
||||
let receiver = mce.receiver()?;
|
||||
let method = mce.name_ref()?;
|
||||
|
@ -1,28 +1,16 @@
|
||||
//! This module contains functions for editing syntax trees. As the trees are
|
||||
//! immutable, all function here return a fresh copy of the tree, instead of
|
||||
//! doing an in-place modification.
|
||||
use std::{
|
||||
fmt, iter,
|
||||
ops::{self, RangeInclusive},
|
||||
};
|
||||
use std::{fmt, iter, ops};
|
||||
|
||||
use crate::{
|
||||
algo,
|
||||
ast::{self, make, AstNode},
|
||||
ted, AstToken, NodeOrToken, SyntaxElement, SyntaxKind,
|
||||
ted, AstToken, NodeOrToken, SyntaxElement,
|
||||
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
||||
SyntaxNode, SyntaxToken,
|
||||
};
|
||||
|
||||
impl ast::BinExpr {
|
||||
#[must_use]
|
||||
pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> {
|
||||
let op_node: SyntaxElement = self.op_details()?.0.into();
|
||||
let to_insert: Option<SyntaxElement> = Some(make::token(op).into());
|
||||
Some(self.replace_children(single_node(op_node), to_insert))
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::UseTree {
|
||||
/// Splits off the given prefix, making it the path component of the use tree, appending the rest of the path to all UseTreeList items.
|
||||
#[must_use]
|
||||
@ -191,15 +179,6 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
|
||||
}
|
||||
|
||||
pub trait AstNodeEdit: AstNode + Clone + Sized {
|
||||
#[must_use]
|
||||
fn replace_children(
|
||||
&self,
|
||||
to_replace: RangeInclusive<SyntaxElement>,
|
||||
to_insert: impl IntoIterator<Item = SyntaxElement>,
|
||||
) -> Self {
|
||||
let new_syntax = algo::replace_children(self.syntax(), to_replace, to_insert);
|
||||
Self::cast(new_syntax).unwrap()
|
||||
}
|
||||
fn indent_level(&self) -> IndentLevel {
|
||||
IndentLevel::from_node(self.syntax())
|
||||
}
|
||||
@ -220,11 +199,6 @@ fn reset_indent(&self) -> Self {
|
||||
|
||||
impl<N: AstNode + Clone> AstNodeEdit for N {}
|
||||
|
||||
fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElement> {
|
||||
let element = element.into();
|
||||
element.clone()..=element
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increase_indent() {
|
||||
let arm_list = {
|
||||
|
Loading…
Reference in New Issue
Block a user