Rust

E0593 Closure Argument Count Fix

The caller passes a fixed number of arguments and the closure declares a different number - too few in four of these forms, too many in one. This guide separates five shapes that produce E0593 and matches each one to the same repair in five positions: make the closure's parameter list match the count at the call site, with |_| where the body does not use the argument.

Written November 24, 2026 · Tested with Rust 1.99.1 · 20 min read

By the end of this guide
  • The rule underneath: the caller sets the count
  • How to read the diagnostic
  • The first failure: map with a closure that takes no parameter
  • The second failure: sortby with a one-parameter closure

Written November 24, 2026

Tested with Rust 1.99.1

What this guide is

Error E0593 is a closure supplied with the wrong number of arguments for the place it is going. The error codes index states it in one line: you tried to supply an Fn-based type with an incorrect number of arguments than what was expected. Its example defines a helper bounded by Fn(), passes a closure that takes one argument, and draws this error; its fix is to remove that argument, so the closure takes the number the bound requires.

The five forms in this guide each reproduce E0593 with a small, complete program, and the place that sets the expected count is different in each one. map with a closure that takes no parameter, though map passes each item. sort_by with a one-parameter closure, though a comparison needs two values. A generic helper bounded by Fn() given a one-parameter closure - the index's own shape, and the one form here where the closure takes too many. filter with a closure that takes no parameter, though the predicate is called with each element. And fold with a one-parameter closure, though the fold passes the accumulator and the item. In each family the failing program is small, the full compiler output is shown, and the fix changes only the parameter list between the pipes.

Four neighboring shapes are not E0593 and are not in the families. Calling a closure variable with the wrong number of arguments is E0057. Calling a plain function that way is E0061. Assigning a two-parameter named function item to a one-parameter function pointer is E0308 (assigning a two-parameter closure to that same pointer type is E0593 instead), and a sort_by closure with the right count but the wrong return type is E0308 as well. The traps section shows each one with its real code. One further program in the traps passes a closure that ignores its argument with |_| where one argument is expected, and compiles - it is the boundary of this error, because the counts match even though the body never names the value passed.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.

The rule underneath: the caller sets the count

A closure is, in the words of The Rust Book's closure chapter, an anonymous function you can save in a variable or pass as an argument to another function. When you pass one, the receiving code decides how it will call it, and that decision fixes the number of parameters the closure must declare. The closure does not get to choose a shorter list because its body happens not to need a value, and it does not get a longer list because a value would be handy. The lists must match in number.

The standard library states those counts in the signatures. On the Iterator trait, map is bounded by FnMut(Self::Item) -> B - one argument, the item. filter is bounded by FnMut(&Self::Item) -> bool - one argument, a reference to the item. fold is bounded by FnMut(B, Self::Item) -> B - two arguments, the accumulator and then the item. A generic bound in your own code does the same work: F: Fn() means the helper will call the closure with no arguments, and F: Fn(i32) means it will call it with one.

That is why the error is reported where the closure is supplied, not where it is later called. The mismatch is between two declarations that are both in front of the compiler at that point: the bound or adapter signature, which says how many arguments will be passed, and the closure's own parameter list, which says how many it takes. No run of the program is needed to see the conflict, and changing the body of the closure - what it computes, what it captures, what it returns - does not touch it. Only the list between the pipes matters.

Two directions occur, and both are the same error. A closure that takes fewer arguments than the caller passes leaves a passed value with nowhere to go. A closure that takes more declares a parameter the caller will never supply. The diagnostic names both numbers in each case, so the fix can be read straight off the first line: add parameters until the second number is reached, or remove them until the first number is reached. Where the body does not use a parameter the caller insists on passing, name it _ - the parameter still counts, it is simply ignored, and the compiler's own help on the map and filter forms below suggests exactly that change.

How to read the diagnostic

The header gives both counts in one sentence: "closure is expected to take 1 argument, but it takes 0 arguments". The first number is the caller's, the second is the closure's. Read it in that order and the fix is already stated: the parameter list has to move from the second number to the first.

The spans then point at the two sides. One marker underlines the method or call that sets the expectation - map, sort_by, the helper's name - and is labeled with the expected count. Another marker sits on the closure itself, usually its parameter list, and is labeled with the count it takes. In the generic-helper family the layout is wider: the closure spans several lines, so the compiler draws a bracket from its first line to its last and puts the expected count at the closing end. The reading is the same - find the call that fixes the count, find the closure that misses it.

Some forms carry a help block and some do not, and that difference is worth noticing. In every form checked for this guide the help appears exactly when the closure takes no arguments at all: the compiler offers the |_| change directly, as in the map and filter families, and the same help appears on a zero-parameter fold or sort_by closure. A closure that already takes one or more arguments - the one-parameter sort_by and fold families here - gets no help block, even when its body could simply ignore the missing parameter, and neither does a closure that takes too many. No help block does not mean a different error; the header and the two counts are the whole instruction.

The first failure: map with a closure that takes no parameter

map calls its closure once per item and passes that item in. This closure declares no parameter at all, so there is nowhere for the item to go:

Rust
fn main() {
    let v = vec![1, 2, 3];
    let out: Vec<i32> = v.iter().map(|| 0).collect();
    println!("{:?}", out);
}
Terminal
$ rustc --edition 2021 fail_map.rs -o fail_map
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
 --> fail_map.rs:3:34
  |
3 |     let out: Vec<i32> = v.iter().map(|| 0).collect();
  |                                  ^^^ -- takes 0 arguments
  |                                  |
  |                                  expected closure that takes 1 argument
  |
help: consider changing the closure to take and ignore the expected argument
  |
3 |     let out: Vec<i32> = v.iter().map(|_| 0).collect();
  |                                       +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0593`.

The help makes the fix, and it is worth taking literally: the body returns 0 for every item and never needed the item itself, so the parameter is added and ignored in the same stroke. The result is a vector of three zeroes, one per input element:

Rust
fn main() {
    let v = vec![1, 2, 3];
    let out: Vec<i32> = v.iter().map(|_| 0).collect();
    println!("{:?}", out);
}
Terminal
$ rustc --edition 2021 fix_map.rs -o fix_map
$ ./fix_map
[0, 0, 0]

The output is [0, 0, 0]. Note what |_| is doing: it is still a parameter, still counted, still receives each &i32 in turn - it just binds no name. Where the body does need the item, the same position takes a name instead, |x|, and nothing else about the shape changes. Most E0593s in iterator code are this family: a constant, a captured value, or a zero-argument helper placed where an adapter passes one argument.

The second failure: sort_by with a one-parameter closure

A comparison needs two values. sort_by passes references to two elements on every call, and this closure declares only the first of them:

Rust
fn main() {
    let mut v = vec![3, 1, 2];
    v.sort_by(|a| a.cmp(&1));
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 fail_sort.rs -o fail_sort
error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
 --> fail_sort.rs:3:7
  |
3 |     v.sort_by(|a| a.cmp(&1));
  |       ^^^^^^^ --- takes 1 argument
  |       |
  |       expected closure that takes 2 arguments

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0593`.

There is no help block here - a closure that already takes an argument gets none, as the diagnostic section describes. The body shows the original mistake in concrete form: it compares a against a fixed &1 - the writer reached for one element and a constant because the parameter list only gave them one element. With both parameters present, the comparison is between the two values sort_by actually passes:

Rust
fn main() {
    let mut v = vec![3, 1, 2];
    v.sort_by(|a, b| a.cmp(b));
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 fix_sort.rs -o fix_sort
$ ./fix_sort
[1, 2, 3]

The output is [1, 2, 3], the input sorted ascending. Two-argument closures are where this error tends to hide a logic slip as well as a count slip: if a body mentions only one of two values a comparison or accumulation is supposed to combine, check the parameter list before checking the logic - the missing parameter is often the missing half of the computation.

The third failure: an Fn() helper given a one-parameter closure

This family runs the other way. The helper is bounded by Fn(), so it calls the closure with no arguments - its body is the single line f();. The closure passed to it declares one parameter:

Rust
fn run<F: Fn()>(f: F) {
    f();
}

fn main() {
    run(|y: i32| {
        println!("{}", y);
    });
}
Terminal
$ rustc --edition 2021 fail_generic.rs -o fail_generic
error[E0593]: closure is expected to take 0 arguments, but it takes 1 argument
 --> fail_generic.rs:6:5
  |
6 |       run(|y: i32| {
  |       ^   -------- takes 1 argument
  |  _____|
  | |
7 | |         println!("{}", y);
8 | |     });
  | |______^ expected closure that takes 0 arguments

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0593`.

This is the shape in the error codes index: its example helper is also bounded by Fn(), its closure also takes one argument, and its stated fix is to remove that argument. The diagnostic here draws the closure as a bracket spanning its three lines, with "takes 1 argument" at the parameter list and the expected count at the closing line. Following the index's fix - the closure here only prints a fixed message once it can be called with no arguments:

Rust
fn run<F: Fn()>(f: F) {
    f();
}

fn main() {
    run(|| {
        println!("called");
    });
}
Terminal
$ rustc --edition 2021 fix_generic.rs -o fix_generic
$ ./fix_generic
called

The output is called, printed by the closure when the helper invokes it. When a closure takes too many arguments, there are two candidate fixes and the choice matters: remove the parameter, as here, when the caller's count is the settled contract; or change the bound - Fn(i32), and a matching call inside the helper - when the closure genuinely needs a value the helper has to supply. What does not work is leaving both as they are and hoping a call site somewhere passes the extra value: the bound is checked where the closure is supplied.

The fourth failure: filter with a closure that takes no parameter

filter calls its predicate with each element - a reference to it, per the Iterator trait signature FnMut(&Self::Item) -> bool. This predicate declares no parameter:

Rust
fn main() {
    let v = vec![1, 2, 3];
    let out: Vec<&i32> = v.iter().filter(|| true).collect();
    println!("{:?}", out);
}
Terminal
$ rustc --edition 2021 fail_filter.rs -o fail_filter
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
 --> fail_filter.rs:3:35
  |
3 |     let out: Vec<&i32> = v.iter().filter(|| true).collect();
  |                                   ^^^^^^ -- takes 0 arguments
  |                                   |
  |                                   expected closure that takes 1 argument
  |
help: consider changing the closure to take and ignore the expected argument
  |
3 |     let out: Vec<&i32> = v.iter().filter(|_| true).collect();
  |                                           +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0593`.

The shape is close to the first family, and the help is the same |_| suggestion, but the position is different in one respect: a predicate that ignores its element is a real pattern, not only a stepping stone. Keeping every element, or dropping every element, is sometimes exactly the intent while code is being restructured, and |_| true states that intent in a form the caller accepts:

Rust
fn main() {
    let v = vec![1, 2, 3];
    let out: Vec<&i32> = v.iter().filter(|_| true).collect();
    println!("{:?}", out);
}
Terminal
$ rustc --edition 2021 fix_filter.rs -o fix_filter
$ ./fix_filter
[1, 2, 3]

The output is [1, 2, 3], every element kept. When the predicate does grow a condition, the ignored parameter takes a name and a pattern - the item arrives as &&i32 here, a reference to the reference iter() yields, so conditions usually start with a dereference, |x| **x > 1. The count never changes during that edit; only the name and the body do.

The fifth failure: fold with a one-parameter closure

fold passes two arguments on each step: the accumulator built so far, and the next item. This closure declares only the accumulator:

Rust
fn main() {
    let v = vec![1, 2, 3];
    let total = v.iter().fold(0, |acc| acc);
    println!("{}", total);
}
Terminal
$ rustc --edition 2021 fail_fold.rs -o fail_fold
error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
 --> fail_fold.rs:3:26
  |
3 |     let total = v.iter().fold(0, |acc| acc);
  |                          ^^^^    ----- takes 1 argument
  |                          |
  |                          expected closure that takes 2 arguments

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0593`.

The diagnostic underlines the whole method call for the expected count and the parameter list for the taken count, and offers no help - a closure that already takes an argument gets no help block, so the second parameter has to be added by hand and named for the body to use. Naming the second parameter gives the body the item it was supposed to combine into the total:

Rust
fn main() {
    let v = vec![1, 2, 3];
    let total = v.iter().fold(0, |acc, x| acc + x);
    println!("{}", total);
}
Terminal
$ rustc --edition 2021 fix_fold.rs -o fix_fold
$ ./fix_fold
6

The output is 6, the sum of 1, 2, and 3. fold is the adapter where a missing second parameter most often signals an unfinished body rather than a stray keystroke: the one-parameter version returns the accumulator unchanged, which would compute the initial value for any input. If a fold's closure cannot mention the item, it cannot be folding anything - the count error is the compiler catching that before the program can run and quietly return 0.

The fixes in reach order

  • The closure takes too few arguments and the body does not need the missing one: add |_| - or one _ per missing argument - and leave the body alone. The compiler's help suggests this exact change on the map and filter forms.
  • The closure takes too few and the body does need the value: give the new parameter a name and finish the body with it - the second value in a sort_by comparison, the item in a fold.
  • The closure takes too many: remove parameters until the list matches the bound, as the error codes index does in its Fn() example - or, if the closure truly needs the value, change the bound and the call inside the helper together.
  • The count already matches and the error persists in a different code: the problem is a type, a return value, or a call site, not a parameter list - see the traps.

Traps

  • Calling a closure variable with the wrong number of arguments is E0057, not E0593. The closure in this program is fine; the call underneath it passes nothing. The error codes index gives the cause: an invalid number of arguments was given when calling a closure, and when invoking closures the number of parameters passed must match the definition:
Rust
fn main() {
    let f = |x| x + 1;
    println!("{}", f());
}
Terminal
$ rustc --edition 2021 probe_call.rs -o probe_call
error[E0057]: this function takes 1 argument but 0 arguments were supplied
 --> probe_call.rs:3:20
  |
3 |     println!("{}", f());
  |                    ^-- argument #1 is missing
  |
note: closure defined here
 --> probe_call.rs:2:13
  |
2 |     let f = |x| x + 1;
  |             ^^^
help: provide the argument
  |
3 |     println!("{}", f(/* x */));
  |                      +++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0057`.
Trap
Read the site of the error to tell the two apart: E0593 is reported where a closure is supplied to something that will call it; E0057 is reported at a call you wrote yourself, with the closure's definition shown as a note. The repair differs accordingly - fix the call, not the parameter list. - Calling a plain function with the wrong number of arguments is E0061. No closure is involved at all. The error codes index gives the rule: an invalid number of arguments was passed when calling a function, the number passed must match the number in the function signature, and Rust has no optional function arguments:
Rust
fn add(x: i32) -> i32 {
    x + 1
}

fn main() {
    println!("{}", add());
}
Terminal
$ rustc --edition 2021 probe_fn_call.rs -o probe_fn_call
error[E0061]: this function takes 1 argument but 0 arguments were supplied
 --> probe_fn_call.rs:6:20
  |
6 |     println!("{}", add());
  |                    ^^^-- argument #1 of type `i32` is missing
  |
note: function defined here
 --> probe_fn_call.rs:1:4
  |
1 | fn add(x: i32) -> i32 {
  |    ^^^ ------
help: provide the argument
  |
6 |     println!("{}", add(/* i32 */));
  |                        +++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0061`.

The header names the missing argument's type, and the note points at the function's definition rather than a closure's. Supply the argument at the call site; there is no bound or adapter to adjust. - Assigning a function with the wrong number of parameters to a function pointer is E0308, even though the diagnostic text mentions the parameter count. The error codes index frames it as a type mismatch: the expected type did not match the received type, and the note under this program states the two function types in full:

Rust
fn add2(x: i32, y: i32) -> i32 {
    x + y
}

fn main() {
    let f: fn(i32) -> i32 = add2;
    println!("{}", f(1));
}
Terminal
$ rustc --edition 2021 probe_fn_assign.rs -o probe_fn_assign
error[E0308]: mismatched types
 --> probe_fn_assign.rs:6:29
  |
6 |     let f: fn(i32) -> i32 = add2;
  |            --------------   ^^^^ incorrect number of function parameters
  |            |
  |            expected due to this
  |
  = note: expected fn pointer `fn(i32) -> _`
                found fn item `fn(i32, i32) -> _ {add2}`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

The distinction from the third family is the target type, not the kind of callable: a callable supplied against an Fn bound draws E0593 on a count mismatch whether it is a closure or a named function item, and a closure assigned to a fn pointer type with the wrong count also draws E0593. The E0308 here comes from the combination in this program - a named function item assigned to a fn pointer type. Matching the signature of add2 - or pointing the binding at a one-parameter function - is the fix, not editing a closure. - A sort_by closure with the right count but the wrong return type is also E0308. Both parameters are present; the body returns a bool where a comparison must return an Ordering:

Rust
fn main() {
    let mut v = vec![3, 1, 2];
    v.sort_by(|a, b| a < b);
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 probe_sort_ret.rs -o probe_sort_ret
error[E0308]: mismatched types
 --> probe_sort_ret.rs:3:22
  |
3 |     v.sort_by(|a, b| a < b);
  |                      ^^^^^ expected `Ordering`, found `bool`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

This is the trap that follows the second family in practice: the count is fixed, the error code changes, and the remaining complaint is the one-line body. Return a.cmp(b) - or the ordering the sort needs - rather than a truth value. - A closure that ignores its argument with |_| where one argument is expected compiles. This program is the boundary in a generic setting: the helper is bounded by Fn(i32) and calls the closure with 7, and the closure takes that argument and binds no name for it:

Rust
fn run<F: Fn(i32)>(f: F) {
    f(7);
}

fn main() {
    run(|_| {
        println!("ignored");
    });
}
Terminal
$ rustc --edition 2021 boundary_ignore.rs -o boundary_ignore
$ ./boundary_ignore
ignored

The output is ignored. This is the boundary of E0593: the same helper with a || closure in place of |_| would take one argument too few and draw the error, and with |a, b| one too many. The count is the whole rule - whether the body names, uses, or discards the value passed is a separate question the error never asks.

Checklist

  • The header read for both counts: the expected number first, the taken number second, and the parameter list changed from the second to the first.
  • Too few arguments and the value unused: _ added per missing argument, body untouched.
  • Too few and the value needed: the new parameter named, and the body finished with it - the comparison's second value, the fold's item.
  • Too many: parameters removed to match the bound, or the bound and the helper's internal call changed together when the value is genuinely needed.
  • The error at a call you wrote, not at a supplied closure: E0057 for a closure variable, E0061 for a function - the call site is what gets fixed.
  • A function item against a fn pointer, or a right-count closure returning the wrong type: E0308 - the signature or the return value is what gets fixed.
  • The fixed program run, and its output checked against what the failing program was trying to compute.

Sources

  • Rust, Error codes index: E0593 - an Fn-based type was supplied with an incorrect number of arguments than what was expected; in its example a helper bounded by Fn() is given a closure that takes one argument, and the fix is to remove the argument so the closure takes the number the bound requires.
  • The Rust Book, Closures - closures are anonymous functions that can be saved in a variable or passed as arguments to other functions, created in one place and called elsewhere, and they can capture values from the scope in which they are defined; the chapter's unwrap_or_else example is a closure that takes no parameters, with any parameters appearing between the two vertical pipes.
  • Rust, Iterator trait - map takes a closure bounded by FnMut(Self::Item) -> B, filter a predicate bounded by FnMut(&Self::Item) -> bool, for_each a closure bounded by FnMut(Self::Item), and fold a closure bounded by FnMut(B, Self::Item) -> B, so each adapter fixes the number of arguments it passes.
  • Rust, Error codes index: E0057 - an invalid number of arguments was given when calling a closure; when invoking closures or other implementations of the Fn, FnMut, or FnOnce traits using call notation, the number of parameters passed must match the definition.
  • Rust, Error codes index: E0061 - an invalid number of arguments was passed when calling a function; the number passed must match the number specified in the function signature, and Rust does not have optional function arguments.
  • Rust, Error codes index: E0308 - the expected type did not match the received type; it occurs in several cases, most commonly when calling a function and passing an argument of a different type than the declaration specifies.

Keep Exploring