Skip to content

Commit 96a4bf7

Browse files
committed
Fix pretty-printing
1 parent 9121453 commit 96a4bf7

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -919,14 +919,14 @@ impl<'a> State<'a> {
919919
self.maybe_print_comment(arm.pat.span.lo());
920920
self.print_outer_attributes(&arm.attrs);
921921
self.print_pat(&arm.pat);
922-
self.space();
923922
if let Some(e) = &arm.guard {
923+
self.space();
924924
self.word_space("if");
925925
self.print_expr(e, FixupContext::default());
926-
self.space();
927926
}
928927

929928
if let Some(body) = &arm.body {
929+
self.space();
930930
self.word_space("=>");
931931

932932
match &body.kind {
@@ -951,7 +951,9 @@ impl<'a> State<'a> {
951951
}
952952
}
953953
} else {
954+
// Empty body following a never pattern.
954955
self.word(",");
956+
self.end(); // Close the ibox for the pattern.
955957
}
956958
self.end(); // Close enclosing cbox.
957959
}

Diff for: compiler/rustc_hir_pretty/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1880,15 +1880,15 @@ impl<'a> State<'a> {
18801880
self.ibox(0);
18811881
self.print_outer_attributes(self.attrs(arm.hir_id));
18821882
self.print_pat(arm.pat);
1883-
self.space();
18841883
if let Some(ref g) = arm.guard {
1884+
self.space();
18851885
self.word_space("if");
18861886
self.print_expr(g);
1887-
self.space();
18881887
}
18891888

18901889
match arm.body.kind {
18911890
hir::ExprKind::Block(blk, opt_label) => {
1891+
self.space();
18921892
self.word_space("=>");
18931893
if let Some(label) = opt_label {
18941894
self.print_ident(label.ident);
@@ -1905,10 +1905,11 @@ impl<'a> State<'a> {
19051905
}
19061906
hir::ExprKind::Unreachable => {
19071907
// Empty body following a never pattern.
1908-
self.end(); // close the ibox for the pattern
19091908
self.word(",");
1909+
self.end(); // close the ibox for the pattern
19101910
}
19111911
_ => {
1912+
self.space();
19121913
self.word_space("=>");
19131914
self.end(); // close the ibox for the pattern
19141915
self.print_expr(arm.body);

Diff for: tests/pretty/never_patterns.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// pp-exact
2+
#![feature(never_patterns)]
3+
#![allow(incomplete_features)]
4+
5+
enum Void {}
6+
7+
fn foo(res: &Result<u32, Void>) -> &u32 { match res { Ok(x) => x, Err(!), } }
8+
9+
fn main() { foo(&Ok(0)); }

0 commit comments

Comments
 (0)