Rust

Name Already Used for Generic E0403 Fix

E0403 is a naming collision inside one generic parameter list: the same name appears twice - as two type parameters, two lifetimes, two const parameters, a type and a const parameter with one spelling, or a method parameter that reuses its trait's or impl block's parameter name. The diagnostic points at both uses and labels the second one 'already used'. The repair is always the same move - rename one of the two parameters and update its uses - and this guide shows that repair running for functions, structs, lifetimes, const parameters, and shadowing methods.

Written December 1, 2026 · Tested with Rust 1.99.0 · 16 min read

By the end of this guide
  • The rule underneath: one name, one parameter, per item
  • How to read the diagnostic
  • The first failure: a function with two parameters named T
  • The item does not matter: struct, enum, trait, impl, type alias

Written December 1, 2026

Tested with Rust 1.99.0

What this guide is

Error E0403 means some type parameters have the same name. The error codes index states it in one line - some type parameters have the same name - and its erroneous example is a function declaring the same type parameter twice: fn f<T, T>(s: T, u: T). The index's repair instruction is to verify that none of the type parameters are misspelled and rename any clashing parameters, and its corrected example renames the second parameter: fn f<T, Y>(s: T, u: Y).

The collision is wider than that one function shape. The same name repeated in the generic parameter list of a struct, an enum, a trait, an impl block, or a type alias draws the same error, and so do a repeated lifetime name and a repeated const generic name. The index adds a second family: type parameters in an associated item also cannot shadow parameters from the containing item - its example is a trait method declaring its own T inside a trait that already has a T. Both families are shown failing below, and in every case the fix is a rename.

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, one parameter, per item

A generic parameter list is a set of names the item's body can refer to. If a name appears twice in that list, a use of the name inside the item cannot say which parameter it means, so the compiler rejects the list itself - before any call, instantiation, or use of the item. That is why the error fires on the declaration alone: the failing programs below are never called from main, and they still fail.

The list is also flat across parameter kinds. A type parameter and a const generic parameter that share one spelling collide, because both live in the same list. A lifetime and a type parameter do not: a lifetime's name includes its apostrophe, so 'a and a are different names and can appear in one list together - that boundary is shown below.

The containing item's parameters are part of the picture for associated items. A method inside a trait or an impl block starts its own parameter list, but it may not reuse a type parameter or const parameter name the containing trait or impl already declared. A lifetime is the exception in form, not in outcome: a method that redeclares its containing item's lifetime is also rejected, but under a different error - E0496, "lifetime name 'a shadows a lifetime name that is already in scope" - with its own labels ("first declared here" and "lifetime 'a already in scope") instead of E0403's "first use" and "already used". A separate, nested item is different: a function declared inside another function has no containing-item relationship with it, and reusing the outer function's parameter name there draws no error.

How to read the diagnostic

Every E0403 diagnostic has the same header: "the name T is already used for a generic parameter in this item's generic parameters", with the colliding name in place of T - `N` for a const parameter, `'a` for a lifetime. The span underlines both occurrences: the first is labeled "first use of T" and the second is labeled "already used". There is no help line and no suggested rename; the compiler does not know which parameter you meant to be different, so choosing the new name - and deciding which of the two parameters keeps the old name - is your call.

Read the two span labels, not just the header. The "first use" label tells you which parameter already owns the name, and the "already used" caret tells you which declaration to rename. In the shadowing family the two labels sit in different items - the first use in the trait's or impl block's list, the "already used" caret in the method's list - which is the tell that the collision is between an inner and an outer list rather than inside one list.

The first failure: a function with two parameters named T

The index's own example shape - one function, the same type parameter declared twice:

Rust
fn f<T, T>(s: T, u: T) {}
fn main() {}
Output
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
 --> fail_fn_dup_type.rs:1:9
  |
1 | fn f<T, T>(s: T, u: T) {}
  |      -  ^ already used
  |      |
  |      first use of `T`

error: aborting due to 1 previous error

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

Nothing calls f, and nothing is wrong with its parameter types or its body. The one defect is the list itself: T is declared twice, so neither s: T nor u: T can say which T it means. Rename either declaration - and the uses that belong to it - and the error is gone; the repair is shown running at the end of this guide.

Position in the list does not matter. A repeated name with another parameter between the two uses fails identically, and the labels still point at the first and the repeated use:

Rust
fn f<T, U, T>(a: T, b: U, c: T) {}
fn main() {}
Output
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
 --> fail_fn_dup_type_dist2.rs:1:12
  |
1 | fn f<T, U, T>(a: T, b: U, c: T) {}
  |      -     ^ already used
  |      |
  |      first use of `T`

error: aborting due to 1 previous error

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

The same applies when the repeated name is the second pair rather than the first: a list declaring T, U, U draws E0403 naming U. The compiler reports the repeated name, whichever pair it is.

The item does not matter: struct, enum, trait, impl, type alias

A struct's parameter list follows the same rule:

Rust
struct S<T, T> { a: T, b: T }
fn main() {}
Output
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
 --> fail_struct_dup_type.rs:1:13
  |
1 | struct S<T, T> { a: T, b: T }
  |          -  ^ already used
  |          |
  |          first use of `T`

error: aborting due to 1 previous error

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

An enum, a trait, an impl block, and a type alias each draw the identical header and labels with the same shape - the repeated name underlined once as "first use" and once as "already used":

  • enum E<T, T> { A(T), B(T) } - E0403 naming T.
  • trait Tr<T, T> {} - E0403 naming T.
  • impl<T, T> S<T> {} on a struct S<T> - E0403 naming T.
  • type Alias<T, T> = Option<T>; - E0403 naming T.

The repair does not depend on the item either: rename the second parameter in the list and update the places that referred to it. For a struct, that repair is shown running below.

The kind does not matter: lifetimes and const parameters

A lifetime is a generic parameter too, and repeating one draws the same error, with the name shown including its apostrophe:

Rust
fn f<'a, 'a>(x: &'a i32, y: &'a i32) -> &'a i32 { if *x > *y { x } else { y } }
fn main() {}
Output
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
 --> fail_fn_dup_lifetime.rs:1:10
  |
1 | fn f<'a, 'a>(x: &'a i32, y: &'a i32) -> &'a i32 { if *x > *y { x } else { y } }
  |      --  ^^ already used
  |      |
  |      first use of `'a`

error: aborting due to 1 previous error

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

