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

Possible type inference regression in guarded match arms #55820

Closed
Robbepop opened this issue Nov 9, 2018 · 2 comments
Closed

Possible type inference regression in guarded match arms #55820

Robbepop opened this issue Nov 9, 2018 · 2 comments

Comments

@Robbepop
Copy link
Contributor

Robbepop commented Nov 9, 2018

Inspecting the CI of this crate I just found out that type inference for it no longer works. This happened about 23 days ago.

The code below is a reduced example that fails with the same error. Link to playground.

enum Foo { A, B }

impl Foo {
    fn is_a(&self) -> bool { if let Foo::A = self { true } else { false } }
}

impl<'a> From<&'a str> for Foo {
    fn from(input: &'a str) -> Self { if input == "a" { Foo::A } else { Foo::B } }
}

fn foo(input: &str) {
    match input.into() {
        ref foo if foo.is_a() => println!("Foo::A"),
        Foo::B => println!("Foo::B"),
        _ => panic!()
    }
}

NOTE: The compiler can infer the types correctly if we swap the first two match arms.

Is this a bug in the compiler or wanted behavior?
I am wondering since the compiler was able to infer types correctly about 23 days ago.

CI here: https://travis-ci.org/Robbepop/stevia/jobs/452228341

@jonas-schievink
Copy link
Contributor

Same issue as in #55810, will be fixed by #55819

@dtolnay
Copy link
Member

dtolnay commented Nov 9, 2018

Closing in favor of #55810.

@dtolnay dtolnay closed this as completed Nov 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants