From 1859df37fd6e308ea4304f69baae038ec09fe424 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 May 2021 18:10:56 +0300 Subject: internal: use mutable syntax trees when filling fields --- crates/ide/src/diagnostics.rs | 6 +++--- crates/ide/src/diagnostics/fixes.rs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 273d8cfbb..d5fba6740 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -579,7 +579,7 @@ fn test_fn() { struct TestStruct { one: i32, two: i64 } fn test_fn() { - let s = TestStruct { one: (), two: ()}; + let s = TestStruct { one: (), two: () }; } "#, ); @@ -599,7 +599,7 @@ impl TestStruct { struct TestStruct { one: i32 } impl TestStruct { - fn test_fn() { let s = Self { one: ()}; } + fn test_fn() { let s = Self { one: () }; } } "#, ); @@ -792,7 +792,7 @@ fn main() { pub struct Foo { pub a: i32, pub b: i32 } "#, r#" -fn some(, b: ()) {} +fn some(, b: () ) {} fn items() {} fn here() {} diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 15821500f..695b59e27 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs @@ -100,11 +100,12 @@ impl DiagnosticWithFix for MissingFields { let root = sema.db.parse_or_expand(self.file)?; let field_list_parent = self.field_list_parent.to_node(&root); let old_field_list = field_list_parent.record_expr_field_list()?; - let mut new_field_list = old_field_list.clone(); + let new_field_list = old_field_list.clone_for_update(); for f in self.missed_fields.iter() { let field = - make::record_expr_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); - new_field_list = new_field_list.append_field(&field); + make::record_expr_field(make::name_ref(&f.to_string()), Some(make::expr_unit())) + .clone_for_update(); + new_field_list.add_field(field); } let edit = { -- cgit v1.2.3