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
Contributor

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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 3, 2024
added
D-confusingDiagnostics: Confusing error or lint that should be reworked.
D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
and removed
D-confusingDiagnostics: Confusing error or lint that should be reworked.
on May 4, 2024
added
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-papercutDiagnostics: An error or lint that needs small tweaks.
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
A-parserArea: The lexing & parsing of Rust source code to an AST
and removed
D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
on May 6, 2024
chenyukang

chenyukang commented on May 7, 2024

@chenyukang
Member

if you apply the suggestion, the next error diagnostic is right:

error: attempt to use a non-constant value in a constant
 --> src/main.rs:5:25
  |
5 |     fn invoke(self: Box<self>) -> i32 {
  |                         ^^^^ help: try using `Self`

I'm not sure we should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @chenyukang@fmease@workingjubilee@sisungo

        Issue actions

          When using `Box<self>` in first method parameter, the error output provides the wrong type in help message · Issue #124657 · rust-lang/rust