Skip to content

Improve error message for impl Self #65784

Closed
@sunjay

Description

@sunjay

Suppose you have the following reduced code example:

impl Self {   
}

This gives you the error message:

error[E0391]: cycle detected when processing `<impl at src/lib.rs:1:1: 3:2>`
 --> src/lib.rs:1:6
  |
1 | impl Self {
  |      ^^^^
  |
  = note: ...which again requires processing `<impl at src/lib.rs:1:1: 3:2>`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> src/lib.rs:1:1
  |
1 | impl Self {
  | ^^^^^^^^^

This is confusing because there isn't actually any obvious cycle (unless you know things about compilers). E0391 actually describes itself with an example like this:

trait FirstTrait : SecondTrait {

}

trait SecondTrait : FirstTrait {

}

This looks nothing like the original code example.

We should probably detect this case and provide a more useful message that indicates that Self is a special keyword that can be used within the impl block, but not as the type of the impl block itself.

Metadata

Metadata

Assignees

Labels

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