Skip to content

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

Closed
@linkmauve

Description

@linkmauve

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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