Skip to content

"associated function without body" error suggestion has incorrect span #83104

Closed
@camelid

Description

@camelid

It suggests

fn foo({ <body> }

when it should suggest

fn foo() { <body> }

or at least suggest

fn foo(){ <body> }

struct Foo;

impl Foo {
    fn foo()
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected one of `->`, `;`, `where`, or `{`, found `}`
 --> src/lib.rs:5:1
  |
4 |     fn foo()
  |        ---  - expected one of `->`, `;`, `where`, or `{`
  |        |
  |        while parsing this `fn`
5 | }
  | ^ unexpected token

error: associated function in `impl` without body
 --> src/lib.rs:4:5
  |
4 |     fn foo()
  |     ^^^^^^^-
  |            |
  |            help: provide a definition for the function: `{ <body> }`

error: aborting due to 2 previous errors

error: could not compile `playground`

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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