Skip to content

Update error message for self #62609

Closed
@limira

Description

@limira

I did some search and find no similar issue, so here is my report:

Compile the following code:

struct Data;
impl Data {
    fn rc(self: &std::rc::Rc<Self>) {
        println!("&rc");
    }
}

Give the error:

error[E0658]: `&std::rc::Rc<Data>` cannot be used as the type of `self` without the `arbitrary_self_types` feature
 --> src/main.rs:3:17
  |
3 |     fn rc(self: &std::rc::Rc<Self>) {
  |                 ^^^^^^^^^^^^^^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/44874
  = help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`

Think the last line of the error message should be updated to match the current status: https://doc.rust-lang.org/reference/items/associated-items.html which states:

If the type of the self parameter is specified, it is limited to one of the following types:

  • Self
  • &Self
  • &mut Self
  • Box<Self>
  • Rc<Self>
  • Arc<Self>
  • Pin<P> where P is one of the above types except Self.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions