mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Make make:: builders slightly more convenient
This commit is contained in:
parent
e177c65e36
commit
4cea6bb6f1
2 changed files with 12 additions and 9 deletions
|
@ -358,7 +358,7 @@ fn replace_children<N: AstNode>(
|
||||||
fn test_increase_indent() {
|
fn test_increase_indent() {
|
||||||
let arm_list = {
|
let arm_list = {
|
||||||
let arm = make::match_arm(iter::once(make::placeholder_pat().into()), make::expr_unit());
|
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!(
|
assert_eq!(
|
||||||
arm_list.syntax().to_string(),
|
arm_list.syntax().to_string(),
|
||||||
|
|
|
@ -84,9 +84,9 @@ pub fn placeholder_pat() -> ast::PlaceholderPat {
|
||||||
|
|
||||||
pub fn tuple_struct_pat(
|
pub fn tuple_struct_pat(
|
||||||
path: ast::Path,
|
path: ast::Path,
|
||||||
pats: impl Iterator<Item = ast::Pat>,
|
pats: impl IntoIterator<Item = ast::Pat>,
|
||||||
) -> ast::TupleStructPat {
|
) -> 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));
|
return from_text(&format!("{}({})", path.syntax(), pats_str));
|
||||||
|
|
||||||
fn from_text(text: &str) -> ast::TupleStructPat {
|
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 {
|
pub fn record_pat(path: ast::Path, pats: impl IntoIterator<Item = ast::Pat>) -> ast::RecordPat {
|
||||||
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));
|
return from_text(&format!("{} {{ {} }}", path.syntax(), pats_str));
|
||||||
|
|
||||||
fn from_text(text: &str) -> ast::RecordPat {
|
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 {
|
pub fn where_pred(
|
||||||
let bounds = bounds.map(|b| b.syntax().to_string()).join(" + ");
|
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));
|
return from_text(&format!("{}: {}", path.syntax(), bounds));
|
||||||
|
|
||||||
fn from_text(text: &str) -> ast::WherePred {
|
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 {
|
pub fn where_clause(preds: impl IntoIterator<Item = ast::WherePred>) -> ast::WhereClause {
|
||||||
let preds = preds.map(|p| p.syntax().to_string()).join(", ");
|
let preds = preds.into_iter().map(|p| p.syntax().to_string()).join(", ");
|
||||||
return from_text(preds.as_str());
|
return from_text(preds.as_str());
|
||||||
|
|
||||||
fn from_text(text: &str) -> ast::WhereClause {
|
fn from_text(text: &str) -> ast::WhereClause {
|
||||||
|
|
Loading…
Reference in a new issue