Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Rust E0061: this function takes 1 argument but 2 were supplied

E0061 counts arguments at the call site. Check the signature, method versus associated function, generic defaults, and trait impls that changed arity.

~5 min readRust
#rust#e0061#compiler-errors#functions
Rust call site plate offering two argument crates to a one-slot function socket

Introduction & Quick Summary

A call that looks right is rejected by arity:

code
error[E0061]: this function takes 1 argument but 2 arguments were supplied --> src/main.rs:9:5 | 9 | calculate(value, rate); | ^^^^^^^^^^^^^^^^^^^^^^ | note: function defined here --> src/lib.rs:3:8 | 3 | pub fn calculate(value: f64) -> f64 { | ^^^^^^^^^ ----------- help: remove the extra argument | 9 - calculate(value, rate); 9 + calculate(value);

Quick answer: the call site and the definition disagree about how many arguments the function takes. E0061 is deliberately literal — it counts arguments and tells you which one to remove — so the fix starts by reading the note: block, which points at the definition the compiler actually resolved.

rust
fn calculate(value: f64) -> f64 { value * 2.0 } fn main() { let value = 3.0; let rate = 0.2; calculate(value); // fix: match the signature }

The interesting cases are the ones where the count is not what it seems: a method call that supplies self, an associated function called with ::, a trait method with a different arity than an inherent one, a tuple-struct constructor, a macro that expands to a function, or a signature that changed because a cfg feature is off. This guide covers each, plus the Rust patterns for optional arguments, which do not exist in the language and must be modelled.

Core Mechanics, Signatures & Reproducible Setup

A Rust function's signature fixes its arity exactly. There are no default parameters, no keyword arguments, and no overloads: two functions with the same name in one scope are a compile error. Variadic calls exist only in FFI (extern "C" with ...) and are unsafe to call.

rust
fn area(width: f64, height: f64) -> f64 { width * height } struct Rect { w: f64, h: f64 } impl Rect { fn new(w: f64, h: f64) -> Self { Rect { w, h } } // 2 args, associated fn area(&self) -> f64 { self.w * self.h } // 1 arg: &self fn scaled(&self, factor: f64) -> f64 { self.area() * factor } // 2: &self, factor } fn main() { let r = Rect::new(2.0, 3.0); // associated function let _ = r.area(); // method: receiver is implicit let _ = r.scaled(1.5); let _ = Rect::new(2.0); // E0061: 1 supplied, 2 expected }

Three call forms have different arities for the same underlying code:

Call formWhat is supplied
f(a, b)exactly the parameters
Type::f(&x, a)self explicitly, plus parameters
x.f(a)self implicitly, plus parameters

A reproducible file with the failure modes:

bash
cargo new e0061 && cd e0061 cat > src/main.rs <<'RS' fn greet(name: &str, times: u8) -> String { name.repeat(times as usize) } fn main() { let s = greet("hi"); println!("{s}"); } RS cargo build 2>&1 | head -12

The compiler prints the definition, the call, and a suggestion. In a workspace, the note: block is the important part: with several similarly named functions, it names the one the compiler resolved, which is often not the one you were reading.

Key Comparison Table

MessageLikely causeFix
takes 1 argument but 2 were suppliedextra argument, or a parameter was removeddelete the argument, or restore the parameter
takes 2 arguments but 1 was suppliedmissing argumentsupply it, or use the builder
takes 0 arguments but 1 was suppliedcalling with self a function without oneuse Type::f(x) or drop the receiver
this method takes 1 argument but 0 were suppliedcalled as a method instead of a functionType::method(&value)
expected &str, found String (E0308)right count, wrong typeconvert with &s or s.as_str()
SituationWhy the count differsCorrect call
inherent method&self is implicitvalue.method(arg)
associated functionno receiver at allType::new(arg)
trait method in scopesame name, different traitqualify: Trait::method(&value, arg)
tuple struct constructorconstructor is a functionPoint(x, y)
enum variant with fieldsvariant is a functionShape::Circle(r)
function pointer variabletype includes the aritylet f: fn(i32) -> i32 = double;
Optional-argument needIdiomatic RustCost
one optional valueOption<T> parametercall site passes None
many optional valuesbuilder patternboilerplate, clear call sites
config objectstruct with Defaultone struct type
variadic valuesslice or IntoIteratorcallers pass &[..]
no-argument casesecond function (f, f_default)name explosion

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Method versus associated function

String::from has no receiver; to_string does. Mixing them produces E0061 with a receiver counted as an argument:

rust
let a = String::from("x"); // associated: 1 arg let b = "x".to_string(); // method: 0 args, receiver implicit let c = String::to_string("x"); // E0061: to_string expects &self as the only arg

The last line is legal with the explicit-receiver form String::to_string(&"x".to_string()); it is written here to show what the compiler counts.

2. Trait methods with the same name

Two traits can define the same method with different arities. A call resolves by what is in scope, and an use change can break a working call:

rust
trait Render { fn render(&self) -> String; } trait RenderWith { fn render(&self, width: usize) -> String; } impl Render for Doc { fn render(&self) -> String { String::new() } } impl RenderWith for Doc { fn render(&self, _w: usize) -> String { String::new() } } let d = Doc::default(); let _ = d.render(); // ambiguous if both are in scope (E0034) ... let _ = Render::render(&d); // qualified: unambiguous let _ = RenderWith::render(&d, 80);

When the compiler picks one, the other call site fails with E0061 rather than E0034 — the note: block names which trait it resolved.

3. Constructors, variants and closures

Tuple structs and enum variants are functions, so a wrong field count is E0061:

rust
struct Point(f64, f64); enum Shape { Circle(f64), Rect(f64, f64) } let p = Point(1.0, 2.0); let c = Shape::Circle(1.0); let r = Shape::Rect(1.0); // E0061: 2 fields expected

Closures infer their arity from the call, and passing a closure where a fn pointer is expected fixes it:

rust
let double = |x: i32| x * 2; // Fn(i32) -> i32 fn apply(f: fn(i32) -> i32, v: i32) -> i32 { f(v) } let _ = apply(double, 4);

4. Macros that expand to functions

A macro error can surface as E0061 in the expansion, with a span pointing at your macro call:

rust
println!("{} {}", 1); // E0061 inside format_args! format!("{name}"); // needs a `name` variable or a positional argument vec![0; ]; // wrong arity inside vec!

cargo expand (nightly or a cargo subcommand install) shows the expanded code when the span is not enough, and --message-format=short keeps the output readable.

5. Signatures changed by cfg or by a version bump

A parameter that only exists with a feature enabled changes the arity depending on how the crate is compiled:

rust
#[cfg(feature = "tls")] pub fn connect(host: &str, port: u16, cert: &Path) -> Result<Conn, Error> { ... } #[cfg(not(feature = "tls"))] pub fn connect(host: &str, port: u16) -> Result<Conn, Error> { ... }

The call that supplies three arguments fails in a build where the feature is off. Check the feature set before editing the call (cargo tree -e features), and prefer an options struct so the signature does not depend on a cfg.

6. Optional arguments without default parameters

Rust has no default arguments, so a port from a language that does ends up adding an argument that the definition does not take, or removing one it requires. Model the optionality:

rust
pub struct Config { pub retries: u8, pub timeout_ms: u64 } impl Default for Config { fn default() -> Self { Self { retries: 3, timeout_ms: 1_000 } } } pub fn fetch(url: &str, cfg: &Config) -> Result<Vec<u8>, Error> { ... } // call site fetch("https://example.com", &Config::default())?; fetch("https://example.com", &Config { retries: 0, ..Default::default() })?;

The struct keeps the arity at two and makes new options additive rather than breaking.

The text diff tool is useful when a signature changed between two commits and the call sites were not updated, and the regular expression tester pulls every E0061 location out of a long cargo build --message-format=short log.

Common Compilation/Runtime Mistakes & Version Gotchas

  • Adding _ to "use up" an argument. fn f(a, _b) changes the API for every caller; remove the parameter instead.
  • Calling a method as a function. Type::method(x) is correct, Type::method(x, y) is not: the receiver is the first argument.
  • Assuming &self is optional. It is a parameter in the signature and the first argument in the explicit form.
  • Copying a signature from an older version's docs. Standard library functions do change; the compiler's note: block shows the version you actually link against.
  • Overloading by adding a generic parameter type. Two impl blocks with different trait bounds can look like overloads but resolve to one function at the call site.
  • Mixing fn pointers and closures. A closure that captures requires impl Fn; passing it where fn is expected changes the expected type, not the arity.
  • Edition 2024 gen keyword and unsafe attributes. Unrelated to arity, but a rename that shadows a function name produces "cannot find function" or a different E-code and can be mistaken for a signature problem.

Official documentation: E0061 error index and Functions in the Rust Book.

Official references

primary documentation

The Rust documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Rust work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Rust guides

More in Rust

All Rust guides

The guides filed next to this one in Rust, in library order.