Skip to content

Commit aa1f134

Browse files
committed
fix: remove space within {} when no fields in struct
1 parent 4357698 commit aa1f134

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

crates/hir/src/display.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,23 @@ fn display_fields(
249249
}
250250
} else {
251251
f.write_char('{')?;
252-
f.write_char(separator)?;
253-
for field in &fields[..count] {
254-
f.write_str(indent)?;
255-
field.hir_fmt(f)?;
256-
f.write_char(',')?;
257-
f.write_char(separator)?;
258-
}
259252

260-
if fields.len() > count {
261-
f.write_str(indent)?;
262-
f.write_str("/* … */")?;
253+
if !fields.is_empty() {
263254
f.write_char(separator)?;
255+
for field in &fields[..count] {
256+
f.write_str(indent)?;
257+
field.hir_fmt(f)?;
258+
f.write_char(',')?;
259+
f.write_char(separator)?;
260+
}
261+
262+
if fields.len() > count {
263+
f.write_str(indent)?;
264+
f.write_str("/* … */")?;
265+
f.write_char(separator)?;
266+
}
264267
}
268+
265269
f.write_str("}")?;
266270
}
267271

crates/ide/src/hover/tests.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,27 @@ fn hover_record_struct_limit() {
10391039
struct Foo { /* … */ }
10401040
```
10411041
"#]],
1042-
)
1042+
);
1043+
1044+
// No extra spaces within `{}` when there are no fields
1045+
check_hover_fields_limit(
1046+
5,
1047+
r#"
1048+
struct Foo$0 {}
1049+
"#,
1050+
expect![[r#"
1051+
*Foo*
1052+
1053+
```rust
1054+
test
1055+
```
1056+
1057+
```rust
1058+
// size = 0, align = 1
1059+
struct Foo {}
1060+
```
1061+
"#]],
1062+
);
10431063
}
10441064

10451065
#[test]

0 commit comments

Comments
 (0)