1
Fork 0

Rollup merge of #130533 - compiler-errors:never-pat-unsafeck, r=Nadrieril

Never patterns constitute a read for unsafety

This code is otherwise unsound if we don't emit an unsafety error here. Noticed when fixing #130528, but it's totally unrelated.

r? `@Nadrieril`
This commit is contained in:
Jubilee 2024-09-18 23:40:30 -07:00 committed by GitHub
commit f9b8ef0687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 4 deletions

View file

@ -322,14 +322,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 { .. } |