Open
Description
A reduced example:
use std::ops::Shl;
struct Foo<T>(T);
impl<T> Shl<usize> for Foo<T> {
type Output = Foo<T>;
fn shl(self, _: usize) -> Foo<T> { self }
}
impl<T> Shl<i32> for Foo<T> {
type Output = Foo<T>;
fn shl(self, _: i32) -> Foo<T> { self }
}
fn main() {
let _ = Foo(0u32) << 2; // works fine
let _ = (Foo(0u32) << 2).0; // does not work
let x = Foo(0u32) << 2; // does not work
let _ = x.0;
let x: Foo<u32> = Foo(0u32) << 2; // works
let _ = x.0;
}
generates the following error:
<anon>:18:13: 18:31 error: the type of this value must be known in this context
<anon>:18 let _ = (Foo(0u32) << 2).0; // does not work
^~~~~~~~~~~~~~~~~~
<anon>:21:13: 21:16 error: the type of this value must be known in this context
<anon>:21 let _ = x.0;
^~~
I suspect what is happening here is that the fallback isn't being triggered early enough -- in particular, before the projection is generating the error. Note that the same problem occurs with a normal struct.
(This may be one reason that Shl
/Shr
are only implemented on usize
for Wrapping<T>
.)