aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/diagnostics/fixes/fill_missing_fields.rs25
-rw-r--r--crates/ide/src/diagnostics/fixes/remove_semicolon.rs10
-rw-r--r--crates/ide/src/diagnostics/fixes/replace_with_find_map.rs42
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs4
4 files changed, 81 insertions, 0 deletions
diff --git a/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs b/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
index 123c2f0af..37a0e37a9 100644
--- a/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
+++ b/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
@@ -189,4 +189,29 @@ fn test_fn() {
189"#, 189"#,
190 ); 190 );
191 } 191 }
192
193 #[test]
194 fn test_fill_struct_fields_blank_line() {
195 check_fix(
196 r#"
197struct S { a: (), b: () }
198
199fn f() {
200 S {
201 $0
202 };
203}
204"#,
205 r#"
206struct S { a: (), b: () }
207
208fn f() {
209 S {
210 a: (),
211 b: (),
212 };
213}
214"#,
215 );
216 }
192} 217}
diff --git a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs
index 058002c69..45471da41 100644
--- a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs
+++ b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs
@@ -29,3 +29,13 @@ impl DiagnosticWithFix for RemoveThisSemicolon {
29 Some(fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)) 29 Some(fix("remove_semicolon", "Remove this semicolon", source_change, semicolon))
30 } 30 }
31} 31}
32
33#[cfg(test)]
34mod tests {
35 use crate::diagnostics::tests::check_fix;
36
37 #[test]
38 fn remove_semicolon() {
39 check_fix(r#"fn f() -> i32 { 92$0; }"#, r#"fn f() -> i32 { 92 }"#);
40 }
41}
diff --git a/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs b/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs
index 5ddfd2064..b0ef7b44a 100644
--- a/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs
+++ b/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs
@@ -40,3 +40,45 @@ impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap {
40 )) 40 ))
41 } 41 }
42} 42}
43
44#[cfg(test)]
45mod tests {
46 use crate::diagnostics::tests::check_fix;
47
48 #[test]
49 fn replace_with_wind_map() {
50 check_fix(
51 r#"
52//- /main.rs crate:main deps:core
53use core::iter::Iterator;
54use core::option::Option::{self, Some, None};
55fn foo() {
56 let m = [1, 2, 3].iter().$0filter_map(|x| if *x == 2 { Some (4) } else { None }).next();
57}
58//- /core/lib.rs crate:core
59pub mod option {
60 pub enum Option<T> { Some(T), None }
61}
62pub mod iter {
63 pub trait Iterator {
64 type Item;
65 fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
66 fn next(&mut self) -> Option<Self::Item>;
67 }
68 pub struct FilterMap {}
69 impl Iterator for FilterMap {
70 type Item = i32;
71 fn next(&mut self) -> i32 { 7 }
72 }
73}
74"#,
75 r#"
76use core::iter::Iterator;
77use core::option::Option::{self, Some, None};
78fn foo() {
79 let m = [1, 2, 3].iter().find_map(|x| if *x == 2 { Some (4) } else { None });
80}
81"#,
82 )
83 }
84}
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index 14624c682..2676ed8c9 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -378,6 +378,10 @@ impl ast::RecordExprFieldList {
378 make::tokens::single_space() 378 make::tokens::single_space()
379 }; 379 };
380 380
381 if is_multiline {
382 normalize_ws_between_braces(self.syntax());
383 }
384
381 let position = match self.fields().last() { 385 let position = match self.fields().last() {
382 Some(last_field) => { 386 Some(last_field) => {
383 let comma = match last_field 387 let comma = match last_field