Skip to content

E0599 doesn't show enough context for misformatted code #108603

Closed
@punkeel

Description

@punkeel

Code

// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7c60867045215214d0aae813162a5cf5

use std::collections::HashMap;

fn main() -> Result<(), ()> {
    HashMap::
    Ok(())
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0599]: no associated item named `Ok` found for struct `HashMap` in the current scope
 --> src/main.rs:5:5
  |
5 |     Ok(())
  |     ^^ associated item not found in `HashMap<_, _, _>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0599]: no associated item named `Ok` found for struct `HashMap` in the current scope
 --> src/main.rs:5:5
  |
+ 4 |     HashMap::
5 |     Ok(())
  |     ^^ associated item not found in `HashMap<_, _, _>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

Rationale and extra context

The error is correct when the code is properly formatted, otherwise it doesn't show enough code-context.

This happened to me today as I was making changes to a file, literally typed SomeType:: .. then Run (cargo run), and was greeted by this error.

Other cases

No response

Anything else?

No response

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