Skip to content

Supertrait methods are called on inner type of object type rather than any explicit impl for the object type #10692

Closed
@huonw

Description

@huonw
trait Foo: Clone {
    fn clone_as_obj(&self) -> ~Foo {
        ~(self.clone()) as ~Foo
    }
}

impl Clone for ~Foo {
    fn clone(&self) -> ~Foo {
        self.clone_as_obj();
    }
}

fn test(x: ~Foo) {
    x.clone();
}
clone-abort-3.rs:14:4: 14:14 error: cannot call a method whose type contains a self-type through an object
clone-abort-3.rs:14     x.clone();
                        ^~~~~~~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /home/huon/rust/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /home/huon/rust/src/librustc/lib.rs:395

It seems like that should prefer the (~Foo).clone() method rather than trying to call the .clone that the compiler knows that the inner type must have.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions