Skip to content

Type Inference in Iterator::sum() is not working well #36201

Closed
@StefanoD

Description

@StefanoD

From this thread:

Example 1:

fn total1(a: &[u32]) -> u32 { // OK
    a.iter().sum()
}

fn total3(a: &[u32]) -> u32 { // Error
    a.iter().sum() + 5u32
}

fn main() {}

Example 2:

fn f() -> f64 { // Ok
   0.0f64 +  vec![1.0f64].into_iter().sum::<f64>()
}

fn f2() -> f64 { // Error
   0.0f64 +  vec![1.0f64].into_iter().sum()
}

fn main() {}

rust version: 1.11 stable

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions