Skip to content

Diagnostics: help text for missing left-hand side in arbitrary self type #64252

Closed
@yoshuawuyts

Description

@yoshuawuyts

Forgetting to include the left-hand side of an arbitrary self type can give some confusing errors. This was reported by someone trying to implement a future manually, and the diagnostics threw them off.

I realize diagnostics for arbitrary self types are an open issue, but figured I'd include this variant as to not overlook it. Thanks!

Link to playground

Code

pub fn hello(Box<Self>) {}

Expected

error: expected one of `:` or `@`, found `<`
 --> src/lib.rs:1:17
  |
1 | pub fn hello(Box<Self>) {}
  |              ^ expected one of `:` or `@` here
  |
help: if this is a `self` type, give it a parameter name
  |
1 | pub fn hello(self: Box<Self>) {}
  |              ^^^^^^^^^^^^^^^

error: aborting due to previous error

Current

error: expected one of `:` or `@`, found `<`
 --> src/lib.rs:1:17
  |
1 | pub fn hello(Box<Self>) {}
  |                 ^ expected one of `:` or `@` here

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.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