Skip to content

Properly suggest fn when function is used #99906

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

Closed
ghost opened this issue Jul 29, 2022 · 2 comments
Closed

Properly suggest fn when function is used #99906

ghost opened this issue Jul 29, 2022 · 2 comments
Labels
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.

Comments

@ghost
Copy link

ghost commented Jul 29, 2022

Given the following code:

function foo() {}

The current output is:

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `foo`
 --> src/main.rs:2:11
  |
2 |  function foo() {}
  |           ^^^ expected one of 8 possible tokens

Ideally the output should look like: help: you likely meant to define a function using the `fn` keyword instead


Rustc already does this to an extent, for eg. here

pub function foo() {}
error: visibility `pub` is not followed by an item
 --> src/main.rs:2:1
  |
2 | pub function foo() {}
  | ^^^ the visibility
  |
  = help: you likely meant to define an item, e.g., `pub fn foo() {}`

However, using a similar implementation to #99903, this could become ideal.

@rustbot claim

@ghost ghost 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. labels Jul 29, 2022
@rustbot rustbot assigned ghost Jul 29, 2022
@Rageking8
Copy link
Contributor

Possible duplicate of #99751

@ghost
Copy link
Author

ghost commented Jul 29, 2022

Ah, that is a duplicate. Thanks for reporting!

@ghost ghost closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2022
This issue was closed.
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant