1
Fork 0

Rollup merge of #92418 - dtolnay:emptystructpat, r=michaelwoerister

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

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($pat:pat) => {
        stringify!($pat)
    };
}

fn main() {
    println!("{}", repro!(Struct {}));
}
```

Before:&ensp;<code>Struct&nbsp;{&nbsp;&nbsp;}</code>
After:&ensp;<code>Struct&nbsp;{}</code>
This commit is contained in:
Matthias Krüger 2022-01-03 14:44:20 +01:00 committed by GitHub
commit df921190f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -2461,7 +2461,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,
@ -2482,7 +2486,9 @@ impl<'a> State<'a> {
}
self.word("..");
}
self.space();
if !empty {
self.space();
}
self.word("}");
}
PatKind::Tuple(ref elts) => {