1
Fork 0

Disallow an arm without a body (except for never patterns)

Parsing now accepts a match arm without a body, so we must make sure to
only accept that if the pattern is a never pattern.
This commit is contained in:
Nadrieril 2023-11-27 01:53:05 +01:00
parent 0bfebc6105
commit a2dcb3a6d9
9 changed files with 128 additions and 12 deletions

View file

@ -1055,6 +1055,23 @@ impl<'hir> Pat<'hir> {
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(s) => {
is_never_pattern = s.iter().all(|p| p.is_never_pattern());
false
}
_ => true,
});
is_never_pattern
}
}
/// A single field in a struct pattern.