Skip to content

Unclear error : unable to infer enough type information about _ #19477

Closed
@BigEpsilon

Description

@BigEpsilon

This code producesses an unclear error

pub trait ValueGiver<T> {
    fn give(_: Option<Self>) -> T;
}

struct m;

impl<f64> ValueGiver<f64> for m {
    fn give(_:Option<m>) -> f64 {
        0.5f64
    } 
}

fn main() {
    let y : f64 = ValueGiver::give(None::<m>);
}

Here the error of course is the impl<f64> that should be impl, but the error message is not clear :

c.rs:64:5: 68:6 error: unable to infer enough type information about `_`; type annotations required
c.rs:64     impl<f64> ValueGiver<f64> for m {
c.rs:65         fn give(_:Option<m>) -> f64 {
c.rs:66             0.5f64
c.rs:67         } 
c.rs:68     }

Could this error message be more helpful ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions