1 This error indicates that the `self` parameter in a method has an invalid
4 Methods take a special first parameter, of which there are three variants:
5 `self`, `&self`, and `&mut self`. These are syntactic sugar for
6 `self: Self`, `self: &Self`, and `self: &mut Self` respectively.
12 // ^^^^^ `self` here is a reference to the receiver object
17 // ^^^^^ the receiver type is `&Foo`
21 The type `Self` acts as an alias to the type of the current trait
22 implementer, or "receiver type". Besides the already mentioned `Self`,
23 `&Self` and `&mut Self` valid receiver types, the following are also valid:
24 `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
25 (where P is one of the previous types except `Self`). Note that `Self` can
26 also be the underlying implementing type, like `Foo` in the following
39 E0307 will be emitted by the compiler when using an invalid reciver type,
40 like in the following example:
53 The nightly feature [Arbintrary self types][AST] extends the accepted
54 set of receiver types to also include any type that can dereference to
58 #![feature(arbitrary_self_types)]
63 // Because you can dereference `Bar` into `Foo`...
64 impl std::ops::Deref for Bar {
67 fn deref(&self) -> &Foo {
74 // ^^^^^^^^^ ...it can be used as the receiver type
78 [AST]: https://doc.rust-lang.org/unstable-book/language-features/arbitrary-self-types.html