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

Adding context breaks type inference #18

Closed
scullionw opened this issue Oct 12, 2019 · 1 comment · Fixed by #19
Closed

Adding context breaks type inference #18

scullionw opened this issue Oct 12, 2019 · 1 comment · Fixed by #19

Comments

@scullionw
Copy link

scullionw commented Oct 12, 2019

Adding context seems to break type inference. For example:

use anyhow::{Context, Result};

fn main() -> Result<()> {
    let x = "k";
    let y: u32 = x.parse().context("context")?;
    println!("{}", y);
    Ok(())
}

gives

error[E0284]: type annotations required: cannot resolve `<_ as std::str::FromStr>::Err == _`
 --> src\main.rs:5:20
  |
5 |     let y: u32 = x.parse().context("context")?;
  |

obviously using turbofish syntax works, like:

let y = x.parse::<u32>().context("context")?;

but it is surprising behaviour. Might be a compiler limitation but I still wanted to mention it.

@dtolnay
Copy link
Owner

dtolnay commented Oct 12, 2019

Thanks! Should be fixed in 1.0.12.

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

Successfully merging a pull request may close this issue.

2 participants