Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing unreachable code/arm warning, when a match guard is diverging #134734

Open
WaffleLapkin opened this issue Dec 24, 2024 · 1 comment
Open
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unreachable_code Lint: unreachable_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

I tried this code:

fn main() {
    match () {
        _ if loop {} => (),
        _ => (),
    }
    println!("nya :3");
}

(playground)

I expected to see this happen: compiler to emit a warning that the first arm and later code is unreachable (since loop{} never terminates and has type !).

Instead, this happened: the code compiles without warnings.

Meta

rustc version: 1.84.0-beta.4 (2024-12-07 202008a1b8de96d2e5b6)

@WaffleLapkin WaffleLapkin added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unreachable_code Lint: unreachable_code labels Dec 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 24, 2024
@compiler-errors
Copy link
Member

This seems somewhat nontrivial to lint, since the match only unconditionally diverges due to the match guard in this way if the pattern is unconditional and there are no other patterns that could've matched prior. Seems like a pretty special case to have to hard-code into the HIR divergence analysis which is already a complete mess.

DianQK added a commit to DianQK/rust that referenced this issue Dec 25, 2024
…ffleLapkin

Consider arm to diverge if guard diverges

This is not a fix for rust-lang#134734, but I discovered it when I was gauging how difficult it would be to fix that. It does fix a really old test though :>

r? `@WaffleLapkin` or reassign
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 25, 2024
Rollup merge of rust-lang#134735 - compiler-errors:arm-diverges, r=WaffleLapkin

Consider arm to diverge if guard diverges

This is not a fix for rust-lang#134734, but I discovered it when I was gauging how difficult it would be to fix that. It does fix a really old test though :>

r? `@WaffleLapkin` or reassign
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unreachable_code Lint: unreachable_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants