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:
commit
f9b8ef0687
3 changed files with 41 additions and 4 deletions
|
@ -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 { .. } |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue