Skip to content

Confusing errors for call_method(arg_name: value) when value is not a literal #105810

Closed
@asquared31415

Description

@asquared31415

Given the following code:

Playground

fn uwu(val: i32) {}

fn main() {
    let x = 1_i32;
    uwu(val: x);
}

The current output is:

error[E0425]: cannot find value `val` in this scope
 --> src/main.rs:5:9
  |
5 |     uwu(val: x);
  |         ^^^ expecting a type here because of type ascription

error[E0573]: expected type, found local variable `x`
 --> src/main.rs:5:14
  |
5 |     uwu(val: x);
  |              ^ expecting a type here because of type ascription

Ideally the output should look like it does when value is a literal, like an integer, float, or string literal

error: invalid `struct` delimiters or `fn` call arguments
 --> src/main.rs:5:5
  |
5 |     uwu(val: x);
  |     ^^^^^^^^^^^^^^^
  |
help: if `uwu` is a struct, use braces as delimiters
  |
5 |     uwu { val: x };
  |         ~        ~
help: if `uwu` is a function, use the arguments directly
  |
5 -     uwu(val: x);
5 +     uwu(x);
  |

Diagnostics reproduce on all of current stable, beta, and nightly:
Stable 1.66.0
Beta 1.67.0-beta.2
Nightly 1.68.0 2022-12-15

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