Skip to content

In rustc_pattern_analysis, put true witnesses before false witnesses #144545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/rustc_pattern_analysis/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,16 +1130,16 @@ impl<Cx: PatCx> ConstructorSet<Cx> {
seen_false = true;
}
}
if seen_false {
present.push(Bool(false));
} else {
missing.push(Bool(false));
}
if seen_true {
present.push(Bool(true));
} else {
missing.push(Bool(true));
}
if seen_false {
present.push(Bool(false));
} else {
missing.push(Bool(false));
}
}
ConstructorSet::Integers { range_1, range_2 } => {
let seen_ranges: Vec<_> =
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_pattern_analysis/tests/exhaustiveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ fn test_witnesses() {
),
vec!["Enum::Variant1(_)", "Enum::Variant2(_)", "_"],
);

// Assert we put `true` before `false`.
assert_witnesses(AllOfThem, Ty::Bool, Vec::new(), vec!["true", "false"]);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
}

match Box::new((true, Box::new(false))) {
//~^ ERROR non-exhaustive patterns: `deref!((false, deref!(false)))` and `deref!((true, deref!(true)))` not covered
//~^ ERROR non-exhaustive patterns: `deref!((true, deref!(true)))` and `deref!((false, deref!(false)))` not covered
(true, false) => {}
(false, true) => {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ LL ~ true => {},
LL + deref!(deref!(false)) => todo!()
|

error[E0004]: non-exhaustive patterns: `deref!((false, deref!(false)))` and `deref!((true, deref!(true)))` not covered
error[E0004]: non-exhaustive patterns: `deref!((true, deref!(true)))` and `deref!((false, deref!(false)))` not covered
--> $DIR/non-exhaustive.rs:17:11
|
LL | match Box::new((true, Box::new(false))) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ patterns `deref!((false, deref!(false)))` and `deref!((true, deref!(true)))` not covered
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ patterns `deref!((true, deref!(true)))` and `deref!((false, deref!(false)))` not covered
|
note: `Box<(bool, Box<bool>)>` defined here
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
= note: the matched value is of type `Box<(bool, Box<bool>)>`
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
|
LL ~ (false, true) => {},
LL + deref!((false, deref!(false))) | deref!((true, deref!(true))) => todo!()
LL + deref!((true, deref!(true))) | deref!((false, deref!(false))) => todo!()
|

error[E0004]: non-exhaustive patterns: `deref!((deref!(T::C), _))` not covered
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/pattern/usefulness/unions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
}
// Our approach can report duplicate witnesses sometimes.
match (x, true) {
//~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
//~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: true }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
(U8AsBool { b: true }, true) => {}
(U8AsBool { b: false }, true) => {}
(U8AsBool { n: 1.. }, true) => {}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/pattern/usefulness/unions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ LL ~ U8AsBool { n: 1.. } => {},
LL + U8AsBool { n: 0_u8 } | U8AsBool { b: false } => todo!()
|

error[E0004]: non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
error[E0004]: non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: true }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
--> $DIR/unions.rs:28:15
|
LL | match (x, true) {
| ^^^^^^^^^ patterns `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
| ^^^^^^^^^ patterns `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: true }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
|
= note: the matched value is of type `(U8AsBool, bool)`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms
Expand Down
Loading