diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index e8d0a16574..08777b4947 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -177,19 +177,24 @@ impl HirDisplay for Struct { } } - f.write_str(");")?; + f.write_str(")")?; } write_where_clause(def_id, f)?; if let StructKind::Record = variant_data.kind() { - f.write_str(" {\n")?; - for field in self.fields(f.db) { - f.write_str(" ")?; - field.hir_fmt(f)?; - f.write_str(",\n")?; + let fields = self.fields(f.db); + if fields.is_empty() { + f.write_str(" {}")?; + } else { + f.write_str(" {\n")?; + for field in self.fields(f.db) { + f.write_str(" ")?; + field.hir_fmt(f)?; + f.write_str(",\n")?; + } + f.write_str("}")?; } - f.write_str("}")?; } Ok(()) diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index a52d98e230..2f160a213f 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -2403,7 +2403,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; } focus_range: 7..10, name: "Arg", kind: Struct, - description: "struct Arg(u32);", + description: "struct Arg(u32)", }, }, ], @@ -2462,7 +2462,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; } focus_range: 7..10, name: "Arg", kind: Struct, - description: "struct Arg(u32);", + description: "struct Arg(u32)", }, }, ], @@ -2498,7 +2498,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); } focus_range: 7..8, name: "A", kind: Struct, - description: "struct A(u32);", + description: "struct A(u32)", }, }, HoverGotoTypeData { @@ -2511,7 +2511,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); } focus_range: 22..23, name: "B", kind: Struct, - description: "struct B(u32);", + description: "struct B(u32)", }, }, HoverGotoTypeData { @@ -2525,7 +2525,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); } name: "C", kind: Struct, container_name: "M", - description: "pub struct C(u32);", + description: "pub struct C(u32)", }, }, ], @@ -2715,7 +2715,7 @@ fn main() { let s$0t = foo(); } focus_range: 39..41, name: "S1", kind: Struct, - description: "struct S1 {\n}", + description: "struct S1 {}", }, }, HoverGotoTypeData { @@ -2728,7 +2728,7 @@ fn main() { let s$0t = foo(); } focus_range: 52..54, name: "S2", kind: Struct, - description: "struct S2 {\n}", + description: "struct S2 {}", }, }, ], @@ -2819,7 +2819,7 @@ fn foo(ar$0g: &impl Foo + Bar) {} focus_range: 36..37, name: "S", kind: Struct, - description: "struct S {\n}", + description: "struct S {}", }, }, ], @@ -2919,7 +2919,7 @@ fn foo(ar$0g: &impl Foo) {} focus_range: 23..24, name: "S", kind: Struct, - description: "struct S {\n}", + description: "struct S {}", }, }, ], @@ -2956,7 +2956,7 @@ fn main() { let s$0t = foo(); } focus_range: 49..50, name: "B", kind: Struct, - description: "struct B {\n}", + description: "struct B {}", }, }, HoverGotoTypeData { @@ -3045,7 +3045,7 @@ fn foo(ar$0g: &dyn Foo) {} focus_range: 23..24, name: "S", kind: Struct, - description: "struct S {\n}", + description: "struct S {}", }, }, ], @@ -3093,7 +3093,7 @@ fn foo(a$0rg: &impl ImplTrait>>>) {} focus_range: 50..51, name: "B", kind: Struct, - description: "struct B {\n}", + description: "struct B {}", }, }, HoverGotoTypeData { @@ -3119,7 +3119,7 @@ fn foo(a$0rg: &impl ImplTrait>>>) {} focus_range: 65..66, name: "S", kind: Struct, - description: "struct S {\n}", + description: "struct S {}", }, }, ], @@ -3346,7 +3346,7 @@ struct S$0T(T); ``` ```rust - struct ST(T); + struct ST(T) ``` "#]], ); @@ -3367,7 +3367,7 @@ struct S$0T(T); ``` ```rust - struct ST(T); + struct ST(T) ``` "#]], ); @@ -3389,7 +3389,7 @@ struct S$0T(T); ``` ```rust - struct ST(T); + struct ST(T) ``` "#]], ); @@ -5946,7 +5946,7 @@ pub struct Foo(i32); ``` ```rust - pub struct Foo(i32); // size = 4, align = 4 + pub struct Foo(i32) // size = 4, align = 4 ``` ---