Closed
Description
I tried this code:
pub type Id<T> = <T as IdTrait>::T;
pub trait IdTrait {
type T: ?Sized;
}
impl<T: ?Sized> IdTrait for T {
type T = T;
}
#[derive(Copy, Clone)]
struct Foo;
impl Foo {
fn method(self: Id<Self>) {
println!("hi!");
}
}
trait FooTrait {
fn method2(self: Id<Self>);
}
impl FooTrait for Foo {
fn method2(self) { // or `: Id<Self>`, makes no difference here
println!("hi!");
}
}
pub fn main() {
let foo = Foo;
foo.method(); // works
foo.method2(); // doesn't work
Foo::method2(foo); // works
}
I expected to see this happen: Code compiles successfully
Instead, this happened:
error[E0599]: no method named `method2` found for struct `Foo` in the current scope
--> <source>:31:9
|
12 | struct Foo;
| ---------- method `method2` not found for this struct
...
20 | fn method2(self: Id<Self>);
| -------- the method might not be found because of this arbitrary self type
...
31 | foo.method2(); // doesn't work
| ^^^^^^^
|
help: there is a method `method` with a similar name
|
31 | foo.method(); // doesn't work
| ~~~~~~
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0599`.
Compiler returned: 1
This is technically an old regression in 1.22
, the code compiled fine up to Rust 1.21
.