From 4a4d9f7a90dc0605992c4f774a8d9a1323ad6d1e Mon Sep 17 00:00:00 2001 From: krk Date: Thu, 31 Oct 2019 21:10:58 +0100 Subject: Handle IfLet in convert_to_guarded_return. --- crates/ra_syntax/src/ast/make.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/ra_syntax/src/ast/make.rs') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 3d5f18bfa..979819d4b 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -110,6 +110,22 @@ pub fn match_arm_list(arms: impl Iterator) -> ast::MatchAr } } +pub fn let_match_early(expr: ast::Expr, early_expression: &str) -> ast::LetStmt { + return from_text(&format!( + r#"let {} = match {} {{ + Some(it) => it, + None => {}, +}};"#, + expr.syntax().text(), + expr.syntax().text(), + early_expression + )); + + fn from_text(text: &str) -> ast::LetStmt { + ast_from_text(&format!("fn f() {{ {} }}", text)) + } +} + pub fn where_pred(path: ast::Path, bounds: impl Iterator) -> ast::WherePred { let bounds = bounds.map(|b| b.syntax().to_string()).join(" + "); return from_text(&format!("{}: {}", path.syntax(), bounds)); -- cgit v1.2.3 From 91ab3f876020872f1f692577792569b7b6c8239d Mon Sep 17 00:00:00 2001 From: krk Date: Fri, 1 Nov 2019 18:18:58 +0100 Subject: Support paths other than "Some". --- crates/ra_syntax/src/ast/make.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast/make.rs') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 979819d4b..95062ef6c 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -110,14 +110,15 @@ pub fn match_arm_list(arms: impl Iterator) -> ast::MatchAr } } -pub fn let_match_early(expr: ast::Expr, early_expression: &str) -> ast::LetStmt { +pub fn let_match_early(expr: ast::Expr, path: &str, early_expression: &str) -> ast::LetStmt { return from_text(&format!( r#"let {} = match {} {{ - Some(it) => it, + {}(it) => it, None => {}, }};"#, expr.syntax().text(), expr.syntax().text(), + path, early_expression )); -- cgit v1.2.3