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

Duplicated help with sum() missing type annotation #93506

Closed
leonardo-m opened this issue Jan 31, 2022 · 2 comments · Fixed by #99075
Closed

Duplicated help with sum() missing type annotation #93506

leonardo-m opened this issue Jan 31, 2022 · 2 comments · Fixed by #99075
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

leonardo-m commented Jan 31, 2022

fn foo() -> u64 {
    [1_u64].iter().sum() + 1
}
fn main() {}

Gives (rustc 1.60.0-nightly 08df8b8 2022-01-30):

error[E0283]: type annotations needed
    --> ...\test.rs:2:20
     |
2    |     [1_u64].iter().sum() + 1
     |                    ^^^ cannot infer type for type parameter `S` declared on the associated function `sum`
     |
     = note: cannot satisfy `_: Sum<&u64>`
note: required by a bound in `std::iter::Iterator::sum`
help: consider specifying the type argument in the method call
     |
2    |     [1_u64].iter().sum::<S>() + 1
     |                       +++++
help: consider specifying the type argument in the function call
     |
2    |     [1_u64].iter().sum::<S>() + 1
     |                       +++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0283`.
@leonardo-m leonardo-m added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 31, 2022
@terrarier2111
Copy link
Contributor

@rustbot claim

@terrarier2111 terrarier2111 removed their assignment Feb 9, 2022
@estebank estebank added A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Jun 15, 2022
@danobi
Copy link
Contributor

danobi commented Jul 9, 2022

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 11, 2022
…henkov

Fix duplicated type annotation suggestion

Before, there was more or less duplicated suggestions to add type hints.
Fix by clearing more generic suggestions when a more specific suggestion
is possible.

This fixes rust-lang#93506 .
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 11, 2022
…henkov

Fix duplicated type annotation suggestion

Before, there was more or less duplicated suggestions to add type hints.
Fix by clearing more generic suggestions when a more specific suggestion
is possible.

This fixes rust-lang#93506 .
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 11, 2022
…henkov

Fix duplicated type annotation suggestion

Before, there was more or less duplicated suggestions to add type hints.
Fix by clearing more generic suggestions when a more specific suggestion
is possible.

This fixes rust-lang#93506 .
@bors bors closed this as completed in 34e9e6d Jul 12, 2022
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-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants