Skip to content

Commit e0aa8d4

Browse files
authored
Merge pull request #20626 from A4-Tacks/make-record-ws
Improve make::struct_ field_list whitespace
2 parents a53b444 + 7e2dc40 commit e0aa8d4

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ macro_rules! foo {
478478
};
479479
}
480480
481-
struct TheVariant{ the_field: u8 }
481+
struct TheVariant { the_field: u8 }
482482
483483
enum TheEnum {
484484
TheVariant(TheVariant),
@@ -502,7 +502,7 @@ enum Foo {
502502
}
503503
"#,
504504
r#"
505-
struct Bar{ node: Box<Foo> }
505+
struct Bar { node: Box<Foo> }
506506
507507
enum Foo {
508508
Bar(Bar),
@@ -519,7 +519,7 @@ enum Foo {
519519
}
520520
"#,
521521
r#"
522-
struct Bar{ node: Box<Foo>, a: Arc<Box<Foo>> }
522+
struct Bar { node: Box<Foo>, a: Arc<Box<Foo>> }
523523
524524
enum Foo {
525525
Bar(Bar),
@@ -560,7 +560,7 @@ enum A { One(One) }"#,
560560
check_assist(
561561
extract_struct_from_enum_variant,
562562
"enum A { $0One { foo: u32, bar: u32 } }",
563-
r#"struct One{ foo: u32, bar: u32 }
563+
r#"struct One { foo: u32, bar: u32 }
564564
565565
enum A { One(One) }"#,
566566
);
@@ -571,7 +571,7 @@ enum A { One(One) }"#,
571571
check_assist(
572572
extract_struct_from_enum_variant,
573573
"enum A { $0One { foo: u32 } }",
574-
r#"struct One{ foo: u32 }
574+
r#"struct One { foo: u32 }
575575
576576
enum A { One(One) }"#,
577577
);
@@ -582,7 +582,7 @@ enum A { One(One) }"#,
582582
check_assist(
583583
extract_struct_from_enum_variant,
584584
r"enum En<T> { Var { a: T$0 } }",
585-
r#"struct Var<T>{ a: T }
585+
r#"struct Var<T> { a: T }
586586
587587
enum En<T> { Var(Var<T>) }"#,
588588
);
@@ -599,7 +599,7 @@ enum Enum { Variant{ field: u32$0 } }"#,
599599
r#"
600600
#[derive(Debug)]
601601
#[derive(Clone)]
602-
struct Variant{ field: u32 }
602+
struct Variant { field: u32 }
603603
604604
#[derive(Debug)]
605605
#[derive(Clone)]
@@ -618,7 +618,7 @@ enum Enum {
618618
}
619619
}"#,
620620
r#"
621-
struct Variant{
621+
struct Variant {
622622
field: u32
623623
}
624624
@@ -642,7 +642,7 @@ mod indenting {
642642
}"#,
643643
r#"
644644
mod indenting {
645-
struct Variant{
645+
struct Variant {
646646
field: u32
647647
}
648648
@@ -668,7 +668,7 @@ enum A {
668668
}
669669
}"#,
670670
r#"
671-
struct One{
671+
struct One {
672672
// leading comment
673673
/// doc comment
674674
#[an_attr]
@@ -700,7 +700,7 @@ enum A {
700700
}
701701
}"#,
702702
r#"
703-
struct One{
703+
struct One {
704704
// comment
705705
/// doc
706706
#[attr]
@@ -747,7 +747,7 @@ enum A {
747747
/* comment */
748748
// other
749749
/// comment
750-
struct One{
750+
struct One {
751751
a: u32
752752
}
753753
@@ -789,7 +789,7 @@ enum A {
789789
extract_struct_from_enum_variant,
790790
"enum A { $0One{ a: u32, pub(crate) b: u32, pub(super) c: u32, d: u32 } }",
791791
r#"
792-
struct One{ a: u32, pub(crate) b: u32, pub(super) c: u32, d: u32 }
792+
struct One { a: u32, pub(crate) b: u32, pub(super) c: u32, d: u32 }
793793
794794
enum A { One(One) }"#,
795795
);
@@ -850,7 +850,7 @@ pub enum A { One(One) }"#,
850850
extract_struct_from_enum_variant,
851851
"pub(in something) enum A { $0One{ a: u32, b: u32 } }",
852852
r#"
853-
pub(in something) struct One{ pub(in something) a: u32, pub(in something) b: u32 }
853+
pub(in something) struct One { pub(in something) a: u32, pub(in something) b: u32 }
854854
855855
pub(in something) enum A { One(One) }"#,
856856
);
@@ -862,7 +862,7 @@ pub(in something) enum A { One(One) }"#,
862862
extract_struct_from_enum_variant,
863863
"pub(crate) enum A { $0One{ a: u32, b: u32, c: u32 } }",
864864
r#"
865-
pub(crate) struct One{ pub(crate) a: u32, pub(crate) b: u32, pub(crate) c: u32 }
865+
pub(crate) struct One { pub(crate) a: u32, pub(crate) b: u32, pub(crate) c: u32 }
866866
867867
pub(crate) enum A { One(One) }"#,
868868
);
@@ -933,7 +933,7 @@ fn f() {
933933
}
934934
"#,
935935
r#"
936-
struct V{ i: i32, j: i32 }
936+
struct V { i: i32, j: i32 }
937937
938938
enum E {
939939
V(V)
@@ -1027,7 +1027,7 @@ fn f() {
10271027
"#,
10281028
r#"
10291029
//- /main.rs
1030-
struct V{ i: i32, j: i32 }
1030+
struct V { i: i32, j: i32 }
10311031
10321032
enum E {
10331033
V(V)
@@ -1057,7 +1057,7 @@ fn foo() {
10571057
}
10581058
"#,
10591059
r#"
1060-
struct One{ a: u32, b: u32 }
1060+
struct One { a: u32, b: u32 }
10611061
10621062
enum A { One(One) }
10631063
@@ -1114,7 +1114,7 @@ enum X<'a, 'b, 'x> {
11141114
}
11151115
"#,
11161116
r#"
1117-
struct A<'a, 'x>{ a: &'a &'x mut () }
1117+
struct A<'a, 'x> { a: &'a &'x mut () }
11181118
11191119
enum X<'a, 'b, 'x> {
11201120
A(A<'a, 'x>),
@@ -1136,7 +1136,7 @@ enum X<'b, T, V, const C: usize> {
11361136
}
11371137
"#,
11381138
r#"
1139-
struct A<'b, T, const C: usize>{ a: T, b: X<'b>, c: [u8; C] }
1139+
struct A<'b, T, const C: usize> { a: T, b: X<'b>, c: [u8; C] }
11401140
11411141
enum X<'b, T, V, const C: usize> {
11421142
A(A<'b, T, C>),
@@ -1158,7 +1158,7 @@ enum X<'a, 'b> {
11581158
}
11591159
"#,
11601160
r#"
1161-
struct C{ c: () }
1161+
struct C { c: () }
11621162
11631163
enum X<'a, 'b> {
11641164
A { a: &'a () },
@@ -1180,7 +1180,7 @@ enum En<T: TraitT, V: TraitV> {
11801180
}
11811181
"#,
11821182
r#"
1183-
struct A<T: TraitT>{ a: T }
1183+
struct A<T: TraitT> { a: T }
11841184
11851185
enum En<T: TraitT, V: TraitV> {
11861186
A(A<T>),

crates/ide-diagnostics/src/handlers/json_is_not_rust.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod tests {
233233
}
234234
235235
#[derive(Serialize)]
236-
struct Root1{ bar: f64, bay: i64, baz: (), r#box: bool, foo: String }
236+
struct Root1 { bar: f64, bay: i64, baz: (), r#box: bool, foo: String }
237237
238238
"#,
239239
);
@@ -252,9 +252,9 @@ mod tests {
252252
}
253253
"#,
254254
r#"
255-
struct Value1{ }
256-
struct Bar1{ kind: String, value: Value1 }
257-
struct Root1{ bar: Bar1, foo: String }
255+
struct Value1 { }
256+
struct Bar1 { kind: String, value: Value1 }
257+
struct Root1 { bar: Bar1, foo: String }
258258
259259
"#,
260260
);
@@ -284,12 +284,12 @@ mod tests {
284284
}
285285
"#,
286286
r#"
287-
struct Address1{ house: i64, street: String }
288-
struct User1{ address: Address1, email: String }
289-
struct AnotherUser1{ user: User1 }
290-
struct Address2{ house: i64, street: String }
291-
struct User2{ address: Address2, email: String }
292-
struct Root1{ another_user: AnotherUser1, user: User2 }
287+
struct Address1 { house: i64, street: String }
288+
struct User1 { address: Address1, email: String }
289+
struct AnotherUser1 { user: User1 }
290+
struct Address2 { house: i64, street: String }
291+
struct User2 { address: Address2, email: String }
292+
struct Root1 { another_user: AnotherUser1, user: User2 }
293293
294294
"#,
295295
);
@@ -326,9 +326,9 @@ mod tests {
326326
use serde::Deserialize;
327327
328328
#[derive(Serialize, Deserialize)]
329-
struct OfObject1{ x: i64, y: i64 }
329+
struct OfObject1 { x: i64, y: i64 }
330330
#[derive(Serialize, Deserialize)]
331-
struct Root1{ empty: Vec<_>, nested: Vec<Vec<Vec<i64>>>, of_object: Vec<OfObject1>, of_string: Vec<String> }
331+
struct Root1 { empty: Vec<_>, nested: Vec<Vec<Vec<i64>>>, of_object: Vec<OfObject1>, of_string: Vec<String> }
332332
333333
"#,
334334
);

crates/syntax/src/ast/make.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,14 +1244,17 @@ pub fn struct_(
12441244
generic_param_list: Option<ast::GenericParamList>,
12451245
field_list: ast::FieldList,
12461246
) -> ast::Struct {
1247-
let semicolon = if matches!(field_list, ast::FieldList::TupleFieldList(_)) { ";" } else { "" };
1247+
let (semicolon, ws) =
1248+
if matches!(field_list, ast::FieldList::TupleFieldList(_)) { (";", "") } else { ("", " ") };
12481249
let type_params = generic_param_list.map_or_else(String::new, |it| it.to_string());
12491250
let visibility = match visibility {
12501251
None => String::new(),
12511252
Some(it) => format!("{it} "),
12521253
};
12531254

1254-
ast_from_text(&format!("{visibility}struct {strukt_name}{type_params}{field_list}{semicolon}",))
1255+
ast_from_text(&format!(
1256+
"{visibility}struct {strukt_name}{type_params}{ws}{field_list}{semicolon}"
1257+
))
12551258
}
12561259

12571260
pub fn enum_(

0 commit comments

Comments
 (0)