Fix spacing in pretty printed PatKind::Struct with no fields

This commit is contained in:
David Tolnay 2021-12-29 12:37:13 -08:00
parent df96fb166f
commit 8d7cf1a4ca
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 20 additions and 8 deletions

View File

@ -2460,7 +2460,11 @@ impl<'a> State<'a> {
self.print_path(path, true, 0);
}
self.nbsp();
self.word_space("{");
self.word("{");
let empty = fields.is_empty() && !etc;
if !empty {
self.space();
}
self.commasep_cmnt(
Consistent,
&fields,
@ -2481,7 +2485,9 @@ impl<'a> State<'a> {
}
self.word("..");
}
if !empty {
self.space();
}
self.word("}");
}
PatKind::Tuple(ref elts) => {

View File

@ -1874,7 +1874,11 @@ impl<'a> State<'a> {
PatKind::Struct(ref qpath, ref fields, etc) => {
self.print_qpath(qpath, true);
self.nbsp();
self.word_space("{");
self.word("{");
let empty = fields.is_empty() && !etc;
if !empty {
self.space();
}
self.commasep_cmnt(
Consistent,
&fields,
@ -1895,7 +1899,9 @@ impl<'a> State<'a> {
}
self.word("..");
}
if !empty {
self.space();
}
self.word("}");
}
PatKind::Or(ref pats) => {

View File

@ -661,7 +661,7 @@ fn test_pat() {
assert_eq!(stringify_pat!(ref mut _x @ _), "ref mut _x @ _");
// PatKind::Struct
assert_eq!(stringify_pat!(Struct {}), "Struct { }"); // FIXME
assert_eq!(stringify_pat!(Struct {}), "Struct {}");
assert_eq!(stringify_pat!(Struct::<u8> {}), "Struct::<u8> {}");
assert_eq!(stringify_pat!(Struct::<'static> {}), "Struct::<'static> {}");
assert_eq!(stringify_pat!(Struct { x }), "Struct { x }");