rust-lang / rust-lang/rust

extra argument to function with complex signature results in rustc telling you to remove 2 arguments

Open
#145,666 0 comments 0 reactions 1 assignee View on GitHub

@xizheyin is already working on this.

Since Aug 21, 2025.

A-diagnostics D-invalid-suggestion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn foo(_c: &mut Option<u32>, _d: impl std::any::Any) {}

fn bar() {
    foo("bad", &mut Some(3_u32), 4_u64);
}
Current output
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
 --> src/lib.rs:4:5
  |
4 |     foo("bad", &mut Some(3_u32), 4_u64);
  |     ^^^                          ----- unexpected argument #3 of type `u64`
  |
note: types differ in mutability
 --> src/lib.rs:4:9
  |
4 |     foo("bad", &mut Some(3_u32), 4_u64);
  |         ^^^^^
  = note: expected mutable reference `&mut Option<u32>`
                     found reference `&'static str`
note: function defined here
 --> src/lib.rs:1:4
  |
1 | fn foo(_c: &mut Option<u32>, _d: impl std::any::Any) {}
  |    ^^^ --------------------
help: remove the extra argument
  |
4 -     foo("bad", &mut Some(3_u32), 4_u64);
4 +     foo(/* &mut Option<u32> */, &mut Some(3_u32));
  |

For more information about this error, try `rustc --explain E0061`.
Desired output
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
 --> src/lib.rs:4:5
  |
4 |     foo("bad", &mut Some(3_u32), 4_u64);
  |     ^^^                          ----- unexpected argument #3 of type `u64`
  |
help: remove the extra argument
  |
4 -     foo("bad", &mut Some(3_u32), 4_u64);
4 +     foo(&mut Some(3_u32), 4_u64);
  |

For more information about this error, try `rustc --explain E0061`.
Rationale and extra context

it seems like the "types differ in mutability" logic is conflicting with the other logic of the diagnostic.

Other cases

Rust Version
(2025-08-19 49fc0cc3e9ae608b4938)
Anything else?

No response

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.