1 The `self` parameter in a method has an invalid "receiver type".
3 Erroneous code example:
18 Methods take a special first parameter, of which there are three variants:
19 `self`, `&self`, and `&mut self`. These are syntactic sugar for
20 `self: Self`, `self: &Self`, and `self: &mut Self` respectively.
26 // ^^^^^ `self` here is a reference to the receiver object
31 // ^^^^^ the receiver type is `&Foo`
35 The type `Self` acts as an alias to the type of the current trait
36 implementer, or "receiver type". Besides the already mentioned `Self`,
37 `&Self` and `&mut Self` valid receiver types, the following are also valid:
38 `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
39 (where P is one of the previous types except `Self`). Note that `Self` can
40 also be the underlying implementing type, like `Foo` in the following
53 This error will be emitted by the compiler when using an invalid receiver type,
54 like in the following example:
67 The nightly feature [Arbitrary self types][AST] extends the accepted
68 set of receiver types to also include any type that can dereference to
72 #![feature(arbitrary_self_types)]
77 // Because you can dereference `Bar` into `Foo`...
78 impl std::ops::Deref for Bar {
81 fn deref(&self) -> &Foo {
88 // ^^^^^^^^^ ...it can be used as the receiver type
92 [AST]: https://doc.rust-lang.org/unstable-book/language-features/arbitrary-self-types.html