fix: using {} for empty struct && remove semicolon for struct with tuple kind

This commit is contained in:
YangzeLuo 2023-11-08 20:46:04 +08:00
parent 46af7d30d0
commit 4f89b20152
2 changed files with 29 additions and 24 deletions

View file

@ -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(())

View file

@ -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<S>) {}
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<S>) {}
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<T> {\n}",
description: "struct B<T> {}",
},
},
HoverGotoTypeData {
@ -3045,7 +3045,7 @@ fn foo(ar$0g: &dyn Foo<S>) {}
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<B<dyn DynTrait<B<S>>>>) {}
focus_range: 50..51,
name: "B",
kind: Struct,
description: "struct B<T> {\n}",
description: "struct B<T> {}",
},
},
HoverGotoTypeData {
@ -3119,7 +3119,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
focus_range: 65..66,
name: "S",
kind: Struct,
description: "struct S {\n}",
description: "struct S {}",
},
},
],
@ -3346,7 +3346,7 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
```
```rust
struct ST<const C: usize = 1, T = Foo>(T);
struct ST<const C: usize = 1, T = Foo>(T)
```
"#]],
);
@ -3367,7 +3367,7 @@ struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
```
```rust
struct ST<const C: usize = {const}, T = Foo>(T);
struct ST<const C: usize = {const}, T = Foo>(T)
```
"#]],
);
@ -3389,7 +3389,7 @@ struct S$0T<const C: usize = VAL, T = Foo>(T);
```
```rust
struct ST<const C: usize = VAL, T = Foo>(T);
struct ST<const C: usize = VAL, T = Foo>(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
```
---