1 The `Self` keyword was used outside an impl, trait, or type definition.
3 Erroneous code example:
6 <Self>::foo; // error: use of `Self` outside of an impl, trait, or type
10 The `Self` keyword represents the current type, which explains why it can only
11 be used inside an impl, trait, or type definition. It gives access to the
12 associated items of a type:
20 fn bar() -> Self::Bar; // like this
24 However, be careful when two types have a common associated type:
35 trait Baz : Foo + Foo2 {
36 fn bar() -> Self::Bar;
37 // error: ambiguous associated type `Bar` in bounds of `Self`
41 This problem can be solved by specifying from which trait we want to use the
53 trait Baz : Foo + Foo2 {
54 fn bar() -> <Self as Foo>::Bar; // ok!