When using `Box<self>` in first method parameter, the error output provides the wrong type in help message
Open
Nobody has claimed this yet.
A-diagnostics
A-parser
A-suggestion-diagnostics
D-invalid-suggestion
D-papercut
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example from the issue with rustc and compare the current diagnostic against the desired output. Trace the compiler diagnostic path responsible for the anonymous-parameter help message; done means the suggested type uses uppercase Self in Box<Self> while the rest of the diagnostic remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100