-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Type inference breaks from a seemingly unrelated change #100882
Comments
Right... This does seem to be intentional, but it's very not clear. The issue is that you're doing But if you have The error message does tell you this to some extent: error[E0283]: type annotations needed
--> src/main.rs:13:25
|
13 | if vec.len() != len.parse().unwrap() {
| -- ^^^^^ cannot infer type of the type parameter `F` declared on the associated function `parse`
| |
| type must be known at this point
|
= note: multiple `impl`s satisfying `usize: PartialEq<_>` found in the following crates: `core`, `serde_json`:
- impl PartialEq for usize;
- impl PartialEq<Value> for usize;
help: consider specifying the generic argument
|
13 | if vec.len() != len.parse::<F>().unwrap() {
| +++++
For more information about this error, try `rustc --explain E0283`. but I agree that the situation is confusing. |
OK thanks, I can see how this originated. And I certainly see how this is not changeable without breaking tons of code. What seems unusual to me is how importing a crate breaks existing code. I think with the traits Rust goes to great length to avoid exactly this kind of situation. Wouldn't it be consistent for the compiler to say: "Please specify the type here, someone in the future might implement Is there maybe a case where it is essential to infer the type automatically, if currently only one implementation exists? |
FYI here are other issues I know of that discuss this problem:
@rustbot label A-inference T-compiler |
Closing in favor of the other issues. |
I was just making changes in one of the crates in my workspace, when the code broke in another crate of the workspace. Rust is no longer able to infer the type automatically, with an explicit annotation it works again.
Feel free to close this bug report if this is to be expected, but to me this seems very unusual for Rust.
This is the code:
Uncomment the
serde_json
line to trigger the bug. After uncommenting Rust needs an explicit type annotation asusize
forlen.parse()
.Meta
rustc --version --verbose
:This occurs also with the stable and beta compiler
The text was updated successfully, but these errors were encountered: