Skip to content

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

@lolbinarycat

Description

@lolbinarycat

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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

Development

No branches or pull requests

Issue actions