Rust
Duplicate Definitions in Impl E0201 Fix
One trait implementation cannot define the same name twice - not two methods, not two associated types or consts, and not a type and a method that share a name. The second definition draws E0201. The fix is to give the block one definition per name: rename one item, remove one, or merge them. This guide shows each duplicated kind failing in a trait impl, the duplicate shapes that draw different codes, the same-name shapes that are legal, and the repairs running.
Written December 1, 2026 · Tested with Rust 1.99.0 · 19 min read
- The rule underneath: one name per trait implementation
- How to read the diagnostic
- The first failure: the index example
- Every kind of item draws the same code in a trait impl
Written December 1, 2026
Tested with Rust 1.99.0
What this guide is
Error E0201 means two associated items were defined with the same identifier inside one trait implementation. The error codes index puts it in one line: "Two associated items (like methods, associated types, associated functions, etc.) were defined with the same identifier."
That one line hides a boundary worth knowing before you start fixing. E0201 is the trait-implementation code: every duplicate inside an impl Trait for Type block draws it, whatever kind of item is duplicated. The same mistake in an inherent impl Type block - even the inherent half of the index's own example - draws a different code, E0592, and a duplicate inside a trait definition or at module level draws E0428. And the same name is often legal: in non-overlapping generic specializations, in an inherent impl next to a trait impl, and in two different traits, it compiles and runs. This guide shows each case with its actual code.
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: one name per trait implementation
A trait implementation is a single contract fulfillment: for each item the trait declares, the impl supplies exactly one definition. A second definition of the same name leaves the compiler with two candidates for one slot, and it rejects the block rather than picking one. Changing the second definition's signature or body does not help - the defect is the repeated name, not what either definition does.
The items in one trait impl also share a single namespace across kinds. A method, an associated function, an associated type, and an associated const in the same impl block must all have different names, even though they are different kinds of item and are used in different positions. The cross-kind examples below show a type Thing and a fn Thing in one trait impl drawing E0201, although no two items in that program are the same kind.
How to read the diagnostic
The header names the repeated identifier and ends with a colon: "duplicate definitions with name baz:". Three spans follow. The trait declaration is labeled "item in trait", the first definition in the impl is labeled "previous definition here", and the second definition - the one the error points at - is labeled "duplicate definition". The repair is always applied to one of the two impl definitions: rename it, remove it, or merge the two into one. The trait declaration span is context, not a third definition to fix.
One reading trap matters in the index example below: a single program can draw E0201 and another code at once, one error per duplicated name. Read each error's code separately instead of assuming the first code covers the whole file.
The first failure: the index example
The index's erroneous example, verbatim apart from the trailing main:
struct Foo(u8);
impl Foo {
fn bar(&self) -> bool { self.0 > 5 }
fn bar() {}
}
trait Baz {
type Quux;
fn baz(&self) -> bool;
}
impl Baz for Foo {
type Quux = u32;
fn baz(&self) -> bool { true }
fn baz(&self) -> bool { self.0 > 5 }
type Quux = u32;
}
fn main() {}
error[E0201]: duplicate definitions with name `baz`:
--> fail_index_full.rs:13:5
|
8 | fn baz(&self) -> bool;
| ---------------------- item in trait
...
12 | fn baz(&self) -> bool { true }
| ------------------------------ previous definition here
13 | fn baz(&self) -> bool { self.0 > 5 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error[E0201]: duplicate definitions with name `Quux`:
--> fail_index_full.rs:14:5
|
7 | type Quux;
| ---------- item in trait
...
11 | type Quux = u32;
| ---------------- previous definition here
...
14 | type Quux = u32;
| ^^^^^^^^^^^^^^^^ duplicate definition
error[E0592]: duplicate definitions with name `bar`
--> fail_index_full.rs:4:5
|
3 | fn bar(&self) -> bool { self.0 > 5 }
| --------------------- other definition for `bar`
4 | fn bar() {}
| ^^^^^^^^ duplicate definitions for `bar`
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0201, E0592.
For more information about an error, try `rustc --explain E0201`.
Three errors, two codes. The two duplicates inside impl Baz for Foo - the method baz and the type Quux - draw E0201. The duplicate bar sits in the inherent impl Foo block, and it draws E0592. The index presents the whole program as the E0201 example without separating the two; the sections below pull each shape apart so the boundary is exact.
Every kind of item draws the same code in a trait impl
A duplicate method is the plainest case. The two definitions may differ in body and still collide, because the name is the defect:
struct Foo(u8);
trait Baz {
fn baz(&self) -> bool;
}
impl Baz for Foo {
fn baz(&self) -> bool { true }
fn baz(&self) -> bool { self.0 > 5 }
}
fn main() {}
error[E0201]: duplicate definitions with name `baz`:
--> fail_trait_impl_dup_method.rs:7:5
|
3 | fn baz(&self) -> bool;
| ---------------------- item in trait
...
6 | fn baz(&self) -> bool { true }
| ------------------------------ previous definition here
7 | fn baz(&self) -> bool { self.0 > 5 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0201`.
An associated function - a function in the impl with no self - is the same case with a different call shape:
struct Foo;
trait Baz {
fn make() -> u32;
}
impl Baz for Foo {
fn make() -> u32 { 1 }
fn make() -> u32 { 2 }
}
fn main() {}
error[E0201]: duplicate definitions with name `make`:
--> fail_trait_impl_dup_assoc_fn.rs:7:5
|
3 | fn make() -> u32;
| ----------------- item in trait
...
6 | fn make() -> u32 { 1 }
| ---------------------- previous definition here
7 | fn make() -> u32 { 2 }
| ^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0201`.
An associated type draws it too. Giving the second definition a different type - u64 instead of u32 - changes nothing:
struct Foo(u8);
trait Baz {
type Quux;
}
impl Baz for Foo {
type Quux = u32;
type Quux = u64;
}
fn main() {}
error[E0201]: duplicate definitions with name `Quux`:
--> fail_dup_assoc_type.rs:7:5
|
3 | type Quux;
| ---------- item in trait
...
6 | type Quux = u32;
| ---------------- previous definition here
7 | type Quux = u64;
| ^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0201`.
And so does an associated const, whatever values the two definitions carry:
struct Foo;
trait Baz {
const LIMIT: u32;
}
impl Baz for Foo {
const LIMIT: u32 = 10;
const LIMIT: u32 = 20;
}
fn main() {}
error[E0201]: duplicate definitions with name `LIMIT`:
--> fail_dup_assoc_const.rs:7:5
|
3 | const LIMIT: u32;
| ----------------- item in trait
...
6 | const LIMIT: u32 = 10;
| ---------------------- previous definition here
7 | const LIMIT: u32 = 20;
| ^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0201`.
Method, associated function, associated type, associated const: the four kinds a trait impl defines, and a repeated name draws E0201 for each of them.
Different kinds, same name, one trait impl: still E0201
The namespace is shared across kinds, so the two definitions do not need to be the same kind of item. An associated type and a method with the same name collide:
struct Foo;
trait Baz {
type Thing;
fn thing_value(&self) -> u32;
}
#[allow(non_snake_case)]
impl Baz for Foo {
type Thing = u32;
fn Thing(&self) -> u32 { 9 }
fn thing_value(&self) -> u32 { 1 }
}
fn main() {}
error[E0201]: duplicate definitions with name `Thing`:
--> fail_trait_impl_type_and_method_same_name.rs:9:5
|
3 | type Thing;
| ----------- item in trait
...
8 | type Thing = u32;
| ----------------- previous definition here
9 | fn Thing(&self) -> u32 { 9 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0201`.
(The real trait in that example also declares thing_value, which the impl defines once; the collision is between type Thing and fn Thing alone.) An associated const and a method collide the same way:
struct Foo;
trait Baz {
const Thing: u32;
fn get(&self) -> u32;
}
#[allow(non_snake_case)]
impl Baz for Foo {
const Thing: u32 = 4;
fn Thing(&self) -> u32 { 5 }
fn get(&self) -> u32 { 1 }
}
fn main() {}
error[E0201]: duplicate definitions with name `Thing`:
--> fail_trait_impl_const_and_method_same_name.rs:9:5
|
3 | const Thing: u32;
| ----------------- item in trait
...
8 | const Thing: u32 = 4;
| --------------------- previous definition here
9 | fn Thing(&self) -> u32 { 5 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0201`.
Renaming is the only repair for a cross-kind collision, because both items are usually wanted: give the method its own name and keep the type or const name the trait declares.
The shape that is not this error: duplicates in an inherent impl
Move the same duplicate out of a trait impl and into an inherent impl, and the code changes. Two methods named bar in one impl Foo block draw E0592, not E0201 - with identical signatures:
struct Foo(u8);
impl Foo {
fn bar(&self) -> bool { self.0 > 5 }
fn bar(&self) -> bool { self.0 > 10 }
}
fn main() {}
error[E0592]: duplicate definitions with name `bar`
--> fail_inherent_dup_method_identical.rs:4:5
|
3 | fn bar(&self) -> bool { self.0 > 5 }
| --------------------- other definition for `bar`
4 | fn bar(&self) -> bool { self.0 > 10 }
| ^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0592`.
- and with different signatures, as in the index example's inherent half, where the second
bartakes noselfat all. Rust has no overloading, so a different signature is not a way out in either block kind.
The inherent code covers the other kinds as well. A duplicate associated function in an inherent impl, fn make() -> u32 { 1 } followed by fn make() -> u32 { 2 }, draws E0592. A duplicate associated const in an inherent impl, const MAX: u32 = 1; followed by const MAX: u32 = 2;, draws E0592. And the cross-kind rule holds there too, under the inherent code: an inherent const Thing: u32 = 4; and an inherent fn Thing(&self) -> u32 { 5 } in one block draw E0592 for the shared name. The boundary between the codes is which kind of impl block holds the duplicate, not which kind of item is duplicated. E0592 has its own guide: Duplicate Method Definition E0592 Fix.
Splitting an inherent duplicate across two blocks does not change the code. fn bar defined in one impl Foo block and again in a second impl Foo block for the same type draws E0592, with the two spans pointing at the two blocks. Inherent impls for one type are read together, so moving the second definition into its own block is not a repair.
What does work: the same name in non-overlapping specializations
The index's own exception: items with the same name are allowed for inherent impl blocks that do not overlap. Two specializations of a generic type can each define the same method:
struct Foo<T>(T);
impl Foo<u8> {
fn bar(&self) -> bool { self.0 > 5 }
}
impl Foo<bool> {
fn bar(&self) -> bool { self.0 }
}
fn main() {
println!("{}", Foo(7u8).bar());
println!("{}", Foo(true).bar());
}
true
true
Each bar belongs to a different concrete type - Foo<u8> and Foo<bool> never overlap - so each type has exactly one bar. The output is true then true: the u8 value 7 passes its > 5 test, and the bool value returns itself.
What does work: an inherent method next to a trait method of the same name
An inherent impl and a trait impl are different blocks with different jobs, so both may define the same name:
struct Foo(u8);
trait Baz {
fn bar(&self) -> bool;
}
impl Foo {
fn bar(&self) -> bool { self.0 > 5 }
}
impl Baz for Foo {
fn bar(&self) -> bool { false }
}
fn main() {
let f = Foo(7);
println!("{}", f.bar());
println!("{}", Baz::bar(&f));
}
true
false
The output shows the resolution rule. Dot syntax, f.bar(), picks the inherent method and prints true. The trait method is still there and still reachable, called by its full path Baz::bar(&f), and prints false. Nothing is duplicated, because each block defines the name once; the two definitions coexist and the call form chooses between them.
The same separation holds across kinds. A method named Thing in an inherent impl and an associated type named Thing in a trait impl live in different blocks, and the program compiles and runs:
struct Foo;
trait Baz {
type Thing;
}
#[allow(non_snake_case)]
impl Foo {
fn Thing(&self) -> u32 { 3 }
}
impl Baz for Foo {
type Thing = u32;
}
fn main() {
println!("{}", Foo.Thing());
}
3
Compare the cross-kind examples above: the collision needs both items in the one trait impl. Splitting them across an inherent impl and a trait impl is legal - though a method named like a type is a naming smell worth avoiding even when the compiler accepts it.
What does work: a trait default replaced, and two traits with one method name
A trait default is not a first definition that the impl then duplicates. A trait may give a method a default body, and the impl replaces it with its own single definition:
struct Foo(u8);
trait Baz {
fn baz(&self) -> bool { false }
}
impl Baz for Foo {
fn baz(&self) -> bool { self.0 > 5 }
}
fn main() {
println!("{}", Foo(7).baz());
}
true
The impl's definition is the one that runs - the output is true, not the default's false. Overriding a default is the designed use of a default, not a duplicate.
Two different traits may also use the same method name, and one type may implement both:
struct Foo(u8);
trait A {
fn bar(&self) -> u32;
}
trait B {
fn bar(&self) -> u32;
}
impl A for Foo {
fn bar(&self) -> u32 { 1 }
}
impl B for Foo {
fn bar(&self) -> u32 { 2 }
}
fn main() {
let f = Foo(0);
println!("{}", A::bar(&f));
println!("{}", B::bar(&f));
}
1
2
Each impl block defines bar once, for a different trait, so there is no duplicate anywhere. The cost is at the call site: plain dot syntax would be ambiguous between the two trait methods, so the calls name the trait, A::bar(&f) and B::bar(&f), and print 1 and 2.
Neighboring codes: E0592, E0428, E0119
Three mistakes sit next to E0201 and are routinely confused with it. Each keeps its own code.
Duplicates in an inherent impl - E0592. Covered in its own section above: any repeated name in an inherent impl, in one block or split across blocks for the same type, draws E0592, "duplicate definitions with name", with the two definitions labeled as each other's "other definition". The repair is the same trio - rename, remove, or merge - under the other code. Its guide is Duplicate Method Definition E0592 Fix.
A duplicate in a trait definition - E0428. The duplicate can be one level up, in the trait itself rather than in any impl:
trait Baz {
fn baz(&self) -> bool;
fn baz(&self) -> bool;
}
fn main() {}
error[E0428]: the name `baz` is defined multiple times
--> fail_trait_def_dup.rs:3:5
|
2 | fn baz(&self) -> bool;
| ---------------------- previous definition of the value `baz` here
3 | fn baz(&self) -> bool;
| ^^^^^^^^^^^^^^^^^^^^^^ `baz` redefined here
|
= note: `baz` must be defined only once in the value namespace of this trait
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0428`.
No impl is involved, so E0201 never appears; the fix is in the trait definition, and every impl of the trait then follows the corrected declaration. The same code covers the module level: two functions named helper at the top level of a file draw E0428, with the note that the name "must be defined only once in the value namespace of this module". E0428 is the code for a name defined twice in a definition namespace - a module, a trait definition - where E0201 and E0592 are the codes for the two kinds of impl block.
A repeated trait impl block - E0119. Writing the whole impl twice is a different failure from duplicating one item inside it:
struct Foo(u8);
trait Baz {
fn baz(&self) -> bool;
}
impl Baz for Foo {
fn baz(&self) -> bool { true }
}
impl Baz for Foo {
fn baz(&self) -> bool { false }
}
fn main() {}
error[E0119]: conflicting implementations of trait `Baz` for type `Foo`
--> fail_two_trait_impl_blocks.rs:8:1
|
5 | impl Baz for Foo {
| ---------------- first implementation here
...
8 | impl Baz for Foo {
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Foo`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0119`.
The compiler rejects the second block as a conflicting implementation before comparing any item inside it, so no E0201 appears even though baz is now defined twice in the program. Keep one impl block per trait-and-type pair and put every item in it - which is also why a duplicate that survives inside that one block is E0201.
The repairs
Rename one definition. This is the repair when both definitions do real, different work - give the second the name that says what it adds:
struct Foo(u8);
impl Foo {
fn bar(&self) -> bool { self.0 > 5 }
fn bar_lenient(&self) -> bool { self.0 > 10 }
}
fn main() {
let f = Foo(7);
println!("{}", f.bar());
println!("{}", f.bar_lenient());
}
true
false
That repair is shown on an inherent impl, where the duplicate drew E0592; the same rename inside a trait impl clears E0201, and it is the only repair for a cross-kind collision, where both items are wanted. Update the call sites to the new name in the same edit.
Remove one definition. This is the repair when the second definition was a leftover - a paste, a stale draft, or an accidental repeat of the first:
struct Foo(u8);
impl Foo {
fn bar(&self) -> bool { self.0 > 5 }
}
fn main() {
println!("{}", Foo(7).bar());
}
true
One definition remains, and every call site uses it. Before deleting, check which of the two bodies the call sites were written against - when the bodies differ, removal is a behavior choice, not a tidy-up.
Merge the two definitions. This is the repair for a trait impl where the two halves each carry part of the intended impl - keep one block, one definition per item, with the body that should win:
struct Foo(u8);
trait Baz {
type Quux;
fn baz(&self) -> bool;
}
impl Baz for Foo {
type Quux = u32;
fn baz(&self) -> bool { self.0 > 5 }
}
fn main() {
println!("{}", Foo(7).baz());
}
true
This is the index example's trait impl with each duplicate merged away: one Quux, one baz, and the program compiles and prints true.
Fixes in reach order
First, check the code before touching anything. E0201 means the duplicate is inside a trait impl; a duplicate in an inherent impl is E0592, in a trait definition or at module level is E0428, and a whole repeated impl block is E0119. The code already tells you which block to open.
Second, in the trait impl the diagnostic names, decide what the second definition was meant to be. If it does different work, rename it - and for a cross-kind collision, where a type or const shares a method's name, renaming the method is the fix, because the trait fixes the other item's name.
Third, if the second definition is a leftover or a repeat, remove it. If the two definitions each carry part of the intended behavior, merge them into one definition with the combined body, and delete the other.
Fourth, if the error is E0119, do not edit items at all: delete one of the two impl blocks, merging its items into the block that stays, one definition per name.
Last, if the same name appears in several places and seems duplicated, check whether the blocks actually differ - different generic specializations, an inherent impl next to a trait impl, two different traits, or a trait default being overridden. Those shapes are legal; leave them alone.
Decision summary
E0201 fired for every duplicate shown inside a trait implementation: a method, an associated function, an associated type, and an associated const each defined twice, and an associated type or const sharing a name with a method in the same impl - always with the header naming the identifier and the spans marking the trait item, the previous definition, and the duplicate definition. It did not fire for duplicates in an inherent impl, which drew E0592 whether the items sat in one block or two, for a duplicate in a trait definition or at module level, which drew E0428, or for a whole trait impl block written twice, which drew E0119. The same name compiled and ran in non-overlapping generic specializations, in an inherent impl next to a trait impl, across an inherent method and a trait associated type, as an override of a trait default, and in two different traits implemented for one type. The index example itself mixes codes: its trait-impl duplicates draw E0201 and its inherent-impl duplicate draws E0592 in a single compile.
Checklist
- One trait implementation defines each name once - methods, associated functions, associated types, and associated consts share a single namespace in the block.
- A different signature or body is not a way out: Rust has no overloading, in either kind of impl block.
- Check the code to find the block: E0201 for a trait impl, E0592 for an inherent impl, E0428 for a trait definition or module, E0119 for a repeated impl block.
- Repair by renaming one definition, removing one, or merging the two - for a cross-kind collision, rename the item the trait does not name.
- Keep one impl block per trait-and-type pair; splitting a duplicate across blocks repairs nothing.
- Leave legal same-name shapes alone: non-overlapping specializations, inherent next to trait impls, two traits with one method name, and defaults being overridden.
Related guides on this site
- E0118 Inherent Impl on Non-Nominal Type Fix
- Inherent Impl on Foreign Type E0116 Fix
- Duplicate Discriminant Value E0081 Fix
- E0200 Unsafe Trait Impl Needs Unsafe Fix
Sources
- Rust error codes index, E0201 - two associated items were defined with the same identifier; the erroneous example duplicates a method and an associated type in a trait impl and a method in an inherent impl, and the page notes that items with the same name are allowed for inherent impl blocks that do not overlap.
- Rust error codes index, E0592 - duplicate definitions with the same name in an inherent implementation, the neighboring code for the inherent-impl shapes shown in this guide.
- Rust error codes index, E0428 - a name defined multiple times in one namespace, the code for duplicates in a trait definition and at module level.
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.