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

unreachable_patterns false negative with or_patterns #76836

Closed
tmiasko opened this issue Sep 17, 2020 · 1 comment · Fixed by #78167
Closed

unreachable_patterns false negative with or_patterns #76836

tmiasko opened this issue Sep 17, 2020 · 1 comment · Fixed by #78167
Assignees
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns C-bug Category: This is a bug. F-or_patterns `#![feature(or_patterns)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Sep 17, 2020

The match remains exhaustive with highlighted pattern removed, but it does not produce any warnings:

#![feature(or_patterns)]

pub struct A;

pub enum B {
    X,
    Y,
}

pub enum E {
    A(A),
    B(B),
}

pub fn f(e: E) -> () {
    match e {
        E::B(B::X) => (),
        E::B(B::Y | B::X)
        //          ~~~~ 
        | E::A(A) => (),
    }
}
@tmiasko tmiasko added the C-bug Category: This is a bug. label Sep 17, 2020
@jonas-schievink jonas-schievink added A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns F-or_patterns `#![feature(or_patterns)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 17, 2020
@Nadrieril
Copy link
Member

I know where the problem comes from: this bit of code tries to handle unreachable sub-or-patterns diagnostics, but it's a bit of a hack. What remains is to come up with a better solution.

pats.into_iter().filter(|p| unreachable_subpats.contains(p)).collect();

@rustbot claim

JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 6, 2020
Fix unreachable sub-branch detection in or-patterns

The previous implementation was too eager to avoid unnecessary "unreachable pattern" warnings. I feel more confident about this implementation than I felt about the previous one.
Fixes rust-lang#76836.

`@rustbot` modify labels: +A-exhaustiveness-checking
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 6, 2020
Fix unreachable sub-branch detection in or-patterns

The previous implementation was too eager to avoid unnecessary "unreachable pattern" warnings. I feel more confident about this implementation than I felt about the previous one.
Fixes rust-lang#76836.

``@rustbot`` modify labels: +A-exhaustiveness-checking
@bors bors closed this as completed in 25e272e Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns C-bug Category: This is a bug. F-or_patterns `#![feature(or_patterns)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants