diff options
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/ast/make.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 3a184094c..74dbdfaf7 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -320,6 +320,10 @@ pub fn param(name: String, ty: String) -> ast::Param { | |||
320 | ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty)) | 320 | ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty)) |
321 | } | 321 | } |
322 | 322 | ||
323 | pub fn ret_type(ty: ast::Type) -> ast::RetType { | ||
324 | ast_from_text(&format!("fn f() -> {} {{ }}", ty)) | ||
325 | } | ||
326 | |||
323 | pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList { | 327 | pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList { |
324 | let args = pats.into_iter().join(", "); | 328 | let args = pats.into_iter().join(", "); |
325 | ast_from_text(&format!("fn f({}) {{ }}", args)) | 329 | ast_from_text(&format!("fn f({}) {{ }}", args)) |
@@ -350,14 +354,20 @@ pub fn fn_( | |||
350 | type_params: Option<ast::GenericParamList>, | 354 | type_params: Option<ast::GenericParamList>, |
351 | params: ast::ParamList, | 355 | params: ast::ParamList, |
352 | body: ast::BlockExpr, | 356 | body: ast::BlockExpr, |
357 | ret_type: Option<ast::RetType>, | ||
353 | ) -> ast::Fn { | 358 | ) -> ast::Fn { |
354 | let type_params = | 359 | let type_params = |
355 | if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; | 360 | if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; |
361 | let ret_type = if let Some(ret_type) = ret_type { format!("{} ", ret_type) } else { "".into() }; | ||
356 | let visibility = match visibility { | 362 | let visibility = match visibility { |
357 | None => String::new(), | 363 | None => String::new(), |
358 | Some(it) => format!("{} ", it), | 364 | Some(it) => format!("{} ", it), |
359 | }; | 365 | }; |
360 | ast_from_text(&format!("{}fn {}{}{} {}", visibility, fn_name, type_params, params, body)) | 366 | |
367 | ast_from_text(&format!( | ||
368 | "{}fn {}{}{} {}{}", | ||
369 | visibility, fn_name, type_params, params, ret_type, body | ||
370 | )) | ||
361 | } | 371 | } |
362 | 372 | ||
363 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 373 | fn ast_from_text<N: AstNode>(text: &str) -> N { |