Skip to content

Commit

Permalink
address reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Nov 9, 2020
1 parent 459dae9 commit 43e4783
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
(&TestKind::Range { .. }, _) => None,

(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => {
// We do call `test()` below to see what kind of test `match_pair` would require.
// If it is the same test as `test`, then we can just use `test`.
// The call to `self.test(&match_pair)` below is not actually used to generate any
// MIR. Instead, we just want to compare with `test` (the parameter of the method)
// to see if it is the same.
//
// However, `test()` assumes that there won't be any or-patterns, so we need to
// specially handle that here and return `None` (since the `test` clearly doesn't
// apply to an or-pattern).
// However, at this point we can still encounter or-patterns that were extracted
// from previous calls to `sort_candidate`, so we need to manually address that
// case to avoid panicking in `self.test()`.
if let PatKind::Or { .. } = &*match_pair.pattern.kind {
return None;
}
Expand Down
46 changes: 23 additions & 23 deletions src/test/ui/match/issue-72680.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
#![feature(or_patterns)]

fn main() {
assert_eq!(f("", 0), true);
assert_eq!(f("a", 1), true);
assert_eq!(f("b", 1), true);
assert!(f("", 0));
assert!(f("a", 1));
assert!(f("b", 1));

assert_eq!(f("", 1), false);
assert_eq!(f("a", 0), false);
assert_eq!(f("b", 0), false);
assert!(!f("", 1));
assert!(!f("a", 0));
assert!(!f("b", 0));

assert_eq!(f("asdf", 032), false);
assert!(!f("asdf", 032));

////

assert_eq!(g(true, true, true), false);
assert_eq!(g(false, true, true), false);
assert_eq!(g(true, false, true), false);
assert_eq!(g(false, false, true), false);
assert_eq!(g(true, true, false), false);
assert!(!g(true, true, true));
assert!(!g(false, true, true));
assert!(!g(true, false, true));
assert!(!g(false, false, true));
assert!(!g(true, true, false));

assert_eq!(g(false, true, false), true);
assert_eq!(g(true, false, false), true);
assert_eq!(g(false, false, false), true);
assert!(g(false, true, false));
assert!(g(true, false, false));
assert!(g(false, false, false));

////

assert_eq!(h(true, true, true), false);
assert_eq!(h(false, true, true), false);
assert_eq!(h(true, false, true), false);
assert_eq!(h(false, false, true), false);
assert_eq!(h(true, true, false), false);
assert!(!h(true, true, true));
assert!(!h(false, true, true));
assert!(!h(true, false, true));
assert!(!h(false, false, true));
assert!(!h(true, true, false));

assert_eq!(h(false, true, false), true);
assert_eq!(h(true, false, false), true);
assert_eq!(h(false, false, false), true);
assert!(h(false, true, false));
assert!(h(true, false, false));
assert!(h(false, false, false));
}

fn f(s: &str, num: usize) -> bool {
Expand Down

0 comments on commit 43e4783

Please sign in to comment.