Skip to content
Merged
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
51 changes: 17 additions & 34 deletions compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fully_matched = true;
Some(variant_index.as_usize())
}
(&TestKind::Switch { .. }, _) => {
fully_matched = false;
None
}

// If we are performing a switch over integers, then this informs integer
// equality, but nothing else.
Expand All @@ -603,10 +599,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
options.len()
})
}
(&TestKind::SwitchInt { .. }, _) => {
fully_matched = false;
None
}

(
&TestKind::Len { len: test_len, op: BinOp::Eq },
Expand Down Expand Up @@ -695,34 +687,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
None
}
}
(&TestKind::Range { .. }, _) => {
fully_matched = false;
None
}

(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => {
// 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, 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 TestCase::Or { .. } = &match_pair.test_case {
return None;
}
// FIXME(#29623): return `Some(1)` when the values are different.
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
if test_val == case_val =>
{
fully_matched = true;
Some(0)
}

// These are all binary tests.
//
// FIXME(#29623) we can be more clever here
let pattern_test = self.test(match_pair);
if pattern_test.kind == test.kind {
fully_matched = true;
Some(0)
} else {
fully_matched = false;
None
}
(
TestKind::Switch { .. }
| TestKind::SwitchInt { .. }
| TestKind::Len { .. }
| TestKind::Range { .. }
| TestKind::Eq { .. },
_,
) => {
fully_matched = false;
None
}
};

Expand Down