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

Mediocre error message for f32/f64 ambiguity #47759

Open
nieksand opened this Issue Jan 25, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@nieksand
Copy link
Contributor

nieksand commented Jan 25, 2018

I have this code:

    let _ = |x: f64| x * 2.0.exp();

https://play.rust-lang.org/?gist=58e23173aec4b798d8021af0ead25bbd&version=nightly

I get this error message:

error[E0599]: no method named `exp` found for type `{float}` in the current scope

I can work around by:

    let _ = |x: f64| x * 2.0f64.exp();

The world would be a better place if:

  • Type inference could just figure out 2.0 has to be f64 given the type on x
  • Failing that, an error message indicating the problem is f32 vs f64 ambiguity rather than this mysterious {float} thing
@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jan 25, 2018

Note that type inference cannot figure out 2.0 is an f64 just by x * 2.0.exp() because this is perfectly valid.

struct Foo;
trait Wat {
    fn exp(self) -> Foo;
}
impl Wat for f32 {
    fn exp(self) -> Foo { Foo }
}
impl std::ops::Mul<Foo> for f64 {
    type Output = &'static str;
    fn mul(self, _: Foo) -> &'static str {
        "wat"
    }
}

fn main() {
    let _ = |x: f64| x * 2.0.exp();
    //let _ = |x: f64| x * 2.0f64.exp();
}
@nieksand

This comment has been minimized.

Copy link
Contributor Author

nieksand commented Jan 25, 2018

Yipes. Inference is definitely out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.