Skip to content

Error span for missing main function is too large #77968

Closed
@lnicola

Description

@lnicola

I tried this code:

fn foo() {}
fn bar() {}
fn baz() {}

I expected to see this happen:

error[E0601]: `main` function not found in crate `hello`
 --> src/main.rs:4:1
3 | | fn baz() {}
4 | ^ consider adding a `main` function to `src/main.rs`

(or something similar -- an empty last line might be missing).

Instead, this happened:

error[E0601]: `main` function not found in crate `hello`
 --> src/main.rs:1:1
  |
1 | / fn foo() {}
2 | | fn bar() {}
3 | | fn baz() {}
  | |___________^ consider adding a `main` function to `src/main.rs`

This matters for IDE support, because using the whole file as an error span is a bit messy, marking potentially hundreds of lines as an error.

Meta

rustc --version:

rustc 1.49.0-nightly (91a79fb29 2020-10-07)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of 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