Open
Description
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
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
m-ou-se commentedon Oct 15, 2021
Some more data points:
Div::div(1f64, 2f64)
inside that function breaks with the same error.Div::<f64>::div(1.0, 2.0)
works.fbstj commentedon Oct 16, 2021
playground link
std::ops::Add
2.0f64
(found type64
){float} / ?
operation in the function body, not just the return valuecuviper commentedon Oct 17, 2021
I think this is part of what #41756 is talking about.
cuviper commentedon Oct 17, 2021
Chasing that conversation leads to a more direct dupe, #24066.