Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@ExpHP

Description

@ExpHP
Issue body actions
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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.