Closed
Description
In this example, function f
compiles, but g
does not. To make g
compiles it's necessary to repeat the C
definition bound. For function f
this is not necessary. This seems to be an inconsistency.
trait A {
fn a(&self);
}
trait B where Self: A {
fn b(&self);
}
trait C where for<'a> &'a Self: A {
fn c(&self);
}
fn f<T>(x: &T) where T: B {
x.b();
x.a();
}
fn g<T>(x: &T) where T: C, /*for<'a> &'a T: A*/ { // uncomment to work
x.c();
x.a();
}
fn main() {}
<anon>:19:7: 19:10 error: the trait `for<'a> A` is not implemented for the type `&'a T` [E0277]
<anon>:19 x.c();
^~~
<anon>:20:7: 20:10 error: no method named `a` found for type `&T` in the current scope
<anon>:20 x.a();
^~~
<anon>:20:7: 20:10 help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `a`, perhaps you need to implement it:
<anon>:20:7: 20:10 help: candidate #1: `A`
error: aborting due to 2 previous errors
Metadata
Metadata
Assignees
Labels
No labels