Skip to content

Commit 4f89b20

Browse files
committed
fix: using {} for empty struct && remove semicolon for struct with tuple kind
1 parent 46af7d3 commit 4f89b20

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

crates/hir/src/display.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,24 @@ impl HirDisplay for Struct {
177177
}
178178
}
179179

180-
f.write_str(");")?;
180+
f.write_str(")")?;
181181
}
182182

183183
write_where_clause(def_id, f)?;
184184

185185
if let StructKind::Record = variant_data.kind() {
186-
f.write_str(" {\n")?;
187-
for field in self.fields(f.db) {
188-
f.write_str(" ")?;
189-
field.hir_fmt(f)?;
190-
f.write_str(",\n")?;
186+
let fields = self.fields(f.db);
187+
if fields.is_empty() {
188+
f.write_str(" {}")?;
189+
} else {
190+
f.write_str(" {\n")?;
191+
for field in self.fields(f.db) {
192+
f.write_str(" ")?;
193+
field.hir_fmt(f)?;
194+
f.write_str(",\n")?;
195+
}
196+
f.write_str("}")?;
191197
}
192-
f.write_str("}")?;
193198
}
194199

195200
Ok(())

crates/ide/src/hover/tests.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
24032403
focus_range: 7..10,
24042404
name: "Arg",
24052405
kind: Struct,
2406-
description: "struct Arg(u32);",
2406+
description: "struct Arg(u32)",
24072407
},
24082408
},
24092409
],
@@ -2462,7 +2462,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
24622462
focus_range: 7..10,
24632463
name: "Arg",
24642464
kind: Struct,
2465-
description: "struct Arg(u32);",
2465+
description: "struct Arg(u32)",
24662466
},
24672467
},
24682468
],
@@ -2498,7 +2498,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
24982498
focus_range: 7..8,
24992499
name: "A",
25002500
kind: Struct,
2501-
description: "struct A(u32);",
2501+
description: "struct A(u32)",
25022502
},
25032503
},
25042504
HoverGotoTypeData {
@@ -2511,7 +2511,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
25112511
focus_range: 22..23,
25122512
name: "B",
25132513
kind: Struct,
2514-
description: "struct B(u32);",
2514+
description: "struct B(u32)",
25152515
},
25162516
},
25172517
HoverGotoTypeData {
@@ -2525,7 +2525,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
25252525
name: "C",
25262526
kind: Struct,
25272527
container_name: "M",
2528-
description: "pub struct C(u32);",
2528+
description: "pub struct C(u32)",
25292529
},
25302530
},
25312531
],
@@ -2715,7 +2715,7 @@ fn main() { let s$0t = foo(); }
27152715
focus_range: 39..41,
27162716
name: "S1",
27172717
kind: Struct,
2718-
description: "struct S1 {\n}",
2718+
description: "struct S1 {}",
27192719
},
27202720
},
27212721
HoverGotoTypeData {
@@ -2728,7 +2728,7 @@ fn main() { let s$0t = foo(); }
27282728
focus_range: 52..54,
27292729
name: "S2",
27302730
kind: Struct,
2731-
description: "struct S2 {\n}",
2731+
description: "struct S2 {}",
27322732
},
27332733
},
27342734
],
@@ -2819,7 +2819,7 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {}
28192819
focus_range: 36..37,
28202820
name: "S",
28212821
kind: Struct,
2822-
description: "struct S {\n}",
2822+
description: "struct S {}",
28232823
},
28242824
},
28252825
],
@@ -2919,7 +2919,7 @@ fn foo(ar$0g: &impl Foo<S>) {}
29192919
focus_range: 23..24,
29202920
name: "S",
29212921
kind: Struct,
2922-
description: "struct S {\n}",
2922+
description: "struct S {}",
29232923
},
29242924
},
29252925
],
@@ -2956,7 +2956,7 @@ fn main() { let s$0t = foo(); }
29562956
focus_range: 49..50,
29572957
name: "B",
29582958
kind: Struct,
2959-
description: "struct B<T> {\n}",
2959+
description: "struct B<T> {}",
29602960
},
29612961
},
29622962
HoverGotoTypeData {
@@ -3045,7 +3045,7 @@ fn foo(ar$0g: &dyn Foo<S>) {}
30453045
focus_range: 23..24,
30463046
name: "S",
30473047
kind: Struct,
3048-
description: "struct S {\n}",
3048+
description: "struct S {}",
30493049
},
30503050
},
30513051
],
@@ -3093,7 +3093,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
30933093
focus_range: 50..51,
30943094
name: "B",
30953095
kind: Struct,
3096-
description: "struct B<T> {\n}",
3096+
description: "struct B<T> {}",
30973097
},
30983098
},
30993099
HoverGotoTypeData {
@@ -3119,7 +3119,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
31193119
focus_range: 65..66,
31203120
name: "S",
31213121
kind: Struct,
3122-
description: "struct S {\n}",
3122+
description: "struct S {}",
31233123
},
31243124
},
31253125
],
@@ -3346,7 +3346,7 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
33463346
```
33473347
33483348
```rust
3349-
struct ST<const C: usize = 1, T = Foo>(T);
3349+
struct ST<const C: usize = 1, T = Foo>(T)
33503350
```
33513351
"#]],
33523352
);
@@ -3367,7 +3367,7 @@ struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
33673367
```
33683368
33693369
```rust
3370-
struct ST<const C: usize = {const}, T = Foo>(T);
3370+
struct ST<const C: usize = {const}, T = Foo>(T)
33713371
```
33723372
"#]],
33733373
);
@@ -3389,7 +3389,7 @@ struct S$0T<const C: usize = VAL, T = Foo>(T);
33893389
```
33903390
33913391
```rust
3392-
struct ST<const C: usize = VAL, T = Foo>(T);
3392+
struct ST<const C: usize = VAL, T = Foo>(T)
33933393
```
33943394
"#]],
33953395
);
@@ -5946,7 +5946,7 @@ pub struct Foo(i32);
59465946
```
59475947
59485948
```rust
5949-
pub struct Foo(i32); // size = 4, align = 4
5949+
pub struct Foo(i32) // size = 4, align = 4
59505950
```
59515951
59525952
---

0 commit comments

Comments
 (0)