]> git.lizzy.rs Git - rust.git/commitdiff
fix: don't add extra whitespace around fields
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 17 May 2021 09:41:48 +0000 (12:41 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 17 May 2021 09:45:01 +0000 (12:45 +0300)
closes #8785

crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
crates/syntax/src/ast/edit_in_place.rs

index 123c2f0af0762d1b4f1ac0c64e865b53c7a4e65e..37a0e37a9f65ea3d2e99655e1fddfa4d5bfcbc72 100644 (file)
@@ -186,6 +186,31 @@ fn test_fn() {
     let one = 1;
     let s = TestStruct{ ..a };
 }
+"#,
+        );
+    }
+
+    #[test]
+    fn test_fill_struct_fields_blank_line() {
+        check_fix(
+            r#"
+struct S { a: (), b: () }
+
+fn f() {
+    S {
+        $0
+    };
+}
+"#,
+            r#"
+struct S { a: (), b: () }
+
+fn f() {
+    S {
+        a: (),
+        b: (),
+    };
+}
 "#,
         );
     }
index 14624c68252c745b0d50a0e7f33970aa78f0e816..2676ed8c981e865971e40802c3056e1054db2790 100644 (file)
@@ -378,6 +378,10 @@ pub fn add_field(&self, field: ast::RecordExprField) {
             make::tokens::single_space()
         };
 
+        if is_multiline {
+            normalize_ws_between_braces(self.syntax());
+        }
+
         let position = match self.fields().last() {
             Some(last_field) => {
                 let comma = match last_field