Skip to content

improve suggestion when writing "fn Trait for Ty" instead of "impl Trait for Ty" #105366

Closed
@matthiaskrgr

Description

@matthiaskrgr

Given the following code:

struct Foo;

fn From<i32> for Foo {
    fn from(a: i32) -> Self {
        Foo
    }
}

fn main() {}

The current output is:

error: expected `(`, found keyword `for`
 --> src/main.rs:3:14
  |
3 | fn From<i32> for Foo {
  |              ^^^ expected `(`

I wonder if we can detect that this is supposed to be trait impl, maybe look for <Trait> for <Ty> or something?

Ideally the output should look like:

 --> src/main.rs:3:14
  |
3 | fn From<i32> for Foo {
  | ^^ expected `impl`, found "fn"

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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