Skip to content

Duplicated help with sum() missing type annotation #93506

@leonardo-m

Description

@leonardo-m
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`.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions