diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-04 09:06:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-04 09:06:53 +0000 |
commit | fe6ba12a772f7fb5d3645b8e1104ccf15b36ed63 (patch) | |
tree | fec106c13469a149c9d51efc867713b17f44f4fa /crates/ra_syntax/src/ast | |
parent | 5c35539f0f69472546253d415c30f524d0a1a212 (diff) | |
parent | bc14f500a0b0e1349d0f795b85dde5946da113bd (diff) |
Merge #2149
2149: Handle IfLet in convert_to_guarded_return. r=matklad a=krk
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/2124
I could not move the cursor position out of `let`:
`le<|>t` vs `let<|>`.
Also, please suggest extra test cases.
Co-authored-by: krk <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 3d5f18bfa..95062ef6c 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -110,6 +110,23 @@ pub fn match_arm_list(arms: impl Iterator<Item = ast::MatchArm>) -> ast::MatchAr | |||
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | pub fn let_match_early(expr: ast::Expr, path: &str, early_expression: &str) -> ast::LetStmt { | ||
114 | return from_text(&format!( | ||
115 | r#"let {} = match {} {{ | ||
116 | {}(it) => it, | ||
117 | None => {}, | ||
118 | }};"#, | ||
119 | expr.syntax().text(), | ||
120 | expr.syntax().text(), | ||
121 | path, | ||
122 | early_expression | ||
123 | )); | ||
124 | |||
125 | fn from_text(text: &str) -> ast::LetStmt { | ||
126 | ast_from_text(&format!("fn f() {{ {} }}", text)) | ||
127 | } | ||
128 | } | ||
129 | |||
113 | pub fn where_pred(path: ast::Path, bounds: impl Iterator<Item = ast::TypeBound>) -> ast::WherePred { | 130 | pub fn where_pred(path: ast::Path, bounds: impl Iterator<Item = ast::TypeBound>) -> ast::WherePred { |
114 | let bounds = bounds.map(|b| b.syntax().to_string()).join(" + "); | 131 | let bounds = bounds.map(|b| b.syntax().to_string()).join(" + "); |
115 | return from_text(&format!("{}: {}", path.syntax(), bounds)); | 132 | return from_text(&format!("{}: {}", path.syntax(), bounds)); |