Skip to content

Commit ffefb13

Browse files
Always perform discr read for never pattern in EUV
1 parent 8c61cd4 commit ffefb13

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
943943
let mutability = if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };
944944
let bk = ty::BorrowKind::from_mutbl(mutability);
945945
self.delegate.borrow_mut().borrow(place, discr_place.hir_id, bk);
946+
} else if let PatKind::Never = pat.kind {
947+
// A `!` pattern always counts as an immutable read of the discriminant,
948+
// even in an irrefutable pattern.
949+
self.delegate.borrow_mut().borrow(place, discr_place.hir_id, BorrowKind::Immutable);
946950
}
947951

948952
Ok(())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ check-pass
2+
3+
// Make sure that the closure captures `s` so it can perform a read of `s`.
4+
5+
#![feature(never_patterns)]
6+
#![allow(incomplete_features)]
7+
8+
enum Void {}
9+
10+
fn by_value(s: Void) {
11+
move || {
12+
let ! = s;
13+
};
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)