Unnamed repository; edit this file 'description' to name the repository.
fix: remove space within `{}` when no fields in struct
roife 2024-04-20
parent 4357698 · commit aa1f134
-rw-r--r--crates/hir/src/display.rs24
-rw-r--r--crates/ide/src/hover/tests.rs22
2 files changed, 35 insertions, 11 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index 1c3eac1590..c276e87786 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -249,19 +249,23 @@ fn display_fields(
}
} else {
f.write_char('{')?;
- f.write_char(separator)?;
- for field in &fields[..count] {
- f.write_str(indent)?;
- field.hir_fmt(f)?;
- f.write_char(',')?;
- f.write_char(separator)?;
- }
- if fields.len() > count {
- f.write_str(indent)?;
- f.write_str("/* … */")?;
+ if !fields.is_empty() {
f.write_char(separator)?;
+ for field in &fields[..count] {
+ f.write_str(indent)?;
+ field.hir_fmt(f)?;
+ f.write_char(',')?;
+ f.write_char(separator)?;
+ }
+
+ if fields.len() > count {
+ f.write_str(indent)?;
+ f.write_str("/* … */")?;
+ f.write_char(separator)?;
+ }
}
+
f.write_str("}")?;
}
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index ff3258b4db..52e57d7889 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -1039,7 +1039,27 @@ fn hover_record_struct_limit() {
struct Foo { /* … */ }
```
"#]],
- )
+ );
+
+ // No extra spaces within `{}` when there are no fields
+ check_hover_fields_limit(
+ 5,
+ r#"
+ struct Foo$0 {}
+ "#,
+ expect![[r#"
+ *Foo*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ // size = 0, align = 1
+ struct Foo {}
+ ```
+ "#]],
+ );
}
#[test]