Rust errors / Everything else
Rust compiler error · checked with rustc 1.99.0
Rust error E0061: this function takes N arguments but M were supplied
What it meansA function or method was called with the wrong number of arguments.
What rustc prints
error[E0061]: this function takes 1 argument but 0 arguments were supplied --> main.rs:5:1 | 5 | f(); // error! | ^-- argument #1 of type `i32` is missing | note: function defined here --> main.rs:3:4 | 3 | fn f(u: i32) {} | ^ ------ help: provide the argument | 5 | f(/* i32 */); // error! | +++++++++
Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
Why it happens
- A crate update changed a function signature.
- Forgetting that a method needs an argument (or passing one it does not take).
How to fix it
1. Match the signature
Hover in your editor or read the help line; it lists the expected parameters.
fn area(w: f64, h: f64) -> f64 { w * h }
let a = area(3.0, 4.0);Other wordings of this error
this function takes N arguments but M were supplied, this function takes arguments but were supplied, this method takes arguments but, argument missing, unexpected argument
The compiler team's explanation
An invalid number of arguments was passed when calling a function.
Erroneous code example:
fn f(u: i32) {}
f(); // error!
The number of arguments passed to a function must match the number of arguments specified in the function signature.
For example, a function like:
fn f(a: u16, b: &str) {}
Must always be called with exactly two arguments, e.g., f(2, "test").
Note that Rust does not have a notion of optional function arguments or variadic functions (except for its C-FFI).
From rustc --explain E0061 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0412cannot find type in this scope
- E0515cannot return reference to local variable
- E0728await is only allowed inside async functions and blocks
- E0605non-primitive cast
- E0057this function takes 1 argument but 0 arguments were supplied
- E0060this function takes at least 1 argument but 0 arguments were supplied
- E0062field `x` specified more than once
- E0063missing field `y` in initializer of `Foo`
Up next
Often hit nextE0412: cannot find type in this scopeA related error from the same family.Read it next →Did this answer your question?