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>
This commit is contained in:
commit
df921190f3
3 changed files with 20 additions and 8 deletions
|
@ -2461,7 +2461,11 @@ impl<'a> State<'a> {
|
||||||
self.print_path(path, true, 0);
|
self.print_path(path, true, 0);
|
||||||
}
|
}
|
||||||
self.nbsp();
|
self.nbsp();
|
||||||
self.word_space("{");
|
self.word("{");
|
||||||
|
let empty = fields.is_empty() && !etc;
|
||||||
|
if !empty {
|
||||||
|
self.space();
|
||||||
|
}
|
||||||
self.commasep_cmnt(
|
self.commasep_cmnt(
|
||||||
Consistent,
|
Consistent,
|
||||||
&fields,
|
&fields,
|
||||||
|
@ -2482,7 +2486,9 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
self.word("..");
|
self.word("..");
|
||||||
}
|
}
|
||||||
|
if !empty {
|
||||||
self.space();
|
self.space();
|
||||||
|
}
|
||||||
self.word("}");
|
self.word("}");
|
||||||
}
|
}
|
||||||
PatKind::Tuple(ref elts) => {
|
PatKind::Tuple(ref elts) => {
|
||||||
|
|
|
@ -1874,7 +1874,11 @@ impl<'a> State<'a> {
|
||||||
PatKind::Struct(ref qpath, ref fields, etc) => {
|
PatKind::Struct(ref qpath, ref fields, etc) => {
|
||||||
self.print_qpath(qpath, true);
|
self.print_qpath(qpath, true);
|
||||||
self.nbsp();
|
self.nbsp();
|
||||||
self.word_space("{");
|
self.word("{");
|
||||||
|
let empty = fields.is_empty() && !etc;
|
||||||
|
if !empty {
|
||||||
|
self.space();
|
||||||
|
}
|
||||||
self.commasep_cmnt(
|
self.commasep_cmnt(
|
||||||
Consistent,
|
Consistent,
|
||||||
&fields,
|
&fields,
|
||||||
|
@ -1895,7 +1899,9 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
self.word("..");
|
self.word("..");
|
||||||
}
|
}
|
||||||
|
if !empty {
|
||||||
self.space();
|
self.space();
|
||||||
|
}
|
||||||
self.word("}");
|
self.word("}");
|
||||||
}
|
}
|
||||||
PatKind::Or(ref pats) => {
|
PatKind::Or(ref pats) => {
|
||||||
|
|
|
@ -661,7 +661,7 @@ fn test_pat() {
|
||||||
assert_eq!(stringify_pat!(ref mut _x @ _), "ref mut _x @ _");
|
assert_eq!(stringify_pat!(ref mut _x @ _), "ref mut _x @ _");
|
||||||
|
|
||||||
// PatKind::Struct
|
// 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::<u8> {}), "Struct::<u8> {}");
|
||||||
assert_eq!(stringify_pat!(Struct::<'static> {}), "Struct::<'static> {}");
|
assert_eq!(stringify_pat!(Struct::<'static> {}), "Struct::<'static> {}");
|
||||||
assert_eq!(stringify_pat!(Struct { x }), "Struct { x }");
|
assert_eq!(stringify_pat!(Struct { x }), "Struct { x }");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue