From 4cea6bb6f11e28a2d1d2e023d46caa82b0f38796 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 13 Nov 2019 11:55:43 +0300 Subject: Make make:: builders slightly more convenient --- crates/ra_syntax/src/ast/edit.rs | 2 +- crates/ra_syntax/src/ast/make.rs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 47bdbb81a..6f005a2d8 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -358,7 +358,7 @@ fn replace_children( fn test_increase_indent() { let arm_list = { let arm = make::match_arm(iter::once(make::placeholder_pat().into()), make::expr_unit()); - make::match_arm_list(vec![arm.clone(), arm].into_iter()) + make::match_arm_list(vec![arm.clone(), arm]) }; assert_eq!( arm_list.syntax().to_string(), diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 6c903ca64..9749327fa 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -84,9 +84,9 @@ pub fn placeholder_pat() -> ast::PlaceholderPat { pub fn tuple_struct_pat( path: ast::Path, - pats: impl Iterator, + pats: impl IntoIterator, ) -> ast::TupleStructPat { - let pats_str = pats.map(|p| p.syntax().to_string()).join(", "); + let pats_str = pats.into_iter().map(|p| p.syntax().to_string()).join(", "); return from_text(&format!("{}({})", path.syntax(), pats_str)); fn from_text(text: &str) -> ast::TupleStructPat { @@ -94,8 +94,8 @@ pub fn tuple_struct_pat( } } -pub fn record_pat(path: ast::Path, pats: impl Iterator) -> ast::RecordPat { - let pats_str = pats.map(|p| p.syntax().to_string()).join(", "); +pub fn record_pat(path: ast::Path, pats: impl IntoIterator) -> ast::RecordPat { + let pats_str = pats.into_iter().map(|p| p.syntax().to_string()).join(", "); return from_text(&format!("{} {{ {} }}", path.syntax(), pats_str)); fn from_text(text: &str) -> ast::RecordPat { @@ -129,8 +129,11 @@ pub fn match_arm_list(arms: impl IntoIterator) -> ast::Mat } } -pub fn where_pred(path: ast::Path, bounds: impl Iterator) -> ast::WherePred { - let bounds = bounds.map(|b| b.syntax().to_string()).join(" + "); +pub fn where_pred( + path: ast::Path, + bounds: impl IntoIterator, +) -> ast::WherePred { + let bounds = bounds.into_iter().map(|b| b.syntax().to_string()).join(" + "); return from_text(&format!("{}: {}", path.syntax(), bounds)); fn from_text(text: &str) -> ast::WherePred { @@ -138,8 +141,8 @@ pub fn where_pred(path: ast::Path, bounds: impl Iterator) } } -pub fn where_clause(preds: impl Iterator) -> ast::WhereClause { - let preds = preds.map(|p| p.syntax().to_string()).join(", "); +pub fn where_clause(preds: impl IntoIterator) -> ast::WhereClause { + let preds = preds.into_iter().map(|p| p.syntax().to_string()).join(", "); return from_text(preds.as_str()); fn from_text(text: &str) -> ast::WhereClause { -- cgit v1.2.3