diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-03 14:44:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-03 14:44:20 +0100 |
| commit | df921190f3e8236892094a0f45aa5cc77e10f3d2 (patch) | |
| tree | d47b205f814bbfac2729822ac63d3bcb3c5b60c3 /compiler | |
| parent | 92f28bda38500e9ba33399e49c297323968109d1 (diff) | |
| parent | 8d7cf1a4cae07489c375af7bd03923012774dadd (diff) | |
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: <code>Struct { }</code>
After: <code>Struct {}</code>
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_hir_pretty/src/lib.rs | 10 |
2 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index b87dd449a1e..91fa4595241 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -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) => { diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index fb11aaf24c4..c17286dfbe3 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -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(".."); } - self.space(); + if !empty { + self.space(); + } self.word("}"); } PatKind::Or(ref pats) => { |
