Never patterns constitute a read for unsafety

This commit is contained in:
Michael Goulet 2024-09-18 17:05:44 -04:00
parent f79a912d9e
commit e138e8760d
3 changed files with 41 additions and 4 deletions

View file

@ -315,14 +315,15 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
| PatKind::DerefPattern { .. }
| PatKind::Range { .. }
| PatKind::Slice { .. }
| PatKind::Array { .. } => {
| PatKind::Array { .. }
// Never constitutes a witness of uninhabitedness.
| PatKind::Never => {
self.requires_unsafe(pat.span, AccessToUnionField);
return; // we can return here since this already requires unsafe
}
// wildcard/never don't take anything
// wildcard doesn't read anything.
PatKind::Wild |
PatKind::Never |
// these just wrap other patterns
// these just wrap other patterns, which we recurse on below.
PatKind::Or { .. } |
PatKind::InlineConstant { .. } |
PatKind::AscribeUserType { .. } |