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

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.
on Dec 17, 2022
Noratrieb

Noratrieb commented on Dec 17, 2022

@Noratrieb
Member

No one should attempt to fix this until my PR where I remove type ascription.

fmease

fmease commented on Dec 23, 2022

@fmease
added
S-blockedStatus: Blocked on something else such as an RFC or other implementation work.
on Dec 23, 2022
fmease

fmease commented on May 3, 2023

@fmease
Member

Unblocked by #109128.

@rustbot label -S-blocked

removed
S-blockedStatus: Blocked on something else such as an RFC or other implementation work.
on May 3, 2023
jieyouxu

jieyouxu commented on May 30, 2023

@jieyouxu
Member

On beta it seems to be fixed?

error: invalid `struct` delimiters or `fn` call arguments
 --> test.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);
  |

error: aborting due to previous error
rustc 1.71.0-beta.1 (eff24c06d 2023-05-29)
binary: rustc
commit-hash: eff24c06d8f4397802b546aa2e52450e1022fc02
commit-date: 2023-05-29
host: x86_64-unknown-linux-gnu
release: 1.71.0-beta.1
LLVM version: 16.0.4
Noratrieb

Noratrieb commented on May 31, 2023

@Noratrieb
Member

Tests:

//~^ ERROR invalid `struct` delimiters or `fn` call arguments

let my = monad_bind(mx, T: Try); //~ ERROR invalid `struct` delimiters or `fn` call arguments

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

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

        Participants

        @fmease@asquared31415@jieyouxu@rustbot@Noratrieb

        Issue actions

          Confusing errors for `call_method(arg_name: value)` when `value` is not a literal · Issue #105810 · rust-lang/rust