Skip to content

Commit 4de2749

Browse files
committed
Explain the purpose of ast::make module more clearly
1 parent 28f6b5b commit 4de2749

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/ra_assists/src/handlers/replace_unwrap_with_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
5151
let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a")));
5252
let ok_arm = make::match_arm(iter::once(ok_tuple), make::expr_path(bind_path));
5353

54-
let unreachable_call = make::unreachable_macro_call().into();
54+
let unreachable_call = make::expr_unreachable();
5555
let err_arm = make::match_arm(iter::once(make::placeholder_pat().into()), unreachable_call);
5656

5757
let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]);

crates/ra_syntax/src/ast/make.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! This module contains free-standing functions for creating AST fragments out
22
//! of smaller pieces.
3+
//!
4+
//! Note that all functions here intended to be stupid constructors, which just
5+
//! assemble a finish node from immediate children. If you want to do something
6+
//! smarter than that, it probably doesn't belong in this module.
37
use itertools::Itertools;
48
use stdx::format_to;
59

@@ -95,6 +99,9 @@ pub fn expr_empty_block() -> ast::Expr {
9599
pub fn expr_unimplemented() -> ast::Expr {
96100
expr_from_text("unimplemented!()")
97101
}
102+
pub fn expr_unreachable() -> ast::Expr {
103+
expr_from_text("unreachable!()")
104+
}
98105
pub fn expr_todo() -> ast::Expr {
99106
expr_from_text("todo!()")
100107
}
@@ -264,10 +271,6 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken {
264271
.unwrap_or_else(|| panic!("unhandled token: {:?}", kind))
265272
}
266273

267-
pub fn unreachable_macro_call() -> ast::MacroCall {
268-
ast_from_text(&format!("unreachable!()"))
269-
}
270-
271274
pub fn param(name: String, ty: String) -> ast::Param {
272275
ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty))
273276
}

0 commit comments

Comments
 (0)