mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
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:
parent
f388482119
commit
905e1e1fc0
8 changed files with 18 additions and 18 deletions
|
@ -97,7 +97,7 @@ pub(crate) fn convert_from_to_tryfrom(acc: &mut Assists, ctx: &AssistContext<'_>
|
||||||
);
|
);
|
||||||
|
|
||||||
for r in return_exprs {
|
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());
|
ted::replace(t.syntax(), wrap_ok(t.clone()).syntax().clone_for_update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1910,7 +1910,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
|
||||||
match &handler {
|
match &handler {
|
||||||
FlowHandler::None => block,
|
FlowHandler::None => block,
|
||||||
FlowHandler::Try { kind } => {
|
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| {
|
map_tail_expr(block, |tail_expr| {
|
||||||
let constructor = match kind {
|
let constructor = match kind {
|
||||||
TryKind::Option => "Some",
|
TryKind::Option => "Some",
|
||||||
|
@ -1924,7 +1924,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
|
||||||
FlowHandler::If { .. } => {
|
FlowHandler::If { .. } => {
|
||||||
let controlflow_continue = make::expr_call(
|
let controlflow_continue = make::expr_call(
|
||||||
make::expr_path(make::path_from_text("ControlFlow::Continue")),
|
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)
|
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::None | FlowHandler::Try { .. } => return None,
|
||||||
FlowHandler::If { .. } => make::expr_call(
|
FlowHandler::If { .. } => make::expr_call(
|
||||||
make::expr_path(make::path_from_text("ControlFlow::Break")),
|
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 { .. } => {
|
FlowHandler::IfOption { .. } => {
|
||||||
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
|
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
|
||||||
let args = make::arg_list(iter::once(expr));
|
let args = make::arg_list([expr]);
|
||||||
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
|
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
|
||||||
}
|
}
|
||||||
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
|
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
|
||||||
FlowHandler::MatchResult { .. } => {
|
FlowHandler::MatchResult { .. } => {
|
||||||
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
|
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
|
||||||
let args = make::arg_list(iter::once(expr));
|
let args = make::arg_list([expr]);
|
||||||
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
|
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -102,7 +102,7 @@ fn compute_dbg_replacement(macro_expr: ast::MacroExpr) -> Option<(TextRange, Opt
|
||||||
};
|
};
|
||||||
(range, None)
|
(range, None)
|
||||||
},
|
},
|
||||||
_ => (macro_call.syntax().text_range(), Some(make::expr_unit())),
|
_ => (macro_call.syntax().text_range(), Some(make::ext::expr_unit())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ fn make_else_arm(
|
||||||
[(Either::Right(_), _)] => make::literal_pat("false").into(),
|
[(Either::Right(_), _)] => make::literal_pat("false").into(),
|
||||||
_ => make::wildcard_pat().into(),
|
_ => make::wildcard_pat().into(),
|
||||||
};
|
};
|
||||||
(pattern, make::expr_unit())
|
(pattern, make::ext::expr_unit())
|
||||||
};
|
};
|
||||||
make::match_arm(iter::once(pattern), None, expr)
|
make::match_arm(iter::once(pattern), None, expr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let empty_tuple = make::expr_unit();
|
let empty_tuple = make::ext::expr_unit();
|
||||||
make::let_stmt(pattern, ty, Some(empty_tuple)).to_string()
|
make::let_stmt(pattern, ty, Some(empty_tuple)).to_string()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -153,8 +153,9 @@ impl<N: AstNode + Clone> AstNodeEdit for N {}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_increase_indent() {
|
fn test_increase_indent() {
|
||||||
let arm_list = {
|
let arm_list = {
|
||||||
let arm = make::match_arm(iter::once(make::wildcard_pat().into()), None, make::expr_unit());
|
let arm =
|
||||||
make::match_arm_list(vec![arm.clone(), arm])
|
make::match_arm(iter::once(make::wildcard_pat().into()), None, make::ext::expr_unit());
|
||||||
|
make::match_arm_list([arm.clone(), arm])
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
arm_list.syntax().to_string(),
|
arm_list.syntax().to_string(),
|
||||||
|
|
|
@ -63,6 +63,9 @@ pub mod ext {
|
||||||
Some(expr)
|
Some(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn expr_unit() -> ast::Expr {
|
||||||
|
expr_tuple([]).into()
|
||||||
|
}
|
||||||
pub fn expr_unreachable() -> ast::Expr {
|
pub fn expr_unreachable() -> ast::Expr {
|
||||||
expr_from_text("unreachable!()")
|
expr_from_text("unreachable!()")
|
||||||
}
|
}
|
||||||
|
@ -546,10 +549,6 @@ pub fn hacky_block_expr(
|
||||||
ast_from_text(&format!("fn f() {buf}"))
|
ast_from_text(&format!("fn f() {buf}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expr_unit() -> ast::Expr {
|
|
||||||
expr_from_text("()")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn expr_literal(text: &str) -> ast::Literal {
|
pub fn expr_literal(text: &str) -> ast::Literal {
|
||||||
assert_eq!(text.trim(), text);
|
assert_eq!(text.trim(), text);
|
||||||
ast_from_text(&format!("fn f() {{ let _ = {text}; }}"))
|
ast_from_text(&format!("fn f() {{ let _ = {text}; }}"))
|
||||||
|
|
|
@ -550,7 +550,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
make::param_list(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())),
|
Some(make::ret_type(make::ty_unit())),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Reference in a new issue