A repeated lifetime in a struct's list (struct S<'a, 'a>) and in an enum's list draw the same error, as does a repeated lifetime with another lifetime between the two uses (<'a, 'b, 'a>). A const generic parameter behaves the same way - the name is what collides, not the kind:

Rust
fn f<const N: usize, const N: usize>() {}
fn main() { f::<1, 2>(); }
Output
error[E0403]: the name `N` is already used for a generic parameter in this item's generic parameters
 --> fail_fn_dup_const.rs:1:28
  |
1 | fn f<const N: usize, const N: usize>() {}
  |            -               ^ already used
  |            |
  |            first use of `N`

error: aborting due to 1 previous error

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

A repeated const parameter name in a struct's list (struct S<const N: usize, const N: usize>) draws the same error naming N. And the kinds mix: a type parameter and a const parameter with one spelling are one collision, not two separate lists:

Rust
fn f<T, const T: usize>() {}
fn main() {}
Output
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
 --> fail_fn_type_vs_const_same_name.rs:1:15
  |
1 | fn f<T, const T: usize>() {}
  |      -        ^ already used
  |      |
  |      first use of `T`

error: aborting due to 1 previous error

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

That mixing has one exception, and it is the apostrophe. A lifetime 'a and a type parameter a in one list - fn f<'a, a>(x: &'a i32, y: a) - compile: the lifetime's name is 'a, the type parameter's name is a, and different names do not collide. (The compiler does warn that a lowercase type parameter name is not upper camel case; that is a style warning, not this error.)

The second family: a method that shadows its containing item

The index's second example family needs no repeated name inside any single list. Here the trait declares T once, and a method inside the trait declares T again:

Rust
trait Foo<T> { fn do_something(&self) -> T; fn do_something_else<T: Clone>(&self, bar: T); }
fn main() {}
Output
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
 --> fail_trait_method_shadow_trait.rs:1:66
  |
1 | trait Foo<T> { fn do_something(&self) -> T; fn do_something_else<T: Clone>(&self, bar: T); }
  |           - first use of `T`                                     ^ already used

error: aborting due to 1 previous error

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

This is the index's own shadowing example, with its method names kept: do_something_else tries to declare a fresh T, but T already names the trait's parameter, and inside the trait that name is taken. Note the span shape: on this long single line both labels sit on the same line - "first use of T" under the trait's parameter and "already used" under the method's - instead of the stacked labels the shorter examples show.

An impl block behaves the same way. A method that redeclares the impl block's parameter name draws E0403, with the first use labeled in the impl header and the "already used" caret in the method's list:

Rust
struct S<T> { a: T }
impl<T> S<T> { fn m<T>(&self, x: T) {} }
fn main() {}
Output
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
 --> fail_impl_method_shadow_impl.rs:2:21
  |
2 | impl<T> S<T> { fn m<T>(&self, x: T) {} }
  |      -              ^ already used
  |      |
  |      first use of `T`

error: aborting due to 1 previous error

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

A method that repeats a name inside its own list - a trait method declared as fn m<T, T>(...) - is the first family again and draws the same error. The distinction that matters is only where the first use lives: in the same list, or in the containing item's list. The repair is the same in both: rename the method's parameter, never the containing item's - the containing parameter is the one the rest of the trait or impl already refers to. Both repairs are shown running below.

The boundary: separate items may reuse a name

Not every repeated generic name is a collision. A function declared inside another function is its own item, not an associated item of the outer function, so an inner fn inner<T> inside an outer fn outer<T> compiles with no error. Generic names are scoped per item; only an associated item - a method or associated item inside a trait or impl - inherits its containing item's names as taken.

That scoping is also why the ordinary case works: two unrelated functions in one file may both declare <T>, and a method may declare any name its containing item did not use - a method declaring <U> inside an impl<T> compiles cleanly. The question to ask about a name is never whether it appears somewhere else in the file; it is whether it already appears in this item's list or in its containing item's list.

Neighbouring errors: a parameter name and a definition are different collisions

Two nearby duplicate-name errors are not E0403. Repeating a function parameter's name - the value parameter, not a generic parameter - is E0415, "identifier x is bound more than once in this parameter list": fn f(x: i32, x: i32) draws E0415, not E0403. See Duplicate Parameter Name E0415 Fix.

Defining the same item twice is E0428, "the name foo is defined multiple times": two fn foo() definitions in one module draw E0428, not E0403. See Duplicate Definition E0428 Fix.

The three errors split by what is duplicated: a generic parameter name in one list (or shadowed from a containing item) is E0403; a value parameter name in one parameter list is E0415; an item's own name in one module is E0428.

The repair: rename the second parameter

The direct repair for the first failure renames the second parameter from T to Y and updates the use that belonged to it - the index's own corrected example, made runnable:

Rust
fn f<T: std::fmt::Debug, Y: std::fmt::Debug>(s: T, u: Y) { println!("{:?} {:?}", s, u); }
fn main() { f(1, "hi"); }
Output
1 "hi"

The output is 1 "hi": the two parameters are now different types, bound separately, and printed separately. The same rename repairs a struct - the second parameter becomes Y, and the field that used it follows:

Rust
struct Pair<T, Y> { a: T, b: Y }
fn main() { let p = Pair { a: 1, b: "hi" }; println!("{} {}", p.a, p.b); }
Output
1 hi

The output is 1 hi. A repeated lifetime is repaired the same way - give the second lifetime its own name:

Rust
fn pair<'a, 'b>(x: &'a str, y: &'b str) -> (usize, usize) { (x.len(), y.len()) }
fn main() { let (a, b) = pair("ab", "c"); println!("{} {}", a, b); }
Output
2 1

The output is 2 1 - the lengths of the two string slices, each tied to its own lifetime. And a repeated const parameter name:

Rust
fn f<const N: usize, const M: usize>() -> usize { N + M }
fn main() { println!("{}", f::<1, 2>()); }
Output
3

The output is 3 - N + M with N as 1 and M as 2, two parameters where the failing version had one name twice.

The repair: rename the method's parameter, not the container's

For the shadowing family, the rename lands on the inner parameter. The trait keeps its T; the method's clashing parameter becomes U:

Rust
trait Foo<T> { fn get(&self) -> T; fn convert<U: Clone>(&self, bar: U) -> U; }
struct S;
impl Foo<i32> for S { fn get(&self) -> i32 { 7 } fn convert<U: Clone>(&self, bar: U) -> U { bar } }
fn main() { let s = S; println!("{} {}", s.get(), s.convert(9)); }
Output
7 9

The output is 7 9: get returns the trait-parameter type's value, and convert works on its own renamed parameter. The impl version is the same move - the impl block keeps T, the method declares U:

Rust
struct S<T> { a: T }
impl<T: std::fmt::Debug> S<T> { fn m<U>(&self, x: U) -> U { x } }
fn main() { let s = S { a: 1 }; println!("{:?} {}", s.a, s.m(42)); }
Output
1 42

The output is 1 42: the struct's field, of the impl block's T, and the method's argument, of the method's own U, are separate values of separate parameters.

Fixes in reach order

First, read the two span labels. "first use" marks the parameter that owns the name; "already used" marks the declaration to rename. Rename the second one, and update every use inside the item that belonged to the second parameter.

Second, if the two labels sit in different items - the first use in a trait or impl header, the caret in a method - the method's parameter is the one to rename. Do not rename the containing item's parameter to free the name: every other member of the trait or impl already refers to it.

Third, check the kind before assuming a near-miss is safe. A repeated lifetime or const parameter name is the same error as a repeated type parameter name, and a type parameter and a const parameter with one spelling collide. The one spelling pair that does not collide is a lifetime and a type parameter - 'a and a are different names.

Last, if the diagnostic names a different error code, it is a different collision: a repeated value parameter name is E0415 and a repeated item definition is E0428, and each is repaired at its own site.

Decision summary

E0403 fired when one generic parameter name appeared twice in a single item's list - on a function, a struct, an enum, a trait, an impl block, and a type alias, for a type parameter, a lifetime, and a const generic parameter, including a type parameter and a const parameter sharing one spelling, and including a repeated name with another parameter between the two uses - and when an associated item reused its containing item's type parameter name, in a trait method shadowing its trait and a method shadowing its impl block. (A method reusing its containing item's lifetime name is rejected too, but as E0496, not E0403.) It did not fire for a lifetime and a type parameter sharing a spelling ('a and a), for a nested function reusing an outer function's parameter name, or for a method declaring a name its containing item had not used. A repeated value parameter name drew E0415 instead, and a repeated item definition drew E0428 instead. Compiling and running were: the renamed function, struct, lifetime, and const-parameter repairs, the trait whose method renamed its parameter to U, and the impl whose method did the same.

Checklist

  • Read both span labels: rename the parameter marked "already used", keep the one marked "first use".
  • Rename the uses, not just the declaration - every use of the second parameter inside the item takes the new name.
  • In a trait or impl, rename the method's clashing parameter; leave the containing item's parameter alone.
  • Lifetimes and const parameters count: a repeated 'a or const N is the same error as a repeated T.
  • A type parameter and a const parameter with one spelling collide; a lifetime 'a and a type parameter a do not.
  • A repeated name in a separate, nested item is not a collision - only associated items inherit the containing item's names.
  • A duplicate value parameter is E0415 and a duplicate definition is E0428 - different errors, different repairs.

Sources

  • Rust error codes index, E0403 - some type parameters have the same name; the erroneous example declares fn f<T, T>(s: T, u: T), the repair is to verify that none of the type parameters are misspelled and rename any clashing parameters (corrected example fn f<T, Y>(s: T, u: Y)), and type parameters in an associated item also cannot shadow parameters from the containing item, shown with a trait method redeclaring its trait's T.

Keep Exploring