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
pubfna<T>(x:T) -> Twherei64: std::ops::Mul<T,Output = T>,T:Copy{let a = 2*2;2* x
}
I expected to see this happen: the variable a is inferred to be i32 (or some other integer type) and the operator 2 * 2 uses the built-in integer multiplication operation.
Instead, this happened: the trait bound i64: std::ops::Mul<T, Output = T> shadows the built-in implementation for Mul<i64, Output=i64> which results in the error:
| pub fn a<T> (x : T) -> T
| - this type parameter
| where i64: Mul<T, Output=T> {
| let a = 2*2;
| ^ expected type parameter `T`, found integer
|
= note: expected type parameter `T`
found type `{integer}`
It is unclear to me whether this shadowing behavior is intended or unintended, however it works fine if the bound is instead T: Mul<i64, Output=T> which makes me wonder if it is unintended.
I tried this code:
I expected to see this happen: the variable
a
is inferred to bei32
(or some other integer type) and the operator2 * 2
uses the built-in integer multiplication operation.Instead, this happened: the trait bound
i64: std::ops::Mul<T, Output = T>
shadows the built-in implementation forMul<i64, Output=i64>
which results in the error:It is unclear to me whether this shadowing behavior is intended or unintended, however it works fine if the bound is instead
T: Mul<i64, Output=T>
which makes me wonder if it is unintended.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: