Closed
Description
As was brought up in this reddit post, Trait objects cannot call methods that take self by-value. Even worse, the error message erroneously claims the desired method does not exist.
It seems to me that trait objects of the form ~Trait
should work with self-by-value methods. And trait objects of the form &Trait
should produce an appropriate error message (just like calling the same method on a reference does).
Example:
trait Foo {
fn foo(self) -> int;
}
struct Bar;
impl Foo for Bar {
fn foo(self) -> int { 42i }
}
fn main() {
let bar = ~Bar as ~Foo;
let _x: int = bar.foo();
}
This produces:
Untitled.rs:12:19: 12:28 error: type `~Foo:Send` does not implement any method in scope named `foo`
Untitled.rs:12 let _x: int = bar.foo();
^~~~~~~~~
Metadata
Metadata
Assignees
Labels
No labels