Skip to content

Diagnostic for mismatching argument count is misleading on nightly #96880

Closed
@barafael

Description

@barafael
Contributor

The compiler nicely reports when calling a function with too few arguments:

let ok = Ok();

leads to

error[[E0061]]: this enum variant takes 1 argument but 0 arguments were supplied

The compiler (on nightly) suggests:

help: provide the argument
  |
6 |     let ok = Ok({_});
  |              ~~~~~~~

This looks like a literal fix suggestion. However, the {_} is probably intended as just a placeholder. Obviously inserting that directly yields another compiler error:

error: in expressions, `_` can only be used on the left-hand side of an assignment

See example on playground.

I personally think the warning is already meaningful enough without the provide the argument section (i.e. the way beta and stable handle this).

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-papercutDiagnostics: An error or lint that needs small tweaks.
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
on May 10, 2022
self-assigned this
on May 10, 2022
added a commit that references this issue on Jun 20, 2022

Auto merge of rust-lang#98264 - compiler-errors:missing-arg-placehold…

a5c039c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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

    Participants

    @estebank@compiler-errors@barafael@TaKO8Ki

    Issue actions

      Diagnostic for mismatching argument count is misleading on nightly · Issue #96880 · rust-lang/rust