Home › Rust

error[E0061]: this function takes 2 arguments but 1 argument was supplied (Rust) — how to fix

error[E0061]: this function takes 2 arguments but 1 argument was supplied
 --> src/main.rs:6:5
  |
6 |     add(1);
  |     ^^^--- an argument of type `i32` is missing

Quick fix: Pass exactly the parameters in the signature (rustc's note shows which one is missing or extra). For optional values take an Option<T> and pass None, provide a second function or a builder, or update the call after a crate upgrade changed the signature. Methods called as Type::method(x) need self as the first argument.

What it means

The number of arguments in the call does not match the function's parameter list:

fn add(a: i32, b: i32) -> i32 { a + b }

fn main() {
    add(1);   // E0061: takes 2 arguments but 1 argument was supplied
}

Rust has no default arguments, no variadic functions (except through macros such as println!) and no overloading by argument count. rustc usually labels which argument is missing or unexpected, and shows the function definition with a note:; read those lines first.

Cause 1: missing or extra argument

Pass exactly what the signature asks for:

add(1, 2);

If rustc says argument of type X is missing, compare the call with the note: function defined here line it prints.

Cause 2: you want an optional parameter

Common patterns instead of default arguments:

// Option parameter
fn connect(host: &str, port: Option<u16>) {
    let port = port.unwrap_or(5432);
}
connect("db", None);
connect("db", Some(6543));
// two functions
fn connect(host: &str) { connect_with_port(host, 5432) }
fn connect_with_port(host: &str, port: u16) { /* ... */ }

For many optional settings, use a config struct implementing Default:

#[derive(Default)]
struct Opts { port: u16, verbose: bool }

run(Opts { verbose: true, ..Default::default() });

Cause 3: method called with path syntax

A method with &self or self takes the receiver as an implicit first argument with dot syntax, but an explicit one with path syntax:

let s = String::from("hi");
s.len();          // ok
String::len();    // E0061: takes 1 argument but 0 were supplied
String::len(&s);  // ok

Conversely, a function without self (an associated function such as new) must be called as Type::new(...), not on an instance.

Cause 4: tuple vs separate arguments

fn area(w: u32, h: u32) -> u32 { w * h }
let size = (3, 4);
area(size);           // E0061: one tuple argument supplied
area(size.0, size.1); // ok

The same applies to tuple-struct and enum constructors: Some(1, 2) fails, Some((1, 2)) passes a single tuple.

Cause 5: the signature changed after a dependency update

If the error appeared after cargo update or bumping a version in Cargo.toml, the crate's API changed. Check the docs for the version you have (cargo doc --open, or docs.rs for that exact version) and adjust the call, or pin the previous version in Cargo.toml.

Cause 6: closures

Closures are checked too, with a sibling error code: let f = |a, b| a + b; f(1); is E0057, and passing a two-argument closure where an API expects one (e.g. map(|a, b| ...)) is E0593. Use a tuple pattern: iter.map(|(a, b)| a + b).

Last updated 2026-12-02.