mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Cleanup invert-if
* stick to trivial factory functions in make * compress the logic for inverting Option/Result
This commit is contained in:
parent
ef9cea945d
commit
7721accebf
2 changed files with 16 additions and 24 deletions
|
@ -7,7 +7,7 @@
|
|||
use itertools::Itertools;
|
||||
use stdx::format_to;
|
||||
|
||||
use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxText, SyntaxToken};
|
||||
use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||
|
||||
pub fn name(text: &str) -> ast::Name {
|
||||
ast_from_text(&format!("mod {};", text))
|
||||
|
@ -137,11 +137,8 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr {
|
|||
pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
|
||||
expr_from_text(&format!("{}{}", f, arg_list))
|
||||
}
|
||||
pub fn expr_method_call<F>(text: &str, caller: F) -> Option<ast::Expr>
|
||||
where
|
||||
F: FnOnce() -> Option<SyntaxText>,
|
||||
{
|
||||
try_expr_from_text(&format!("{}.{}()", caller()?, text))
|
||||
pub fn expr_method_call(receiver: ast::Expr, method: &str, arg_list: ast::ArgList) -> ast::Expr {
|
||||
expr_from_text(&format!("{}.{}{}", receiver, method, arg_list))
|
||||
}
|
||||
fn expr_from_text(text: &str) -> ast::Expr {
|
||||
ast_from_text(&format!("const C: () = {};", text))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue