Skip to content

Type inference error when importing unrelated function. #85565

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

Closed
neuring opened this issue May 21, 2021 · 3 comments
Closed

Type inference error when importing unrelated function. #85565

neuring opened this issue May 21, 2021 · 3 comments
Labels
A-inference Area: Type inference C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@neuring
Copy link

neuring commented May 21, 2021

I tried this code:

use serde_json::to_string;

pub fn some_function() {
    assert_eq!(3_u32, (0..3).sum());
}

Playground

I expected this to compile, but a type inference error was emitted.

error[E0283]: type annotations needed
 --> src/lib.rs:4:30
  |
4 |     assert_eq!(3_u32, (0..3).sum());
  |                              ^^^ cannot infer type for type parameter `S` declared on the associated function `sum`
  |
  = note: cannot satisfy `_: Sum<i32>`
help: consider specifying the type argument in the method call
  |
4 |     assert_eq!(3_u32, (0..3).sum::<S>());
  |                                 ^^^^^

If the import of serde_json::to_string is removed the code compiles just fine.

Meta

It fails on all stable, beta and nightly.

@neuring neuring added the C-bug Category: This is a bug. label May 21, 2021
@PatchMixolydic
Copy link
Contributor

@rustbot modify labels: +A-inference +T-compiler

@rustbot rustbot added A-inference Area: Type inference T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 21, 2021
@jonas-schievink
Copy link
Contributor

I believe this is expected behavior. It also happens with use serde_json as _;, which just causes the compiler to load the crate. Since that also loads any impls in the crate, they can cause ambiguities.

@neuring
Copy link
Author

neuring commented May 21, 2021

@jonas-schievink There don't seem to be any impls for Sum in serde_json and neither in serde. The problem seems to be another PartialEq .impl
In searching for those I found serde-rs/json#651 which linked to #46257.
So this issue is a duplicate.

@neuring neuring closed this as completed May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. 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

4 participants