about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-02-21 22:48:58 +0100
committerGitHub <noreply@github.com>2024-02-21 22:48:58 +0100
commit60cb794181d0652a6917b97224be62177b384b1f (patch)
tree497ecd0f19951f7a14633e610ed0ff9d83bd073b /compiler/rustc_passes/src
parent084e2322f34f81bf1f50d4a77d8b8add9c0e95f0 (diff)
parent5e0e5b1efb8a5776231b07c71e7c03ef016654b5 (diff)
downloadrust-60cb794181d0652a6917b97224be62177b384b1f.tar.gz
rust-60cb794181d0652a6917b97224be62177b384b1f.zip
Rollup merge of #121391 - Nadrieril:fix-liveness, r=compiler-errors
never patterns: Fix liveness analysis in the presence of never patterns

There's a bunch of code that only looks at the first alternative of an or-pattern, under the assumption that all alternatives have the same set of bindings. This is true except for never pattern alternatives  (e.g. `Ok(x) | Err(!)`), so we skip these. I expect there's other code with this problem, I'll have to check that later.

I don't have tests for this yet because mir lowering causes other issues; I'll have some in the next PR.

r? ``@compiler-errors``
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/liveness.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs
index 3a8dc377520..487407014d1 100644
--- a/compiler/rustc_passes/src/liveness.rs
+++ b/compiler/rustc_passes/src/liveness.rs
@@ -526,8 +526,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
     }
 
     fn define_bindings_in_pat(&mut self, pat: &hir::Pat<'_>, mut succ: LiveNode) -> LiveNode {
-        // In an or-pattern, only consider the first pattern; any later patterns
-        // must have the same bindings, and we also consider the first pattern
+        // In an or-pattern, only consider the first non-never pattern; any later patterns
+        // must have the same bindings, and we also consider that pattern
         // to be the "authoritative" set of ids.
         pat.each_binding_or_first(&mut |_, hir_id, pat_sp, ident| {
             let ln = self.live_node(hir_id, pat_sp);