Skip to content

Generic impls of traits don't autoderef #10456

Closed
@alexcrichton

Description

@alexcrichton
pub struct Foo;

pub trait Bar {
    fn bar(&self);
}

pub trait Baz {}

impl<T: Baz> Bar for T {
    fn bar(&self) {}
}

impl Baz for Foo {}

pub fn foo(t: ~Foo) {
    t.bar() // ~Foo doesn't implement Baz
    (*t).bar() // ok b/c Foo implements Baz
}

fn main() {}

From a code-writer point of view, it'd be nice for t to auto-deref to (*t).bar() to appease the compiler, but I can see that the compiler may not know a whole lot about this.

If we don't get auto-deref here, perhaps a better error message may work. It's a little confusing to see that ~Foo doesn't implement Baz when Foo clearly implements Baz

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions