Skip to content

where clause hides f64: Div<f64> impl #89910

@m-ou-se

Description

@m-ou-se

This code:

use std::ops::Div;

pub fn f<T>(_: T) -> f64
where
    f64: Div<T, Output = f64>,
{
    1.0 / 2.0
}

Results in this error:

error[E0308]: mismatched types
 --> src/lib.rs:7:11
  |
3 | pub fn f<T>(_: T) -> f64
  |          - this type parameter
...
7 |     1.0 / 2.0
  |           ^^^ expected type parameter `T`, found floating-point number
  |
  = note: expected type parameter `T`
                       found type `{float}`

But I expected it to compile fine, since f64: Div<f64, Output = f64> also exists unconditionally. It seems that the bound on f64 hides the existing f64: Div<f64>.

This seems to happen on all versions of Rust since 1.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions