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

Unhelpful suggestion for "cannot infer type" error #69123

Open
Sherlock-Holo opened this issue Feb 13, 2020 · 1 comment
Open

Unhelpful suggestion for "cannot infer type" error #69123

Sherlock-Holo opened this issue Feb 13, 2020 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Sherlock-Holo
Copy link

Sherlock-Holo commented Feb 13, 2020

I tried this code:

fn main() {
    let map: HashMap<i32, i32, _> = HashMap::from_iter(vec![(1, 1), (2, 2)].into_iter());
}

I expected to see this happen:

when run cargo check, it should says

  --> src/main.rs:30:14
   |
30 |     let map: HashMap<i32, i32, _> = HashMap::from_iter(vec![(1, 1), (2, 2)].into_iter());
   |         ---  ^^^^^^^^^^^^^^^^^^^^ cannot infer type
   |         |
   |         consider change `HashMap<i32, i32, _>` to `HashMap<i32, i32>` because it has a default type, or specify a detail type.

Instead, this happened:

  --> src/main.rs:30:14
   |
30 |     let map: HashMap<i32, i32, _> = HashMap::from_iter(vec![(1, 1), (2, 2)].into_iter());
   |         ---  ^^^^^^^^^^^^^^^^^^^^ cannot infer type
   |         |
   |         consider giving `map` the explicit type `std::collections::HashMap<i32, i32, _>`, with the type parameters specified

Meta

rustc --version --verbose:

ustc 1.43.0-nightly (a1912f2e8 2020-02-12)
binary: rustc
commit-hash: a1912f2e89b77cfe2a0e64b96f444848fe4e2d49
commit-date: 2020-02-12
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
@Sherlock-Holo Sherlock-Holo added the C-bug Category: This is a bug. label Feb 13, 2020
@jonas-schievink jonas-schievink changed the title cargo check prompt should be more smart Unhelpful suggestion for "cannot infer type" error Feb 13, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Feb 13, 2020
@compiler-errors
Copy link
Member

This actually suggests nothing now:

Compiling playground v0.0.1 (/playground)
error[[E0282]](https://doc.rust-lang.org/stable/error-index.html#E0282): type annotations needed
 --> src/main.rs:4:14
  |
4 |     let map: HashMap<i32, i32, _> = HashMap::from_iter(vec![(1, 1), (2, 2)].into_iter());
  |              ^^^^^^^^^^^^^^^^^^^^ cannot infer type

For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground` due to previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

3 participants