You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code generates the following compile error, on any version of Rust I've checked down to 1.0.0 (with different format, obviously, but the same content):
error[E0308]: mismatched types
--> src/lib.rs:4:25
|
3 | fn test<V>() where f32: Mul<V, Output = V> {
| - this type parameter
4 | let _: f32 = 1f32 * 1f32;
| ^^^^ expected type parameter `V`, found `f32`
|
= note: expected type parameter `V`
found type `f32`
error[E0308]: mismatched types
--> src/lib.rs:4:18
|
3 | fn test<V>() where f32: Mul<V, Output = V> {
| - this type parameter
4 | let _: f32 = 1f32 * 1f32;
| --- ^^^^^^^^^^^ expected `f32`, found type parameter `V`
| |
| expected due to this
|
= note: expected type `f32`
found type parameter `V`
However, after adding another bound, it compiles successfully on all current versions (beta, stable and nightly):
use std::ops::Mul;// the only difference is `+ Mul`fntest<V>()wheref32:Mul<V,Output = V> + Mul{let _:f32 = 1f32*1f32;}
The text was updated successfully, but these errors were encountered:
Not sure if I follow. Why should the predicate make the implementation known to the compiler (since they are obviously available without the where clause) unavailable?
Hi, original urlo poster here. To me it makes little sense that the compiler would completely forget other implementations. And the only way that it could "compete" with the f32 implementation is if V becomes f32, but then we are fine too and 1f32 * 1f32 should be valid. In my use case, I need to express that V is some kind of vector type than can be multiplied by a scalar (here f32) so that I can do things like (1.0 + 2.0) * v but also (1.0 * 2.0) * v and the second one is the one that triggers the compiler error. Using Mul::<f32>::mul(1.0, 2.0) * v makes the compiler happy though so the trait implementation is definitely available, and both are compatible, it's just forgotten by the compiler.
This bug was initially reported on URLO and minimized to the following code:
(Playground)
This code generates the following compile error, on any version of Rust I've checked down to 1.0.0 (with different format, obviously, but the same content):
However, after adding another bound, it compiles successfully on all current versions (beta, stable and nightly):
The text was updated successfully, but these errors were encountered: