Skip to content

When using Box<self> in first method parameter, the error output provides the wrong type in help message #124657

Open
@sisungo

Description

@sisungo

Code

struct Foo {

}
impl Foo {
    fn invoke(Box<self>) -> i32 {
        0
    }
}

fn main() {}

Current output

error: expected one of `:`, `@`, or `|`, found `<`
 --> main.rs:5:18
  |
5 |     fn invoke(Box<self>) -> i32 {
  |                  ^ expected one of `:`, `@`, or `|`
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a `self` type, give it a parameter name
  |
5 |     fn invoke(self: Box<self>) -> i32 {
  |               +++++
help: if this is a type, explicitly ignore the parameter name
  |
5 |     fn invoke(_: Box<self>) -> i32 {
  |               ++

error: aborting due to 1 previous error

Desired output

error: expected one of `:`, `@`, or `|`, found `<`
 --> main.rs:5:18
  |
5 |     fn invoke(Box<self>) -> i32 {
  |                  ^ expected one of `:`, `@`, or `|`
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a `self` type, give it a parameter name
  |
5 |     fn invoke(self: Box<Self>) -> i32 {
  |               +++++
help: if this is a type, explicitly ignore the parameter name
  |
5 |     fn invoke(_: Box<Self>) -> i32 {
  |               ++

error: aborting due to 1 previous error

Rationale and extra context

The type of the parameter in the error message should be uppercase, Box<Self>. However, a lowercase Box<self> is present.

Other cases

No response

Rust Version

$ rustc --version --verbose
rustc 1.80.0-nightly (79734f1db 2024-05-02)
binary: rustc
commit-hash: 79734f1db8dbe322192dea32c0f6b80ab14c4c1d
commit-date: 2024-05-02
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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