Merge pull request #19568 from snprajwal/destructure-struct-editor

refactor: editor for `destructure_struct_binding`
This commit is contained in:
Lukas Wirth 2025-04-14 15:35:00 +00:00 committed by GitHub
commit 7fc29a99ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 76 additions and 99 deletions

View file

@ -643,8 +643,8 @@ pub fn expr_method_call(
) -> ast::MethodCallExpr {
expr_from_text(&format!("{receiver}.{method}{arg_list}"))
}
pub fn expr_macro_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
expr_from_text(&format!("{f}!{arg_list}"))
pub fn expr_macro(path: ast::Path, arg_list: ast::ArgList) -> ast::MacroExpr {
expr_from_text(&format!("{path}!{arg_list}"))
}
pub fn expr_ref(expr: ast::Expr, exclusive: bool) -> ast::Expr {
expr_from_text(&if exclusive { format!("&mut {expr}") } else { format!("&{expr}") })

View file

@ -241,7 +241,7 @@ impl SyntaxFactory {
ast
}
pub fn record_pat_field(self, name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPatField {
pub fn record_pat_field(&self, name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPatField {
let ast = make::record_pat_field(name_ref.clone(), pat.clone()).clone_for_update();
if let Some(mut mapping) = self.mappings() {
@ -290,6 +290,10 @@ impl SyntaxFactory {
ast
}
pub fn rest_pat(&self) -> ast::RestPat {
make::rest_pat().clone_for_update()
}
pub fn block_expr(
&self,
statements: impl IntoIterator<Item = ast::Stmt>,
@ -580,6 +584,21 @@ impl SyntaxFactory {
ast
}
pub fn expr_macro(&self, path: ast::Path, args: ast::ArgList) -> ast::MacroExpr {
let ast = make::expr_macro(path.clone(), args.clone()).clone_for_update();
if let Some(mut mapping) = self.mappings() {
let macro_call = ast.macro_call().unwrap();
let mut builder = SyntaxMappingBuilder::new(macro_call.syntax().clone());
builder.map_node(path.syntax().clone(), macro_call.path().unwrap().syntax().clone());
builder
.map_node(args.syntax().clone(), macro_call.token_tree().unwrap().syntax().clone());
builder.finish(&mut mapping);
}
ast
}
pub fn match_arm(
&self,
pat: ast::Pat,