internal: move make::expr_unit to make::ext::expr_unit

`expr_unit` is just a shortcut for a common expression, so it belongs in `make::ext`
This commit is contained in:
Giga Bowser 2024-12-16 14:38:53 -05:00
parent f388482119
commit 905e1e1fc0
8 changed files with 18 additions and 18 deletions

View file

@ -97,7 +97,7 @@ pub(crate) fn convert_from_to_tryfrom(acc: &mut Assists, ctx: &AssistContext<'_>
);
for r in return_exprs {
let t = r.expr().unwrap_or_else(make::expr_unit);
let t = r.expr().unwrap_or_else(make::ext::expr_unit);
ted::replace(t.syntax(), wrap_ok(t.clone()).syntax().clone_for_update());
}

View file

@ -1910,7 +1910,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
match &handler {
FlowHandler::None => block,
FlowHandler::Try { kind } => {
let block = with_default_tail_expr(block, make::expr_unit());
let block = with_default_tail_expr(block, make::ext::expr_unit());
map_tail_expr(block, |tail_expr| {
let constructor = match kind {
TryKind::Option => "Some",
@ -1924,7 +1924,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
FlowHandler::If { .. } => {
let controlflow_continue = make::expr_call(
make::expr_path(make::path_from_text("ControlFlow::Continue")),
make::arg_list(iter::once(make::expr_unit())),
make::arg_list([make::ext::expr_unit()]),
);
with_tail_expr(block, controlflow_continue)
}
@ -2127,17 +2127,17 @@ fn make_rewritten_flow(handler: &FlowHandler, arg_expr: Option<ast::Expr>) -> Op
FlowHandler::None | FlowHandler::Try { .. } => return None,
FlowHandler::If { .. } => make::expr_call(
make::expr_path(make::path_from_text("ControlFlow::Break")),
make::arg_list(iter::once(make::expr_unit())),
make::arg_list([make::ext::expr_unit()]),
),
FlowHandler::IfOption { .. } => {
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
let args = make::arg_list(iter::once(expr));
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
let args = make::arg_list([expr]);
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
}
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
FlowHandler::MatchResult { .. } => {
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
let args = make::arg_list(iter::once(expr));
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
let args = make::arg_list([expr]);
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
}
};

View file

@ -102,7 +102,7 @@ fn compute_dbg_replacement(macro_expr: ast::MacroExpr) -> Option<(TextRange, Opt
};
(range, None)
},
_ => (macro_call.syntax().text_range(), Some(make::expr_unit())),
_ => (macro_call.syntax().text_range(), Some(make::ext::expr_unit())),
}
}
}

View file

@ -179,7 +179,7 @@ fn make_else_arm(
[(Either::Right(_), _)] => make::literal_pat("false").into(),
_ => make::wildcard_pat().into(),
};
(pattern, make::expr_unit())
(pattern, make::ext::expr_unit())
};
make::match_arm(iter::once(pattern), None, expr)
}

View file

@ -61,7 +61,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
}
}
None => {
let empty_tuple = make::expr_unit();
let empty_tuple = make::ext::expr_unit();
make::let_stmt(pattern, ty, Some(empty_tuple)).to_string()
}
};

View file

@ -153,8 +153,9 @@ impl<N: AstNode + Clone> AstNodeEdit for N {}
#[test]
fn test_increase_indent() {
let arm_list = {
let arm = make::match_arm(iter::once(make::wildcard_pat().into()), None, make::expr_unit());
make::match_arm_list(vec![arm.clone(), arm])
let arm =
make::match_arm(iter::once(make::wildcard_pat().into()), None, make::ext::expr_unit());
make::match_arm_list([arm.clone(), arm])
};
assert_eq!(
arm_list.syntax().to_string(),

View file

@ -63,6 +63,9 @@ pub mod ext {
Some(expr)
}
pub fn expr_unit() -> ast::Expr {
expr_tuple([]).into()
}
pub fn expr_unreachable() -> ast::Expr {
expr_from_text("unreachable!()")
}
@ -546,10 +549,6 @@ pub fn hacky_block_expr(
ast_from_text(&format!("fn f() {buf}"))
}
pub fn expr_unit() -> ast::Expr {
expr_from_text("()")
}
pub fn expr_literal(text: &str) -> ast::Literal {
assert_eq!(text.trim(), text);
ast_from_text(&format!("fn f() {{ let _ = {text}; }}"))

View file

@ -550,7 +550,7 @@ mod tests {
None,
None,
make::param_list(None, []),
make::block_expr([], Some(make::expr_unit())),
make::block_expr([], Some(make::ext::expr_unit())),
Some(make::ret_type(make::ty_unit())),
false,
false,