Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
matthiaskrgr opened this issue Dec 6, 2022 · 1 comment · Fixed by #105502
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 6, 2022

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"
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Dec 6, 2022
@chenyukang
Copy link
Member

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 14, 2022
… r=estebank

Suggest impl in the scenario of typo with fn

Fixes rust-lang#105366
@bors bors closed this as completed in b70a869 Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants