Auto merge of #123332 - Nadrieril:testkind-never, r=matthewjasper
never patterns: lower never patterns to `Unreachable` in MIR This lowers a `!` pattern to "goto Unreachable". Ideally I'd like to read from the place to make it clear that the UB is coming from an invalid value, but that's tricky so I'm leaving it for later. r? `@compiler-errors` how do you feel about a lil bit of MIR lowering
This commit is contained in:
commit
0f40f14b61
16 changed files with 315 additions and 21 deletions
|
@ -682,6 +682,23 @@ impl<'tcx> Pat<'tcx> {
|
|||
true
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether this a never pattern.
|
||||
pub fn is_never_pattern(&self) -> bool {
|
||||
let mut is_never_pattern = false;
|
||||
self.walk(|pat| match &pat.kind {
|
||||
PatKind::Never => {
|
||||
is_never_pattern = true;
|
||||
false
|
||||
}
|
||||
PatKind::Or { pats } => {
|
||||
is_never_pattern = pats.iter().all(|p| p.is_never_pattern());
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
});
|
||||
is_never_pattern
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> IntoDiagArg for Pat<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue