Skip to content
New issue

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

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

Already on GitHub? # to your account

Suggest a title case change when Self is mistyped as self #110642

Closed
linkmauve opened this issue Apr 21, 2023 · 0 comments · Fixed by #111460
Closed

Suggest a title case change when Self is mistyped as self #110642

linkmauve opened this issue Apr 21, 2023 · 0 comments · Fixed by #111460
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@linkmauve
Copy link
Contributor

Code

struct Foo;

impl Foo {
    fn do_something(self: Box<self>) -> Box<self> {
        self
    }
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0435]: attempt to use a non-constant value in a constant
 --> src/lib.rs:4:31
  |
4 |     fn do_something(self: Box<self>) -> Box<self> {
  |                     ----      ^^^^
  |                     |
  |                     this would need to be a `const`

error[E0435]: attempt to use a non-constant value in a constant
 --> src/lib.rs:4:45
  |
4 |     fn do_something(self: Box<self>) -> Box<self> {
  |                     ----                    ^^^^
  |                     |
  |                     this would need to be a `const`

For more information about this error, try `rustc --explain E0435`.
error: could not compile `playground` due to 2 previous errors

Desired output

Instead, rustc should suggest a change from `self` to `Self`, I think there is no case where `self` can appear like that in arguments or return type as it isn’t a type, but the current error message is definitely not clear to a newbie.

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

@linkmauve linkmauve added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 21, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 11, 2023
…mpiler-errors

Improve suggestion for `self: Box<self>`

Fixes rust-lang#110642
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 11, 2023
…mpiler-errors

Improve suggestion for `self: Box<self>`

Fixes rust-lang#110642
@bors bors closed this as completed in 6641b49 May 12, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

1 participant