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
When using T::clamp() in generics, T must be Ord. Types f32 and f64 are not Ord but implements clamp since 1.50.0, yet they cannot be used in generics due to the Ord constraint.
A possible solution I can think of is relax the constraint for clamp() from Ord to PartialOrd.
stephanemagnenat
changed the title
Use of clamp in generics does not combine with f64, maybe relax restriction to PartialOrd?
Use of clamp in generics does not combine with f32 and f64, maybe relax restriction to PartialOrd?
May 20, 2021
This is of course not a compiler bug, but rather a typing limitation in std.
stephanemagnenat
changed the title
Use of clamp in generics does not combine with f32 and f64, maybe relax restriction to PartialOrd?
Use of clamp in generics does not compose with f32 and f64, maybe relax restriction to PartialOrd?
May 20, 2021
The conclusion we came to is that PartialOrd was too likely to lead to surprising behavior. Thanks to the num crate you can still write your software the way you want to though.
When using
T::clamp()
in generics,T
must beOrd
. Typesf32
andf64
are notOrd
but implementsclamp
since 1.50.0, yet they cannot be used in generics due to theOrd
constraint.A possible solution I can think of is relax the constraint for
clamp()
fromOrd
toPartialOrd
.I tried this code:
I expected to see this happen: compilation success
Instead, this happened: error[E0599]: the method
clamp
exists for type parameterT
, but its trait bounds were not satisfiedMeta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: