rust-lang / rust-lang/rust-analyzer

Too many arguments generates two diagnostics

Open
#19,491 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer-2025-03-31

rustc version: (eg. output of rustc -V) rustc 1.85.0 (4d91de4e4 2025-02-17)

editor or extension: Zed

relevant settings: N/A

repository link (if public, optional): https://github.com/ConradIrwin/rust-analyzer-repro/blob/main/src/main.rs#L2

code snippet to reproduce:

fn main() {
    foo(1, "Hello, world!");
}

fn foo(_: i32) -> bool {
    true
}

When running rust-analyzer on this file, I see two different diagnostics for the extra function argument:

2:26 - 2:42: Some(Error): expected 1 argument, found 2
2:19 - 2:22: Some(Error): this function takes 1 argument but 2 arguments were supplied
    /Users/conrad/0/rust/test2/src/main.rs: 2:26 - 2:41: unexpected argument #2 of type `&'static str`
    /Users/conrad/0/rust/test2/src/main.rs: 5:3 - 5:6: function defined here
    /Users/conrad/0/rust/test2/src/main.rs: 2:24 - 2:41: remove the extra argument
2:26 - 2:41: Some(Hint): unexpected argument #2 of type `&'static str`
    /Users/conrad/0/rust/test2/src/main.rs: 2:19 - 2:22: original diagnostic
5:3 - 5:6: Some(Hint): function defined here
    /Users/conrad/0/rust/test2/src/main.rs: 2:19 - 2:22: original diagnostic
2:24 - 2:41: Some(Hint): remove the extra argument
    /Users/conrad/0/rust/test2/src/main.rs: 2:19 - 2:22: original diagnostic

If I open the example file and then save it I see "this function takes 1 argument but 2 arguments were supplied" and its related diagnostics. If I then edit the file, I additionally see the "expected 1 argument, found 2" diagnostic.

I think rust-analyzer should pick only one of these to return to the client.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in src/main.rs at the reported call to foo, and compare diagnostics after opening, saving, and editing the file in Zed. Trace the rust-analyzer diagnostics produced for the extra argument and confirm the client receives only one diagnostic for this error condition.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.