aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/make.rs16
1 files changed, 16 insertions, 0 deletions
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<Item = ast::MatchArm>) -> ast::MatchAr
110 } 110 }
111} 111}
112 112
113pub fn let_match_early(expr: ast::Expr, early_expression: &str) -> ast::LetStmt {
114 return from_text(&format!(
115 r#"let {} = match {} {{
116 Some(it) => it,
117 None => {},
118}};"#,
119 expr.syntax().text(),
120 expr.syntax().text(),
121 early_expression
122 ));
123
124 fn from_text(text: &str) -> ast::LetStmt {
125 ast_from_text(&format!("fn f() {{ {} }}", text))
126 }
127}
128
113pub fn where_pred(path: ast::Path, bounds: impl Iterator<Item = ast::TypeBound>) -> ast::WherePred { 129pub 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(" + "); 130 let bounds = bounds.map(|b| b.syntax().to_string()).join(" + ");
115 return from_text(&format!("{}: {}", path.syntax(), bounds)); 131 return from_text(&format!("{}: {}", path.syntax(), bounds));