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

If a function requires f64: Mul<C>, then 1f64 * 1f64 becomes a type error #46697

Closed
ExpHP opened this issue Dec 12, 2017 · 2 comments
Closed

Comments

@ExpHP
Copy link
Contributor

ExpHP commented Dec 12, 2017

use ::std::ops::Mul;

fn multiply_two_floats<C>()
where f64: Mul<C>,
{
    let _ = 1.0_f64 * 1.0_f64;
}
   Compiling playground v0.0.1 (file:///playground)
error[E0308]: mismatched types
 --> src/main.rs:7:23
  |
7 |     let _ = 1.0_f64 * 1.0_f64;
  |                       ^^^^^^^ expected type parameter, found f64
  |
  = note: expected type `C`
             found type `f64`

I've been playing around with this since yesterday and it looks and feels like the sort of thing that would usually be a known limitation (if that makes sense)... except that I cannot seem to locate any existing discussion on it. Here's some more properties of it:

Adding f64: Mul<f64> + Mul<C> does not resolve the issue.

It is unrelated to operators. (if you swap out Add for some other trait and use a.method(b), the issue persists)

UFCS still works:

use ::std::ops::Mul;

fn multiply_two_floats<C>()
where f64: Mul<C>,
{
    <f64 as Mul<f64>>::mul(1.0_f64, 1.0_f64); // ok
}
@hanna-kruppe
Copy link
Contributor

See #24066

@ExpHP
Copy link
Contributor Author

ExpHP commented Dec 13, 2017

Yep, closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants