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

Ok(T) is not an irrefutable pattern even when its type is Result<T, !> #71984

Closed
shika-blyat opened this issue May 7, 2020 · 2 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@shika-blyat
Copy link

I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=165744f32b174e1068e0813fe906735f

#![feature(never_type)]
struct A{n: usize}

fn a() -> Result<A, !> { Ok(A{n: 5}) }

fn main(){
  let Ok(A{ n }) = a();
}

I expected the code to compile, because Err is obviously an irrefutable pattern here.

I'm not even sure this is a bug (maybe rust's typesystem cannot understand that n inconstructible pattern on a n + 1 variants enum make the last pattern irrefutable ?)

@shika-blyat shika-blyat added the C-bug Category: This is a bug. label May 7, 2020
@lily-commure
Copy link
Contributor

The example code compiles with #![feature(exhaustive_patterns)]

@shika-blyat
Copy link
Author

Oh i wasn't aware of this feature, tyvm, i'm closing this 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants