Make make:: builders slightly more convenient

This commit is contained in:
Aleksey Kladov 2019-11-13 11:55:43 +03:00
parent e177c65e36
commit 4cea6bb6f1
2 changed files with 12 additions and 9 deletions

View file

@ -358,7 +358,7 @@ fn replace_children<N: AstNode>(
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(),

View file

@ -84,9 +84,9 @@ pub fn placeholder_pat() -> ast::PlaceholderPat {
pub fn tuple_struct_pat(
path: ast::Path,
pats: impl Iterator<Item = ast::Pat>,
pats: impl IntoIterator<Item = ast::Pat>,
) -> 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<Item = ast::Pat>) -> ast::RecordPat {
let pats_str = pats.map(|p| p.syntax().to_string()).join(", ");
pub fn record_pat(path: ast::Path, pats: impl IntoIterator<Item = ast::Pat>) -> 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<Item = ast::MatchArm>) -> ast::Mat
}
}
pub fn where_pred(path: ast::Path, bounds: impl Iterator<Item = ast::TypeBound>) -> ast::WherePred {
let bounds = bounds.map(|b| b.syntax().to_string()).join(" + ");
pub fn where_pred(
path: ast::Path,
bounds: impl IntoIterator<Item = ast::TypeBound>,
) -> 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<Item = ast::TypeBound>)
}
}
pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereClause {
let preds = preds.map(|p| p.syntax().to_string()).join(", ");
pub fn where_clause(preds: impl IntoIterator<Item = ast::WherePred>) -> 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 {