Skip to content

Properly suggest fn when function is used #99906

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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