Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Error calling supertrait method via trait reference #4295

Closed
jdm opened this Issue · 3 comments

2 participants

@jdm
Collaborator
trait A {
    fn foo();
}

trait B: A {
}

struct BImpl {
    unused: int
}

impl BImpl: B {
}

impl BImpl: A {
    fn foo() {}
}

struct CImpl {
    b: B
}

impl CImpl: A {
    fn foo() {
        self.b.foo();
    }
}

fn main() {
    let b = BImpl { unused: 0 } as B;
    let c = CImpl { b: b };
    c.foo();
}
[jdm@rosencrantz traitinheritance]$ rustc test2.rs 
test2.rs:25:8: 25:21 error: type `@B` does not implement any method in scope named `foo`
test2.rs:25         self.b.foo();
                    ^~~~~~~~~~~~~
@jdm
Collaborator

Here's a simpler testcase:

trait A {
    fn foo();
}

trait B: A {
}

impl int: A {
    fn foo() {}
}

impl int: B {
}

fn main() {
    5.foo();
    (5 as B).foo();
}
[jdm@rosencrantz traitinheritance]$ rustc test3.rs 
test3.rs:33:4: 33:19 error: type `@B` does not implement any method in scope named `foo`
test3.rs:33     (5 as B).foo();
                ^~~~~~~~~~~~~~~
@catamorphism catamorphism was assigned
@catamorphism

Reproduced with 373504 but not critical for 0.6.

@jdm
Collaborator

I guess this is the same as #4100.

@jdm jdm closed this
@catamorphism catamorphism was unassigned by jdm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.