mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-18 17:40:29 +00:00
Simplify
This commit is contained in:
parent
80f522091a
commit
c4a119f433
8 changed files with 39 additions and 27 deletions
|
@ -48,7 +48,7 @@ impl ast::Expr {
|
|||
}
|
||||
|
||||
/// Preorder walk all the expression's child expressions preserving events.
|
||||
/// If the callback returns true the subtree of the expression will be skipped.
|
||||
/// If the callback returns true on an [`WalkEvent::Enter`], the subtree of the expression will be skipped.
|
||||
/// Note that the subtree may already be skipped due to the context analysis this function does.
|
||||
pub fn preorder(&self, cb: &mut dyn FnMut(WalkEvent<ast::Expr>) -> bool) {
|
||||
let mut preorder = self.syntax().preorder();
|
||||
|
|
|
@ -304,12 +304,20 @@ 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(receiver: ast::Expr, method: &str, arg_list: ast::ArgList) -> ast::Expr {
|
||||
pub fn expr_method_call(
|
||||
receiver: ast::Expr,
|
||||
method: ast::NameRef,
|
||||
arg_list: ast::ArgList,
|
||||
) -> ast::Expr {
|
||||
expr_from_text(&format!("{}.{}{}", receiver, method, arg_list))
|
||||
}
|
||||
pub fn expr_ref(expr: ast::Expr, exclusive: bool) -> ast::Expr {
|
||||
expr_from_text(&if exclusive { format!("&mut {}", expr) } else { format!("&{}", expr) })
|
||||
}
|
||||
pub fn expr_closure(pats: impl IntoIterator<Item = ast::Param>, expr: ast::Expr) -> ast::Expr {
|
||||
let params = pats.into_iter().join(", ");
|
||||
expr_from_text(&format!("|{}| {}", params, expr))
|
||||
}
|
||||
pub fn expr_paren(expr: ast::Expr) -> ast::Expr {
|
||||
expr_from_text(&format!("({})", expr))
|
||||
}
|
||||
|
|
|
@ -611,6 +611,12 @@ impl ast::Item {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::Condition {
|
||||
pub fn is_pattern_cond(&self) -> bool {
|
||||
self.let_token().is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum FieldKind {
|
||||
Name(ast::NameRef),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue