pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://doc.rust-lang.org/std/pin/../hash/../../std/sync/../../../std/../error_codes/./E0801.html

ink rel="stylesheet" href="css/general-2459343d.css">

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0801

The self parameter in a method has an invalid generic “receiver type”.

Erroneous code example:

#![allow(unused)]
fn main() {
struct Foo;

impl Foo {
    fn foo<R: std::ops::Deref<Target=Self>>(self: R) {}
}
}

or alternatively,

#![allow(unused)]
fn main() {
struct Foo;

impl Foo {
    fn foo(self: impl std::ops::Deref<Target=Self>) {}
}
}

Methods take a special first parameter, termed self. It’s normal to use self, &self or &mut self, which are syntactic sugar for self: Self, self: &Self, and self: &mut Self respectively. But it’s also possible to use more sophisticated types of self parameter, for instance std::rc::Rc<Self>. The set of allowable Self types is extensible using the nightly feature Arbitrary self types. This will extend the valid set of Self types to anything which implements std::ops::Deref<Target=Self>, for example Rc<Self>, Box<Self>, or your own smart pointers that do the same.

However, even with that feature, the self type must be concrete. Generic self types are not permitted. Specifically, a self type will be rejected if it is a type parameter defined on the method.

These are OK:

#![allow(unused)]
fn main() {
struct Foo;

impl Foo {
    fn foo(self) {}
    fn foo2(self: std::rc::Rc<Self>) {} // or some other similar
        // smart pointer if you enable arbitrary self types and
        // the pointer implements Deref<Target=Self>
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy