Skip to content

Commit 9449b78

Browse files
committed
show a trailing comma on singleton tuple constructors in witness pats
1 parent 29737cb commit 9449b78

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

compiler/rustc_pattern_analysis/src/rustc/print.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ pub(crate) fn write_struct_like<'tcx>(
119119
write!(f, "_")?;
120120
}
121121
}
122+
if matches!(ty.kind(), ty::Tuple(..)) && num_fields == 1 {
123+
write!(f, ",")?;
124+
}
122125
write!(f, ")")?;
123126
}
124127

tests/ui/or-patterns/exhaustiveness-non-exhaustive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ fn main() {
77
(0 | 1, 2 | 3) => {}
88
}
99
match ((0u8,),) {
10-
//~^ ERROR non-exhaustive patterns: `((4_u8..=u8::MAX))`
10+
//~^ ERROR non-exhaustive patterns: `((4_u8..=u8::MAX,),)`
1111
((0 | 1,) | (2 | 3,),) => {}
1212
}
1313
match (Some(0u8),) {
14-
//~^ ERROR non-exhaustive patterns: `(Some(2_u8..=u8::MAX))`
14+
//~^ ERROR non-exhaustive patterns: `(Some(2_u8..=u8::MAX),)`
1515
(None | Some(0 | 1),) => {}
1616
}
1717
}

tests/ui/or-patterns/exhaustiveness-non-exhaustive.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ LL ~ (0 | 1, 2 | 3) => {},
1111
LL + (2_u8..=u8::MAX, _) => todo!()
1212
|
1313

14-
error[E0004]: non-exhaustive patterns: `((4_u8..=u8::MAX))` not covered
14+
error[E0004]: non-exhaustive patterns: `((4_u8..=u8::MAX,),)` not covered
1515
--> $DIR/exhaustiveness-non-exhaustive.rs:9:11
1616
|
1717
LL | match ((0u8,),) {
18-
| ^^^^^^^^^ pattern `((4_u8..=u8::MAX))` not covered
18+
| ^^^^^^^^^ pattern `((4_u8..=u8::MAX,),)` not covered
1919
|
2020
= note: the matched value is of type `((u8,),)`
2121
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
2222
|
2323
LL ~ ((0 | 1,) | (2 | 3,),) => {},
24-
LL + ((4_u8..=u8::MAX)) => todo!()
24+
LL + ((4_u8..=u8::MAX,),) => todo!()
2525
|
2626

27-
error[E0004]: non-exhaustive patterns: `(Some(2_u8..=u8::MAX))` not covered
27+
error[E0004]: non-exhaustive patterns: `(Some(2_u8..=u8::MAX),)` not covered
2828
--> $DIR/exhaustiveness-non-exhaustive.rs:13:11
2929
|
3030
LL | match (Some(0u8),) {
31-
| ^^^^^^^^^^^^ pattern `(Some(2_u8..=u8::MAX))` not covered
31+
| ^^^^^^^^^^^^ pattern `(Some(2_u8..=u8::MAX),)` not covered
3232
|
3333
= note: the matched value is of type `(Option<u8>,)`
3434
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
3535
|
3636
LL ~ (None | Some(0 | 1),) => {},
37-
LL + (Some(2_u8..=u8::MAX)) => todo!()
37+
LL + (Some(2_u8..=u8::MAX),) => todo!()
3838
|
3939

4040
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)