Skip to content

Commit db9b4ea

Browse files
committed
Add tests
1 parent 8cf2c0d commit db9b4ea

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tests/ui/pattern/usefulness/unions.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
fn main() {
2+
#[derive(Copy, Clone)]
3+
union U8AsBool {
4+
n: u8,
5+
b: bool,
6+
}
7+
8+
let x = U8AsBool { n: 1 };
9+
unsafe {
10+
match x {
11+
// exhaustive
12+
U8AsBool { n: 2 } => {}
13+
U8AsBool { b: true } => {}
14+
U8AsBool { b: false } => {}
15+
}
16+
match x {
17+
// exhaustive
18+
U8AsBool { b: true } => {}
19+
U8AsBool { n: 0 } => {}
20+
U8AsBool { n: 1.. } => {}
21+
}
22+
match x {
23+
//~^ ERROR non-exhaustive patterns: `U8AsBool { n: 0_u8, b: false }` not covered
24+
U8AsBool { b: true } => {}
25+
U8AsBool { n: 1.. } => {}
26+
}
27+
match (x, true) {
28+
//~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8, b: false }, false)` and `(U8AsBool { n: 0_u8, b: true }, false)` not covered
29+
(U8AsBool { b: true }, true) => {}
30+
(U8AsBool { b: false }, true) => {}
31+
(U8AsBool { n: 1.. }, true) => {}
32+
}
33+
}
34+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error[E0004]: non-exhaustive patterns: `U8AsBool { n: 0_u8, b: false }` not covered
2+
--> $DIR/unions.rs:22:15
3+
|
4+
LL | match x {
5+
| ^ pattern `U8AsBool { n: 0_u8, b: false }` not covered
6+
|
7+
note: `U8AsBool` defined here
8+
--> $DIR/unions.rs:3:11
9+
|
10+
LL | union U8AsBool {
11+
| ^^^^^^^^
12+
= note: the matched value is of type `U8AsBool`
13+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
14+
|
15+
LL ~ U8AsBool { n: 1.. } => {},
16+
LL + U8AsBool { n: 0_u8, b: false } => todo!()
17+
|
18+
19+
error[E0004]: non-exhaustive patterns: `(U8AsBool { n: 0_u8, b: false }, false)` and `(U8AsBool { n: 0_u8, b: true }, false)` not covered
20+
--> $DIR/unions.rs:27:15
21+
|
22+
LL | match (x, true) {
23+
| ^^^^^^^^^ patterns `(U8AsBool { n: 0_u8, b: false }, false)` and `(U8AsBool { n: 0_u8, b: true }, false)` not covered
24+
|
25+
= note: the matched value is of type `(U8AsBool, bool)`
26+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
27+
|
28+
LL ~ (U8AsBool { n: 1.. }, true) => {},
29+
LL + (U8AsBool { n: 0_u8, b: false }, false) | (U8AsBool { n: 0_u8, b: true }, false) => todo!()
30+
|
31+
32+
error: aborting due to 2 previous errors
33+
34+
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)