Skip to content

diagnostic about typoed path separator could be better #84566

Closed
@comex

Description

@comex

Given this code, where a path separator is typoed as a single instead of double colon:

struct Foo { a: () }

fn main() {
    Foo:new();        
}

the compiler currently outputs:

error[E0423]: expected value, found struct `Foo`
 --> src/main.rs:4:5
  |
1 | struct Foo { a: () }
  | -------------------- `Foo` defined here
...
4 |     Foo:new();        
  |     ^^^ help: use struct literal syntax instead: `Foo { a: val }`

error[E0412]: cannot find type `new` in this scope
 --> src/main.rs:4:9
  |
4 |     Foo:new();        
  |        -^^^ not found in this scope
  |        |
  |        help: maybe you meant to write a path separator here: `::`

This output is quite decent already: the second diagnostic correctly identifies that I meant to write a path separator and suggests a fix. However, before I read the second diagnostic, I naturally read the first diagnostic, which is entirely unhelpful. It would be better if the suggestion could be on the first diagnostic, or if the diagnostics could be combined in some way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.F-type_ascription`#![feature(type_ascription)]`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