aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-20 00:28:11 +0100
committerAleksey Kladov <[email protected]>2020-05-20 00:28:46 +0100
commit4de2749db8281c00aba37270fa9ae8d4bd2572d8 (patch)
tree1ec6bea678f9c00b97d4f6dd3b45e88bd1b87d05
parent28f6b5b8493024b87f53ea9be4d517442588b7e5 (diff)
Explain the purpose of `ast::make` module more clearly
-rw-r--r--crates/ra_assists/src/handlers/replace_unwrap_with_match.rs2
-rw-r--r--crates/ra_syntax/src/ast/make.rs11
2 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
index c4b56f6e9..b379b55a8 100644
--- a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
@@ -51,7 +51,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
51 let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a"))); 51 let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a")));
52 let ok_arm = make::match_arm(iter::once(ok_tuple), make::expr_path(bind_path)); 52 let ok_arm = make::match_arm(iter::once(ok_tuple), make::expr_path(bind_path));
53 53
54 let unreachable_call = make::unreachable_macro_call().into(); 54 let unreachable_call = make::expr_unreachable();
55 let err_arm = make::match_arm(iter::once(make::placeholder_pat().into()), unreachable_call); 55 let err_arm = make::match_arm(iter::once(make::placeholder_pat().into()), unreachable_call);
56 56
57 let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]); 57 let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]);
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index d0e960fb4..2db017038 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -1,5 +1,9 @@
1//! This module contains free-standing functions for creating AST fragments out 1//! This module contains free-standing functions for creating AST fragments out
2//! of smaller pieces. 2//! 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.
3use itertools::Itertools; 7use itertools::Itertools;
4use stdx::format_to; 8use stdx::format_to;
5 9
@@ -95,6 +99,9 @@ pub fn expr_empty_block() -> ast::Expr {
95pub fn expr_unimplemented() -> ast::Expr { 99pub fn expr_unimplemented() -> ast::Expr {
96 expr_from_text("unimplemented!()") 100 expr_from_text("unimplemented!()")
97} 101}
102pub fn expr_unreachable() -> ast::Expr {
103 expr_from_text("unreachable!()")
104}
98pub fn expr_todo() -> ast::Expr { 105pub fn expr_todo() -> ast::Expr {
99 expr_from_text("todo!()") 106 expr_from_text("todo!()")
100} 107}
@@ -264,10 +271,6 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken {
264 .unwrap_or_else(|| panic!("unhandled token: {:?}", kind)) 271 .unwrap_or_else(|| panic!("unhandled token: {:?}", kind))
265} 272}
266 273
267pub fn unreachable_macro_call() -> ast::MacroCall {
268 ast_from_text(&format!("unreachable!()"))
269}
270
271pub fn param(name: String, ty: String) -> ast::Param { 274pub fn param(name: String, ty: String) -> ast::Param {
272 ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty)) 275 ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty))
273} 276}