Skip to content

Commit 02c7b8b

Browse files
committed
Add MethodCallExpr::get_or_create_generic_arg_list
Mirrors `PathSegment's` version, except that it always generates a turbofish
1 parent 3b7c7f9 commit 02c7b8b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

crates/syntax/src/ast/edit_in_place.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
SyntaxNode, SyntaxToken,
1515
};
1616

17-
use super::HasName;
17+
use super::{HasArgList, HasName};
1818

1919
pub trait GenericParamsOwnerEdit: ast::HasGenericParams {
2020
fn get_or_create_generic_param_list(&self) -> ast::GenericParamList;
@@ -362,6 +362,24 @@ impl ast::PathSegment {
362362
}
363363
}
364364

365+
impl ast::MethodCallExpr {
366+
pub fn get_or_create_generic_arg_list(&self) -> ast::GenericArgList {
367+
if self.generic_arg_list().is_none() {
368+
let generic_arg_list = make::turbofish_generic_arg_list(empty()).clone_for_update();
369+
370+
if let Some(arg_list) = self.arg_list() {
371+
ted::insert_raw(
372+
ted::Position::before(arg_list.syntax()),
373+
generic_arg_list.syntax(),
374+
);
375+
} else {
376+
ted::append_child(self.syntax(), generic_arg_list.syntax());
377+
}
378+
}
379+
self.generic_arg_list().unwrap()
380+
}
381+
}
382+
365383
impl Removable for ast::UseTree {
366384
fn remove(&self) {
367385
for dir in [Direction::Next, Direction::Prev] {

crates/syntax/src/ast/make.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,13 @@ pub fn lifetime_arg(lifetime: ast::Lifetime) -> ast::LifetimeArg {
941941
ast_from_text(&format!("const S: T<{lifetime}> = ();"))
942942
}
943943

944+
pub fn turbofish_generic_arg_list(
945+
args: impl IntoIterator<Item = ast::GenericArg>,
946+
) -> ast::GenericArgList {
947+
let args = args.into_iter().join(", ");
948+
ast_from_text(&format!("const S: T::<{args}> = ();"))
949+
}
950+
944951
pub(crate) fn generic_arg_list(
945952
args: impl IntoIterator<Item = ast::GenericArg>,
946953
) -> ast::GenericArgList {

0 commit comments

Comments
 (0)