Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6528650

Browse files
committed
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`
1 parent ef7bb04 commit 6528650

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub(crate) fn convert_from_to_tryfrom(acc: &mut Assists, ctx: &AssistContext<'_>
9797
);
9898

9999
for r in return_exprs {
100-
let t = r.expr().unwrap_or_else(make::expr_unit);
100+
let t = r.expr().unwrap_or_else(make::ext::expr_unit);
101101
ted::replace(t.syntax(), wrap_ok(t.clone()).syntax().clone_for_update());
102102
}
103103

src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
19101910
match &handler {
19111911
FlowHandler::None => block,
19121912
FlowHandler::Try { kind } => {
1913-
let block = with_default_tail_expr(block, make::expr_unit());
1913+
let block = with_default_tail_expr(block, make::ext::expr_unit());
19141914
map_tail_expr(block, |tail_expr| {
19151915
let constructor = match kind {
19161916
TryKind::Option => "Some",
@@ -1924,7 +1924,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
19241924
FlowHandler::If { .. } => {
19251925
let controlflow_continue = make::expr_call(
19261926
make::expr_path(make::path_from_text("ControlFlow::Continue")),
1927-
make::arg_list(iter::once(make::expr_unit())),
1927+
make::arg_list([make::ext::expr_unit()]),
19281928
);
19291929
with_tail_expr(block, controlflow_continue)
19301930
}
@@ -2127,17 +2127,17 @@ fn make_rewritten_flow(handler: &FlowHandler, arg_expr: Option<ast::Expr>) -> Op
21272127
FlowHandler::None | FlowHandler::Try { .. } => return None,
21282128
FlowHandler::If { .. } => make::expr_call(
21292129
make::expr_path(make::path_from_text("ControlFlow::Break")),
2130-
make::arg_list(iter::once(make::expr_unit())),
2130+
make::arg_list([make::ext::expr_unit()]),
21312131
),
21322132
FlowHandler::IfOption { .. } => {
2133-
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
2134-
let args = make::arg_list(iter::once(expr));
2133+
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
2134+
let args = make::arg_list([expr]);
21352135
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
21362136
}
21372137
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
21382138
FlowHandler::MatchResult { .. } => {
2139-
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
2140-
let args = make::arg_list(iter::once(expr));
2139+
let expr = arg_expr.unwrap_or_else(make::ext::expr_unit);
2140+
let args = make::arg_list([expr]);
21412141
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
21422142
}
21432143
};

src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_dbg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn compute_dbg_replacement(macro_expr: ast::MacroExpr) -> Option<(TextRange, Opt
102102
};
103103
(range, None)
104104
},
105-
_ => (macro_call.syntax().text_range(), Some(make::expr_unit())),
105+
_ => (macro_call.syntax().text_range(), Some(make::ext::expr_unit())),
106106
}
107107
}
108108
}

src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn make_else_arm(
179179
[(Either::Right(_), _)] => make::literal_pat("false").into(),
180180
_ => make::wildcard_pat().into(),
181181
};
182-
(pattern, make::expr_unit())
182+
(pattern, make::ext::expr_unit())
183183
};
184184
make::match_arm(iter::once(pattern), None, expr)
185185
}

src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
6161
}
6262
}
6363
None => {
64-
let empty_tuple = make::expr_unit();
64+
let empty_tuple = make::ext::expr_unit();
6565
make::let_stmt(pattern, ty, Some(empty_tuple)).to_string()
6666
}
6767
};

src/tools/rust-analyzer/crates/syntax/src/ast/edit.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ impl<N: AstNode + Clone> AstNodeEdit for N {}
153153
#[test]
154154
fn test_increase_indent() {
155155
let arm_list = {
156-
let arm = make::match_arm(iter::once(make::wildcard_pat().into()), None, make::expr_unit());
157-
make::match_arm_list(vec![arm.clone(), arm])
156+
let arm =
157+
make::match_arm(iter::once(make::wildcard_pat().into()), None, make::ext::expr_unit());
158+
make::match_arm_list([arm.clone(), arm])
158159
};
159160
assert_eq!(
160161
arm_list.syntax().to_string(),

src/tools/rust-analyzer/crates/syntax/src/ast/make.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub mod ext {
6363
Some(expr)
6464
}
6565

66+
pub fn expr_unit() -> ast::Expr {
67+
expr_tuple([]).into()
68+
}
6669
pub fn expr_unreachable() -> ast::Expr {
6770
expr_from_text("unreachable!()")
6871
}
@@ -546,10 +549,6 @@ pub fn hacky_block_expr(
546549
ast_from_text(&format!("fn f() {buf}"))
547550
}
548551

549-
pub fn expr_unit() -> ast::Expr {
550-
expr_from_text("()")
551-
}
552-
553552
pub fn expr_literal(text: &str) -> ast::Literal {
554553
assert_eq!(text.trim(), text);
555554
ast_from_text(&format!("fn f() {{ let _ = {text}; }}"))

src/tools/rust-analyzer/crates/syntax/src/syntax_editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ mod tests {
550550
None,
551551
None,
552552
make::param_list(None, []),
553-
make::block_expr([], Some(make::expr_unit())),
553+
make::block_expr([], Some(make::ext::expr_unit())),
554554
Some(make::ret_type(make::ty_unit())),
555555
false,
556556
false,

0 commit comments

Comments
 (0)