Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error message for self #62609

Closed
limira opened this issue Jul 12, 2019 · 6 comments · Fixed by #62712
Closed

Update error message for self #62609

limira opened this issue Jul 12, 2019 · 6 comments · Fixed by #62712
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@limira
Copy link
Contributor

limira commented Jul 12, 2019

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.
@limira
Copy link
Contributor Author

limira commented Jul 12, 2019

But it is better if Rust supports self: &Rc<Self>, is it possible?

@hellow554
Copy link
Contributor

It's not yet possible. See the compiler output:

cannot be used as the type of self without the arbitrary_self_types feature

See the unstable book for that feature flag. So you have to use a nightly compiler and opt into that feature to use it. There's nothing werong here. The reference is referencing the nightly compiler and not the stable one.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 12, 2019
@limira
Copy link
Contributor Author

limira commented Jul 12, 2019

At least self: Rc<Self> works on stable (unless I am confused), but the error message only suggest &self, &mut self, or self: Box<Self>.

@hellow554
Copy link
Contributor

Upsidaisy. you're right, my bad. Would you think you could do a PR and improve that? Should be fairly easy. Ask here if you need some guidance.

@limira
Copy link
Contributor Author

limira commented Jul 12, 2019

I do a quick search and found at least 3 instances of help with the same content in wfcheck: the first here, the second on L825, the third is on L832 (all in the same file). If I do it, I want to replace them with a

    const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, \
                                     `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one \
                                     of the previous types except `Self`)";

then use .help(HELP_FOR_SELF_TYPE) in all 3 locations.

Anything else do I need to pay attention?

Hope it goes well, because I don't think I will try to compile Rust on my tiny machine!

@limira
Copy link
Contributor Author

limira commented Jul 16, 2019

I create a PR #62712

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 18, 2019
Update the help message on error for self type

Fix rust-lang#62609
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants