diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-22 18:10:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-22 18:10:17 +0100 |
commit | ba95de936df92b3901163249aed4e1bd769021df (patch) | |
tree | d41e817b741475cac2783bf8b6466acc54308472 /crates/ra_syntax/src/ast/make.rs | |
parent | 2dffae6f35ce4b5824df881a5c190daabd3efd3c (diff) | |
parent | fb215dc192005160c70d5026bea7bfd752033292 (diff) |
Merge #1933
1933: Adds "replace with guarded return" assist r=matklad a=mikhail-m1
first draft for #1782. I'm pretty sure I missed something.
Co-authored-by: Mikhail Modin <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 143835172..00422ea91 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -128,6 +128,14 @@ pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereCl | |||
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { | ||
132 | return ast_from_text(&format!( | ||
133 | "fn f() {{ if !{} {{\n {}\n}}\n}}", | ||
134 | condition.syntax().text(), | ||
135 | statement | ||
136 | )); | ||
137 | } | ||
138 | |||
131 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 139 | fn ast_from_text<N: AstNode>(text: &str) -> N { |
132 | let parse = SourceFile::parse(text); | 140 | let parse = SourceFile::parse(text); |
133 | let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); | 141 | let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); |