Skip to content

Unhelpful error message when missing the final path segment for a function call #120892

Closed
@Jarcho

Description

@Jarcho

Given an invalid call such as:

fn main() {
  foo::("foo");
}

The following diagnostic is issued:

error: expected type, found `"foo"`
 --> src/main.rs:2:9
  |
2 |   foo::("foo");
  |         ^^^^^ expected type

This gets much worse on multiline calls:

fn main() {
  foo::(
    bar(x, y, z),
    bar(x, y, z),
    bar(x, y, z),
    bar(x, y, z),
    bar(x, y, z),
    bar(x, y, z),
    bar(x, y, z),
    baz("test"),
  ),
}

Which just prints out a diagnostic nowhere near the error:

error: expected type, found `"test"`
  --> src/main.rs:10:13
   |
10 |         baz("test"),
   |             ^^^^^^ expected type

Ideally this should mention something about either missing a missing turbofish (e.g. foo::<..>("foo")), or a missing identifier (e.g. foo::bar("foo")). This would at least get the error pointing to the correct spot.


Latest playground nightly (2024-02-09)

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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