internal: make::expr_prefix should return ast::PrefixExpr

This commit is contained in:
Giga Bowser 2024-12-14 16:12:25 -05:00
parent 159731022f
commit 913d197a04
7 changed files with 8 additions and 8 deletions

View file

@ -252,7 +252,7 @@ fn tail_cb_impl(edit: &mut SourceChangeBuilder, e: &ast::Expr) {
/// Add bang and parentheses to the expression.
fn add_bang_paren(expr: ast::Expr) -> ast::Expr {
make::expr_prefix(T![!], make::expr_paren(expr))
make::expr_prefix(T![!], make::expr_paren(expr)).into()
}
#[cfg(test)]

View file

@ -507,7 +507,7 @@ fn wrap_capture_in_deref_if_needed(
if does_autoderef {
return capture_name;
}
make::expr_prefix(T![*], capture_name)
make::expr_prefix(T![*], capture_name).into()
}
fn capture_as_arg(ctx: &AssistContext<'_>, capture: &ClosureCapture) -> ast::Expr {

View file

@ -272,7 +272,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext<'
ast::Pat::LiteralPat(p)
if p.literal().is_some_and(|it| it.token().kind() == T![false]) =>
{
make::expr_prefix(T![!], scrutinee)
make::expr_prefix(T![!], scrutinee).into()
}
_ => make::expr_let(if_let_pat, scrutinee).into(),
};

View file

@ -246,7 +246,7 @@ pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize {
}
pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
invert_special_case(&expr).unwrap_or_else(|| make::expr_prefix(T![!], expr))
invert_special_case(&expr).unwrap_or_else(|| make::expr_prefix(T![!], expr).into())
}
fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
@ -262,7 +262,7 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
T![>] => T![<=],
T![>=] => T![<],
// Parenthesize other expressions before prefixing `!`
_ => return Some(make::expr_prefix(T![!], make::expr_paren(expr.clone()))),
_ => return Some(make::expr_prefix(T![!], make::expr_paren(expr.clone())).into()),
};
ted::replace(op_token, make::token(rev_token));
Some(bin.into())

View file

@ -121,7 +121,7 @@ impl RefData {
/// Derefs `expr` and wraps it in parens if necessary
pub(crate) fn wrap_expr(&self, mut expr: ast::Expr) -> ast::Expr {
if self.needs_deref {
expr = make::expr_prefix(T![*], expr);
expr = make::expr_prefix(T![*], expr).into();
}
if self.needs_parentheses {

View file

@ -303,7 +303,7 @@ fn include_references(initial_element: &ast::Expr) -> (ast::Expr, ast::Expr) {
resulting_element = ast::Expr::from(parent_deref_element);
new_element_opt = make::expr_prefix(syntax::T![*], new_element_opt);
new_element_opt = make::expr_prefix(syntax::T![*], new_element_opt).into();
}
if let Some(first_ref_expr) = resulting_element.syntax().parent().and_then(ast::RefExpr::cast) {

View file

@ -623,7 +623,7 @@ pub fn expr_loop(block: ast::BlockExpr) -> ast::Expr {
expr_from_text(&format!("loop {block}"))
}
pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr {
pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::PrefixExpr {
let token = token(op);
expr_from_text(&format!("{token}{expr}"))
}