File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -1807,8 +1807,9 @@ impl<'hir> Pat<'hir> {
18071807 // Does not constitute a read.
18081808 PatKind :: Wild => false ,
18091809
1810- // Might not constitute a read, since the condition might be false.
1811- PatKind :: Guard ( _, _) => true ,
1810+ // The guard cannot affect if we make a read or not (it runs after the inner pattern
1811+ // has matched), therefore it's irrelevant.
1812+ PatKind :: Guard ( pat, _) => pat. is_guaranteed_to_constitute_read_for_never ( ) ,
18121813
18131814 // This is unnecessarily restrictive when the pattern that doesn't
18141815 // constitute a read is unreachable.
Original file line number Diff line number Diff line change @@ -259,7 +259,8 @@ impl<'tcx> TyCtxt<'tcx> {
259259 expr. hir_id != lhs. hir_id
260260 }
261261
262- // See note on `PatKind::Or` below for why this is `all`.
262+ // See note on `PatKind::Or` in `Pat::is_guaranteed_to_constitute_read_for_never`
263+ // for why this is `all`.
263264 ExprKind :: Match ( scrutinee, arms, _) => {
264265 assert_eq ! ( scrutinee. hir_id, expr. hir_id) ;
265266 arms. iter ( ) . all ( |arm| arm. pat . is_guaranteed_to_constitute_read_for_never ( ) )
Original file line number Diff line number Diff line change 1+ // Regression test for <https://github.com/rust-lang/rust/pull/149545#discussion_r2585205872>
2+ //
3+ //@ check-pass
4+ #![ feature( guard_patterns, never_type) ]
5+ #![ expect( incomplete_features, unused_parens) ]
6+ #![ deny( unreachable_code) ]
7+
8+ fn main ( ) {
9+ unsafe {
10+ let x = std:: ptr:: null :: < !> ( ) ;
11+
12+ // This should not constitute a read for never, therefore no code here is unreachable
13+ let ( _ if false ) : ! = * x;
14+ ( ) ;
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments