Rust
E0415 Duplicate Parameter Name Fix
A parameter list may not bind one name twice. This guide works the duplicate-name error for a plain function, a method, a closure, a trait implementation, and names bound inside tuple and struct patterns, then separates the real error from the declaration-only shapes that merely look like it.
Written November 30, 2026 · Tested with Rust 1.99.1 · 18 min read
- The rule underneath: parameters are patterns, and patterns bind
- How to read the diagnostic
- The first failure: a plain function
- The same error in a method and an associated function
Written November 30, 2026
Tested with Rust 1.99.1
What this guide is
Error E0415 is one name bound twice in a single parameter list. The error codes index states it in one line - "More than one function parameter have the same name" - and its erroneous example is the smallest form of it, fn foo(f: i32, f: i32) {}, annotated "error: identifier f is bound more than once in this parameter list". Its repair advice is to verify you did not misspell a parameter's name, and its corrected example renames the second parameter to g.
The practical payoff is knowing what counts as a binding. The rule is not "no two parameters may share a name" in the abstract - it is that the list may not bind the same identifier twice, and bindings hide inside patterns as well as in plain names. A name bound once in each of two tuple patterns is the same error as a name typed twice in full, while a name repeated in a place that binds nothing - a trait declaration, an extern declaration, a function pointer type - is no error at all. The forms in this guide each reproduce E0415 with a small, complete program, followed by the shapes that raise no error and the repairs.
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: parameters are patterns, and patterns bind
The functions chapter of the Rust Reference states the fact this error rests on: "Function parameters are irrefutable patterns, so any pattern that is valid in an else-less let binding is also valid as a parameter". A plain name is the simplest pattern, and it binds that name to the argument. A tuple pattern or a struct pattern binds every name inside it. The parameter list therefore produces one set of bindings for the body to use, and a set cannot hold one name twice - the body would have no way to say which argument the name means.
Closure parameters work the same way. The Reference's closure expressions chapter describes a closure as taking a comma-separated list of patterns, and states that "the closure parameters are irrefutable patterns", just like a let binding. So the duplicate-name rule reaches closures unchanged, and it reaches methods and associated functions because those are functions with a parameter list of their own.
Two consequences follow. First, the count that matters is bindings per list, not parameters per list: two parameters that each bind a and b through patterns produce two errors, one per name. Second, places where a parameter name is only a label bind nothing, so the rule does not reach them - a distinction the no-error section below works through in full.
How to read the diagnostic
The header is "identifier x is bound more than once in this parameter list", with the code E0415, naming whichever identifier collided. The single label underlines the later binding - the second occurrence, not the first - and reads "used as parameter more than once". That underline is the exact spot to rename. There is no label on the first binding and no note naming a correct name, because the compiler cannot know which of the two arguments the body means by the shared name.
One warning usually rides along: because the body can only refer to one of the bindings, the other reads as unused, so an "unused variable" warning for the first binding often appears under the error. The warning is a symptom, not the defect - renaming the second binding clears both, and silencing the warning with an underscore prefix does not clear the error, as the _x case below shows.
The first failure: a plain function
This is the index's own shape with a body that uses the name - a two-argument add function in which both parameters are called x:
fn add(x: i32, x: i32) -> i32 { x }
fn main() { println!("{}", add(1, 2)); }
error[E0415]: identifier `x` is bound more than once in this parameter list
--> p1.rs:1:16
|
1 | fn add(x: i32, x: i32) -> i32 { x }
| ^ used as parameter more than once
warning: unused variable: `x`
--> p1.rs:1:8
|
1 | fn add(x: i32, x: i32) -> i32 { x }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0415`.
The label sits on the second x, at column 16. The body's x cannot be assigned to one argument or the other, so the whole definition is rejected - this is not a shadowing situation, because both bindings arrive in the same list at the same time. The repair, renaming one parameter, is worked in the fixes section below.
The same error in a method and an associated function
A method's parameter list follows the self parameter, and the rule applies to it unchanged. Here a counter's add method names both amounts amount:
struct Counter { total: i32 }
impl Counter {
fn add(&mut self, amount: i32, amount: i32) { self.total += amount; }
}
fn main() { let mut c = Counter { total: 0 }; c.add(3, 4); println!("{}", c.total); }
error[E0415]: identifier `amount` is bound more than once in this parameter list
--> p3.rs:3:36
|
3 | fn add(&mut self, amount: i32, amount: i32) { self.total += amount; }
| ^^^^^^ used as parameter more than once
warning: unused variable: `amount`
--> p3.rs:3:23
|
3 | fn add(&mut self, amount: i32, amount: i32) { self.total += amount; }
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_amount`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0415`.
The self parameter does not take part - it binds through its own form, and the collision is between the two ordinary parameters after it. An associated function without a self parameter behaves the same way:
struct S;
impl S { fn new(v: i32, v: i32) -> S { S } }
fn main() { let _s = S::new(1, 2); }
error[E0415]: identifier `v` is bound more than once in this parameter list
--> p15.rs:2:25
|
2 | impl S { fn new(v: i32, v: i32) -> S { S } }
| ^ used as parameter more than once
warning: unused variable: `v`
--> p15.rs:2:17
|
2 | impl S { fn new(v: i32, v: i32) -> S { S } }
| ^ help: if this is intentional, prefix it with an underscore: `_v`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: unused variable: `v`
--> p15.rs:2:25
|
2 | impl S { fn new(v: i32, v: i32) -> S { S } }
| ^ help: if this is intentional, prefix it with an underscore: `_v`
error: aborting due to 1 previous error; 2 warnings emitted
For more information about this error, try `rustc --explain E0415`.
The same error in a closure
A closure's parameter list is a list of patterns between the pipes, and it binds the same way:
fn main() { let f = |x: i32, x: i32| x; println!("{}", f(1, 2)); }
error[E0415]: identifier `x` is bound more than once in this parameter list
--> p4.rs:1:30
|
1 | fn main() { let f = |x: i32, x: i32| x; println!("{}", f(1, 2)); }
| ^ used as parameter more than once
warning: unused variable: `x`
--> p4.rs:1:22
|
1 | fn main() { let f = |x: i32, x: i32| x; println!("{}", f(1, 2)); }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0415`.
Nothing about the closure form softens the rule - no inference is involved, the two bindings are both written out, and the second one is underlined exactly as in a function.
The same error in a trait implementation
A trait implementation supplies a body, so its parameter names are real bindings, and a duplicate fails there:
trait Scale { fn scale(&self, factor: i32, factor: i32) -> i32; }
struct V(i32);
impl Scale for V { fn scale(&self, factor: i32, factor: i32) -> i32 { self.0 * factor } }
fn main() { println!("{}", V(3).scale(2, 5)); }
error[E0415]: identifier `factor` is bound more than once in this parameter list
--> p5.rs:3:49
|
3 | impl Scale for V { fn scale(&self, factor: i32, factor: i32) -> i32 { self.0 * factor } }
| ^^^^^^ used as parameter more than once
warning: unused variable: `factor`
--> p5.rs:3:36
|
3 | impl Scale for V { fn scale(&self, factor: i32, factor: i32) -> i32 { self.0 * factor } }
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_factor`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0415`.
Hold this program next to the trait declaration in the no-error section below: the declaration line at the top of this very program repeats factor too, and draws no error - because a declaration's names bind nothing. Only the implementation, which has a body to bind names for, is checked.
Duplicates inside patterns: one error per name
Because parameters are patterns, a duplicate does not need two identical parameter names written in full - two patterns that bind the same name collide. Two tuple parameters that each bind a and b produce two errors, one for each name:
fn f((a, b): (i32, i32), (a, b): (i32, i32)) -> i32 { a + b }
fn main() { println!("{}", f((1, 2), (3, 4))); }
error[E0415]: identifier `a` is bound more than once in this parameter list
--> p9.rs:1:27
|
1 | fn f((a, b): (i32, i32), (a, b): (i32, i32)) -> i32 { a + b }
| ^ used as parameter more than once
error[E0415]: identifier `b` is bound more than once in this parameter list
--> p9.rs:1:30
|
1 | fn f((a, b): (i32, i32), (a, b): (i32, i32)) -> i32 { a + b }
| ^ used as parameter more than once
warning: unused variable: `a`
--> p9.rs:1:7
|
1 | fn f((a, b): (i32, i32), (a, b): (i32, i32)) -> i32 { a + b }
| ^ help: if this is intentional, prefix it with an underscore: `_a`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: unused variable: `b`
--> p9.rs:1:10
|
1 | fn f((a, b): (i32, i32), (a, b): (i32, i32)) -> i32 { a + b }
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: aborting due to 2 previous errors; 2 warnings emitted
For more information about this error, try `rustc --explain E0415`.
Struct patterns behave identically - two parameters destructuring the same struct bind its field names twice:
struct Pair { a: i32, b: i32 }
fn sum(Pair { a, b }: Pair, Pair { a, b }: Pair) -> i32 { a + b }
fn main() { println!("{}", sum(Pair{a:1,b:2}, Pair{a:3,b:4})); }
error[E0415]: identifier `a` is bound more than once in this parameter list
--> q3.rs:2:36
|
2 | fn sum(Pair { a, b }: Pair, Pair { a, b }: Pair) -> i32 { a + b }
| ^ used as parameter more than once
error[E0415]: identifier `b` is bound more than once in this parameter list
--> q3.rs:2:39
|
2 | fn sum(Pair { a, b }: Pair, Pair { a, b }: Pair) -> i32 { a + b }
| ^ used as parameter more than once
warning: unused variable: `a`
--> q3.rs:2:15
|
2 | fn sum(Pair { a, b }: Pair, Pair { a, b }: Pair) -> i32 { a + b }
| ^ help: try ignoring the field: `a: _`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: unused variable: `b`
--> q3.rs:2:18
|
2 | fn sum(Pair { a, b }: Pair, Pair { a, b }: Pair) -> i32 { a + b }
| ^ help: try ignoring the field: `b: _`
error: aborting due to 2 previous errors; 2 warnings emitted
For more information about this error, try `rustc --explain E0415`.
The count scales with bindings, not with parameters. Three parameters with one name produce two errors, at the second and at the third binding:
fn add(x: i32, x: i32, x: i32) -> i32 { x }
fn main() { println!("{}", add(1, 2, 3)); }
error[E0415]: identifier `x` is bound more than once in this parameter list
--> q1.rs:1:16
|
1 | fn add(x: i32, x: i32, x: i32) -> i32 { x }
| ^ used as parameter more than once
error[E0415]: identifier `x` is bound more than once in this parameter list
--> q1.rs:1:24
|
1 | fn add(x: i32, x: i32, x: i32) -> i32 { x }
| ^ used as parameter more than once
warning: unused variable: `x`
--> q1.rs:1:8
|
1 | fn add(x: i32, x: i32, x: i32) -> i32 { x }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: unused variable: `x`
--> q1.rs:1:16
|
1 | fn add(x: i32, x: i32, x: i32) -> i32 { x }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
error: aborting due to 2 previous errors; 2 warnings emitted
For more information about this error, try `rustc --explain E0415`.
Modifiers do not change the count. Parameters written mut x twice, or ref x twice, fail with the same single error at the second binding - the modifier describes how the name binds, and the name still binds twice.
The underscore trap: _ is free, _x is a name
_x is an ordinary identifier that happens to start with an underscore, so two of them bind the same name twice:fn f(_x: i32, _x: i32) -> i32 { 0 }
fn main() { println!("{}", f(1, 2)); }
error[E0415]: identifier `_x` is bound more than once in this parameter list
--> q2.rs:1:15
|
1 | fn f(_x: i32, _x: i32) -> i32 { 0 }
| ^^ used as parameter more than once
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0415`.
The bare underscore is different: _ is a pattern that binds nothing at all, so it may repeat in one list freely. This function takes three arguments and names only the first:
fn f(x: i32, _: i32, _: i32) -> i32 { x }
fn main() { println!("{}", f(7, 8, 9)); }
7
The output is 7. Use _ for an argument the body genuinely ignores, and a distinct name for every argument the body needs - the underscore prefix is a naming convention, not a way out of the duplicate rule.
The shapes that raise no error: declarations bind nothing
Three shapes repeat a parameter name in writing and compile, because in each of them the name is a label for the reader, not a binding for a body. The Reference puts the underlying fact plainly: functions without a body block "may only appear in a trait or external block" - with no body, there is nothing for a parameter name to bind into.
A trait declaration repeats a name freely. This trait declares scale with factor twice, and the program compiles - the only diagnostic is a dead-code warning because the trait is never used:
trait Scale { fn scale(&self, factor: i32, factor: i32) -> i32; }
fn main() {}
warning: trait `Scale` is never used
--> p6.rs:1:7
|
1 | trait Scale { fn scale(&self, factor: i32, factor: i32) -> i32; }
| ^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: 1 warning emitted
An extern block declaration does the same:
extern "C" { fn ext(x: i32, x: i32); }
fn main() {}
warning: function `ext` is never used
--> p11.rs:1:17
|
1 | extern "C" { fn ext(x: i32, x: i32); }
| ^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: 1 warning emitted
And a function pointer type may repeat a name, because a type describes a signature without binding anything:
type F = fn(x: i32, x: i32) -> i32;
fn main() {}
warning: type alias `F` is never used
--> p13.rs:1:6
|
1 | type F = fn(x: i32, x: i32) -> i32;
| ^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: 1 warning emitted
Two more contrasts complete the boundary. A name that differs only in case is a different identifier - x and X in one list bind two distinct names and compile, drawing only a style warning for the non-snake-case X. And a duplicate created later, in the body, is not this error at all: a let binding with the parameter's own name shadows it legally, so a function that opens with let x = x + 1; compiles and returns the shadowed value.
Fixes in reach order
The repair is always the same move - give every binding in the list a distinct name, choosing the name that says what that argument is. Applied to the first failure, renaming the two parameters for their roles:
fn add(first: i32, second: i32) -> i32 { first + second }
fn main() { println!("{}", add(1, 2)); }
3
The output is 3. Any distinct names work - the index's own repair renames the second parameter to a new letter - but role names repay the small effort, because the body now says which argument each line uses, and a future edit is less likely to reintroduce the collision.
The method repair renames the second amount for what it adds:
struct Counter { total: i32 }
impl Counter {
fn add(&mut self, amount: i32, bonus: i32) { self.total += amount + bonus; }
}
fn main() { let mut c = Counter { total: 0 }; c.add(3, 4); println!("{}", c.total); }
7
The output is 7, and the body now uses both arguments - the unused-variable warning goes with the error, since it was the same defect seen from the other side. The closure repair is identical in form:
fn main() { let f = |x: i32, y: i32| x + y; println!("{}", f(1, 2)); }
3
For patterns, rename the bindings inside the second pattern - the fields and the tuple positions keep their order, only the bound names change:
fn f((a, b): (i32, i32), (c, d): (i32, i32)) -> i32 { a + b + c + d }
fn main() { println!("{}", f((1, 2), (3, 4))); }
10
The output is 10. For a trait implementation, rename in the implementation only - the declaration may keep its repeated label, though renaming there too keeps the two signatures easy to compare:
trait Scale { fn scale(&self, factor: i32, factor: i32) -> i32; }
struct V(i32);
impl Scale for V { fn scale(&self, factor: i32, extra: i32) -> i32 { self.0 * factor + extra } }
fn main() { println!("{}", V(3).scale(2, 5)); }
11
The output is 11. Last, if one of the two arguments is genuinely unused, do not rename it - replace its name with _, the pattern that binds nothing, and the duplicate disappears with the binding.
Decision summary
E0415, "identifier is bound more than once in this parameter list", is one identifier bound twice in a single parameter list - in a function, a method, an associated function, a closure, or a trait implementation, whether the name is written as a plain parameter or bound inside tuple or struct patterns. The error is reported once per extra binding, underlined at the later binding, and an unused-variable warning for the shadowed binding usually rides along. The repair is to rename one binding so every name in the list is distinct, or to replace an unused binding with _. Three look-alikes are not this error: a trait declaration, an extern declaration, and a function pointer type may repeat a name because those names bind nothing; a repeated bare _ binds nothing either; and a let in the body with the parameter's name is legal shadowing, not a duplicate binding.
Checklist
- The name underlined by E0415 is the later binding - rename that one, or rename the earlier one for its role, so the list binds each name once.
- A body that uses both arguments gets two role names, not a name and an underscore-prefixed copy of it.
- Two patterns in one list bind distinct names in each pattern - check tuple and struct patterns, not only the plain parameter names.
- An argument the body ignores is written
_, never given a repeated name. - A duplicate in a trait declaration, an extern declaration, or a function pointer type needs no repair - but the matching implementation is checked, because there the names bind.
- The unused-variable warning that rides with E0415 clears with the rename; it is not silenced separately.
Related guides on this site
- E0091 Unused Type Parameter Fix
- E0158 Constant Pattern Generic Parameter Fix
- Duplicate Discriminant Value E0081 Fix
- Name Already Used for Generic E0403 Fix
Sources
- Rust error codes index, E0415 - more than one function parameter have the same name, its erroneous example
fn foo(f: i32, f: i32), and its repair of verifying the spelling and renaming the second parameter. - The Rust Reference, Functions - function parameters are irrefutable patterns, any pattern valid in an else-less
letis valid as a parameter, and functions without a body may only appear in a trait or an external block. - The Rust Reference, Closure expressions - a closure takes a comma-separated list of patterns as its parameters, and the closure parameters are irrefutable patterns like a
letbinding.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.