Rust
E0223 Ambiguous Associated Type Fix
An associated type gets its concrete type from an implementation, so naming it through a trait alone - or through a type that implements two traits defining it - leaves the compiler with no way to know which one you mean. This guide works the shapes that produce E0223, shows the fully-qualified repair the diagnostic itself proposes, and separates the neighboring shapes - generic bounds, method collisions, unimplemented traits - that fail under different codes.
Written November 30, 2026 · Tested with Rust 1.99.1 · 20 min read
- The rule underneath: an associated type is concrete only in an implementation
- How to read the diagnostic
- The first failure: the trait alone names no concrete type
- Two traits, one type: the collision form
Written November 30, 2026
Tested with Rust 1.99.1
What this guide is
Error E0223 is an ambiguous associated type lookup. The error codes index opens with the cause in one sentence - "An attempt was made to retrieve an associated type, but the type was ambiguous" - and its erroneous example is the first failure in this guide: an associated type named through the trait alone, Trait::X, with no implementing type in the path at all. Its working version names both: <Struct as Trait>::X. That fully-qualified form is the repair for every E0223 program in this guide whose help lists real candidates; the trap programs near the end fail for other reasons - a trait that is not implemented, or a name no trait defines - and qualifying does not repair them.
The practical payoff is that E0223 is a missing piece of the path, not a missing implementation. In the collision, single-candidate, and scope programs below, the implementations the path could mean exist and are complete; what the written path lacks is the trait choice. The trait-alone first failure and the trap programs are the exceptions: there an implementation, or the name itself, is what is missing, as their sections show. The diagnostic's help writes that choice for you, once per candidate trait. The neighboring guide on E0034 covers the same two-traits collision for methods, associated functions, and associated constants; this guide is about associated types, where the collision - and, in the probed set, even a single candidate - lands on E0223 instead.
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: an associated type is concrete only in an implementation
The Rust Reference's traits section states the fact the whole error turns on: "Associated types must never define the type, the type may only be specified in an implementation." A trait declaration says that an associated type exists; it does not say what it is. So a path that stops at the trait - Trait::X - names something that has no concrete type yet, and a path that stops at a type implementing two traits that both define the item - S::Item - names two different concrete types at once. Both are the same defect from the compiler's side: the path does not determine one implementation.
The fully-qualified path is the form that determines one. The Reference's paths section states that fully qualified paths "allow for disambiguating the path for trait implementations": <S as A>::Item names the item as reached through S's implementation of A specifically, so exactly one concrete type remains. Every repair in this guide is that one move, applied in a function signature, a let annotation, a type alias, and a generic bound.
One consequence is worth stating plainly, because the probed set shows it twice: in every failing program in this guide, the bare Type::Item form failed - including the program where only one trait defines the item at all. Do not read E0223 as proof that two traits are colliding in your code; read it as proof that the path did not name a trait, and check the candidate list in the help to see how many traits were actually in play.
How to read the diagnostic
The header is fixed: "ambiguous associated type", with the span under the whole path that failed - Trait::X, S::Item. There are no candidate notes of the kind E0034 prints; instead the help block carries the information, offering one fully-qualified replacement per candidate trait: "use fully-qualified syntax", then each <S as Trait>::Item form as a replacement line. Read the offered forms as the menu - they name exactly the traits the repair can choose between.
Two details in the help deserve attention. First, in the two-trait programs below, the help also offers standard-library traits the type could implement - <S as IntoIterator>::Item and <S as IntoAsyncIterator>::Item appear alongside the two traits actually implemented. Those are possibilities, not candidates: the compiler is listing other traits that define an Item, not reporting that S implements them. Second, when the path names a trait alone and no type in the program implements that trait, as in the first failure, the help changes shape: it cannot name a concrete type for you, so it shows a placeholder - "if there were a type named Example that implemented Trait, you could use the fully-qualified path" - and leaves you to supply the implementing type from your own code. When an implementing type does exist in the program, the help instead offers that type's fully-qualified form directly, like any other candidate.
The first failure: the trait alone names no concrete type
This is the error index's own example, as a complete program - a trait declaring an associated type X, named in a let annotation with no implementing type anywhere in the path:
trait Trait { type X; }
fn main() { let foo: Trait::X; }
error[E0223]: ambiguous associated type
--> q1.rs:2:22
|
2 | fn main() { let foo: Trait::X; }
| ^^^^^^^^
|
help: if there were a type named `Example` that implemented `Trait`, you could use the fully-qualified path
|
2 - fn main() { let foo: Trait::X; }
2 + fn main() { let foo: <Example as Trait>::X; }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
Nothing is missing from the trait - an associated type is supposed to be left abstract there. The defect is in the annotation: Trait::X asks for a concrete type that only an implementation can supply, and the path names no implementation. The error index explains the same point in prose: the type of X "is not defined, because it's only made concrete in implementations of the trait". The repair, run in the fixes section, is to name an implementing type and the trait together.
Two traits, one type: the collision form
The shape most readers meet E0223 through: a type implementing two traits that both define the same associated type - here with deliberately different concrete types, i32 through A and i64 through B - named through the type alone in a function parameter:
struct S;
trait A { type Item; }
trait B { type Item; }
impl A for S { type Item = i32; }
impl B for S { type Item = i64; }
fn f(x: S::Item) {}
fn main() { f(3); }
error[E0223]: ambiguous associated type
--> q2.rs:6:9
|
6 | fn f(x: S::Item) {}
| ^^^^^^^
|
help: use fully-qualified syntax
|
6 - fn f(x: S::Item) {}
6 + fn f(x: <S as A>::Item) {}
|
6 - fn f(x: S::Item) {}
6 + fn f(x: <S as B>::Item) {}
|
6 - fn f(x: S::Item) {}
6 + fn f(x: <S as IntoAsyncIterator>::Item) {}
|
6 - fn f(x: S::Item) {}
6 + fn f(x: <S as IntoIterator>::Item) {}
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
Here the ambiguity is real, not formal: <S as A>::Item is i32 and <S as B>::Item is i64, so S::Item cannot silently mean either one. The parameter type changes meaning depending on the choice, which is exactly why the compiler refuses to make it.
The same failure appears wherever a type is written. In a let annotation inside a function body:
struct S;
trait A { type Item; }
trait B { type Item; }
impl A for S { type Item = i32; }
impl B for S { type Item = i32; }
fn main() { let x: S::Item = 3; println!("{}", x); }
error[E0223]: ambiguous associated type
--> q4.rs:6:20
|
6 | fn main() { let x: S::Item = 3; println!("{}", x); }
| ^^^^^^^
|
help: use fully-qualified syntax
|
6 - fn main() { let x: S::Item = 3; println!("{}", x); }
6 + fn main() { let x: <S as A>::Item = 3; println!("{}", x); }
|
6 - fn main() { let x: S::Item = 3; println!("{}", x); }
6 + fn main() { let x: <S as B>::Item = 3; println!("{}", x); }
|
6 - fn main() { let x: S::Item = 3; println!("{}", x); }
6 + fn main() { let x: <S as IntoAsyncIterator>::Item = 3; println!("{}", x); }
|
6 - fn main() { let x: S::Item = 3; println!("{}", x); }
6 + fn main() { let x: <S as IntoIterator>::Item = 3; println!("{}", x); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
And in a type alias, where the ambiguous path is written once and reused:
struct S;
trait A { type Item; }
trait B { type Item; }
impl A for S { type Item = i32; }
impl B for S { type Item = i32; }
type Alias = S::Item;
fn main() { let x: Alias = 3; println!("{}", x); }
error[E0223]: ambiguous associated type
--> q5.rs:6:14
|
6 | type Alias = S::Item;
| ^^^^^^^
|
help: use fully-qualified syntax
|
6 - type Alias = S::Item;
6 + type Alias = <S as A>::Item;
|
6 - type Alias = S::Item;
6 + type Alias = <S as B>::Item;
|
6 - type Alias = S::Item;
6 + type Alias = <S as IntoAsyncIterator>::Item;
|
6 - type Alias = S::Item;
6 + type Alias = <S as IntoIterator>::Item;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
In all three positions - parameter, annotation, alias - the header, the span, and the offered repairs are the same. In this guide's probed set, E0223 is one diagnostic for the whole family: any type position that writes S::Item while S implements two traits defining Item.
One trait is not enough: the bare form fails on its own
The collision framing suggests that removing one trait would fix the bare form. In the probed set it does not. Here a single trait defines Item, S implements only that trait, and S::Item still fails with E0223:
struct S;
trait A { type Item; }
impl A for S { type Item = i32; }
fn f(x: S::Item) -> i32 { x }
fn main() { println!("{}", f(3)); }
error[E0223]: ambiguous associated type
--> n1.rs:4:9
|
4 | fn f(x: S::Item) -> i32 { x }
| ^^^^^^^
|
help: use fully-qualified syntax
|
4 - fn f(x: S::Item) -> i32 { x }
4 + fn f(x: <S as A>::Item) -> i32 { x }
|
4 - fn f(x: S::Item) -> i32 { x }
4 + fn f(x: <S as IntoAsyncIterator>::Item) -> i32 { x }
|
4 - fn f(x: S::Item) -> i32 { x }
4 + fn f(x: <S as IntoIterator>::Item) -> i32 { x }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
The help offers exactly one implemented candidate, <S as A>::Item, plus the two standard-library possibilities - and the bare form is still rejected. This matches the error index's own closing remark that, due to limitations of the current compiler implementation, "we cannot simply use Struct::X": the type-alone path to an associated type is not an accepted form in the probed set, whether the candidate count is one or two. The practical reading: when you see E0223, do not spend time hunting for a second trait that may not exist - qualify the path.
Scope does not rescue the bare form either. Here both traits are implemented for S but only A is imported at the use site - the arrangement that resolves a method collision - and the associated-type path fails the same way, with the import itself reported unused:
mod m { pub trait A { type Item; } pub trait B { type Item; } }
struct S;
impl m::A for S { type Item = i32; }
impl m::B for S { type Item = i32; }
use m::A;
fn f(x: S::Item) -> i32 { x }
fn main() { println!("{}", f(3)); }
warning: unused import: `m::A`
--> n2.rs:5:5
|
5 | use m::A;
| ^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error[E0223]: ambiguous associated type
--> n2.rs:6:9
|
6 | fn f(x: S::Item) -> i32 { x }
| ^^^^^^^
|
help: use fully-qualified syntax
|
6 - fn f(x: S::Item) -> i32 { x }
6 + fn f(x: <S as A>::Item) -> i32 { x }
|
6 - fn f(x: S::Item) -> i32 { x }
6 + fn f(x: <S as B>::Item) -> i32 { x }
|
6 - fn f(x: S::Item) -> i32 { x }
6 + fn f(x: <S as IntoAsyncIterator>::Item) -> i32 { x }
|
6 - fn f(x: S::Item) -> i32 { x }
6 + fn f(x: <S as IntoIterator>::Item) -> i32 { x }
|
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0223`.
Note the help offers <S as B>::Item even though B is not in scope at the use site: for associated types in the probed set, the candidate set is the type's implementations, not the traits the call site imported. Narrowing imports - a real repair for method ambiguity - changes nothing here.
The generic form is a different code: E0221
Move the same collision onto a generic parameter and the code changes. A parameter bounded by both traits, with the associated type named through the parameter, fails as E0221 - "ambiguous associated type Item in bounds of T" - not E0223:
trait A { type Item; }
trait B { type Item; }
fn f<T: A + B>(x: T::Item) {}
fn main() {}
error[E0221]: ambiguous associated type `Item` in bounds of `T`
--> q3.rs:3:19
|
1 | trait A { type Item; }
| --------- ambiguous `Item` from `A`
2 | trait B { type Item; }
| --------- ambiguous `Item` from `B`
3 | fn f<T: A + B>(x: T::Item) {}
| ^^^^^^^ ambiguous associated type `Item`
|
help: use fully-qualified syntax to disambiguate
|
3 - fn f<T: A + B>(x: T::Item) {}
3 + fn f<T: A + B>(x: <T as B>::Item) {}
|
help: use fully-qualified syntax to disambiguate
|
3 - fn f<T: A + B>(x: T::Item) {}
3 + fn f<T: A + B>(x: <T as A>::Item) {}
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0221`.
The repair is the same fully-qualified syntax - the fixes section runs it - but the diagnostic is structured differently: the ambiguity is charged to the bounds, each trait definition is labelled as a source of the ambiguous name, and there are no standard-library candidates in the help. If your error names the bounds of a type parameter, you are in E0221 territory; if it names a concrete type's path, E0223. Note also the contrast with the concrete programs: through a generic parameter, T::Item under a single bound is an accepted form, as the last fix shows - the bare form fails on concrete types in the probed set, not on bounded parameters.
The traps: neighbors that are not the two-trait collision
The method version of the two-traits collision is E0034, "multiple applicable items in scope", covered by the neighboring guide:
struct S;
trait A { fn name(&self) -> i32; }
trait B { fn name(&self) -> i32; }
impl A for S { fn name(&self) -> i32 { 1 } }
impl B for S { fn name(&self) -> i32 { 2 } }
fn main() { let s = S; println!("{}", s.name()); }
error[E0034]: multiple applicable items in scope
--> n3.rs:6:41
|
6 | fn main() { let s = S; println!("{}", s.name()); }
| ^^^^ multiple `name` found
|
note: candidate #1 is defined in an impl of the trait `A` for the type `S`
--> n3.rs:4:16
|
4 | impl A for S { fn name(&self) -> i32 { 1 } }
| ^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl of the trait `B` for the type `S`
--> n3.rs:5:16
|
5 | impl B for S { fn name(&self) -> i32 { 2 } }
| ^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method for candidate #1
|
6 - fn main() { let s = S; println!("{}", s.name()); }
6 + fn main() { let s = S; println!("{}", A::name(&s)); }
|
help: disambiguate the method for candidate #2
|
6 - fn main() { let s = S; println!("{}", s.name()); }
6 + fn main() { let s = S; println!("{}", B::name(&s)); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0034`.
The line between the codes is the kind of item: in the probed set, an ambiguous method, associated function, or associated constant on a type is E0034, and an ambiguous associated type is E0223 - with the same fully-qualified repair offered by both.
Qualifying the path does not end the story if the named trait is not implemented for the type. This program uses the correct fully-qualified form, but S does not implement C at all, and the failure is E0277, the unsatisfied-trait-bound error covered by the E0277 guide:
struct S;
trait C { type Item; }
fn f(x: <S as C>::Item) {}
fn main() {}
error[E0277]: the trait bound `S: C` is not satisfied
--> n4.rs:3:9
|
3 | fn f(x: <S as C>::Item) {}
| ^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `C` is not implemented for `S`
--> n4.rs:1:1
|
1 | struct S;
| ^^^^^^^^
help: this trait has no implementations, consider adding one
--> n4.rs:2:1
|
2 | trait C { type Item; }
| ^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
And a qualified path that names an associated type the trait does not define is E0576, "cannot find associated type" - the trait is implemented, the name is wrong:
struct S;
trait A { type Item; }
impl A for S { type Item = i32; }
fn f(x: <S as A>::Missing) {}
fn main() {}
error[E0576]: cannot find associated type `Missing` in trait `A`
--> n6.rs:4:19
|
2 | trait A { type Item; }
| ---------- associated type `Item` defined here
3 | impl A for S { type Item = i32; }
4 | fn f(x: <S as A>::Missing) {}
| ^^^^^^^ not found in `A`
|
help: maybe you meant this associated type
|
4 - fn f(x: <S as A>::Missing) {}
4 + fn f(x: <S as A>::Item) {}
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0576`.
The last trap keeps the E0223 header but is not an ambiguity between real candidates at all. A bare path naming an associated type that no trait in the program defines for the type - S::Missing, where the only trait defines Item - also reports E0223, with a help that invents a hypothetical trait rather than listing candidates:
struct S;
trait A { type Item; }
impl A for S { type Item = i32; }
fn f(x: S::Missing) {}
fn main() {}
error[E0223]: ambiguous associated type
--> n5.rs:4:9
|
4 | fn f(x: S::Missing) {}
| ^^^^^^^^^^
|
help: if there were a trait named `Example` with associated type `Missing` implemented for `S`, you could use the fully-qualified path
|
4 - fn f(x: S::Missing) {}
4 + fn f(x: <S as Example>::Missing) {}
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
Read the help's shape, not just the header: candidate replacements naming your own traits mean a real choice is missing from the path; a hypothetical "if there were a trait named Example" help means the name in the path may not exist at all, and the fix is to correct the name or add the associated type, not to qualify.
Fixes in reach order
When E0223 appears, name the implementing type and the trait in the path - the diagnostic's own help is the first fix. For the error index's example, the working version supplies the implementing type the original omitted:
trait Trait { type X; }
struct Struct;
impl Trait for Struct { type X = u32; }
fn main() { let foo: <Struct as Trait>::X = 7; println!("{}", foo); }
7
The output is 7: <Struct as Trait>::X resolved to the implementation's u32, and the value flowed through the annotation that Trait::X could not type at all. The same form repairs the two-trait collision, and because the two implementations here give Item different concrete types, the output shows the choice mattering:
struct S;
trait A { type Item; }
trait B { type Item; }
impl A for S { type Item = i32; }
impl B for S { type Item = String; }
fn main() { let a: <S as A>::Item = 3; let b: <S as B>::Item = String::from("hi"); println!("{} {}", a, b); }
3 hi
The output is 3 hi: <S as A>::Item is the i32 from A's implementation and <S as B>::Item is the String from B's, each annotation taking its type from the trait it names. This is the honest fix when both traits are legitimately implemented - nothing is removed, nothing is hidden from scope; each use site states which implementation it means.
The generic E0221 form takes the same repair. With both bounds kept, qualify the parameter's associated type through the intended trait:
struct S;
trait A { type Item; }
trait B { type Item; }
impl A for S { type Item = i32; }
impl B for S { type Item = String; }
fn get<T: A + B>(x: <T as A>::Item) -> <T as A>::Item { x }
fn main() { println!("{}", get::<S>(3)); }
3
The output is 3, the i32 that A's implementation assigns, returned through <T as A>::Item on both sides of the signature. Last, where the generic code only ever needs one trait's associated type, the simpler repair is to bound by that trait alone - under a single bound in the probed set, the bare T::Item form is accepted:
struct S;
trait A { type Item; }
trait B { type Item; }
impl A for S { type Item = i32; }
impl B for S { type Item = String; }
fn get<T: A>(x: T::Item) -> T::Item { x }
fn main() { println!("{}", get::<S>(3)); }
3
The output is 3. Note the asymmetry this leaves you with, stated only for the probed set: a bounded generic parameter accepts the bare T::Item form under one bound, while a concrete type's bare S::Item was rejected even with one candidate trait - so a fix that works in generic code does not license the same spelling at a concrete use site. And if the diagnostic is not E0223 at all, switch playbooks: bounds ambiguity on a generic parameter is E0221 (same repair, above), a method or associated-function collision is E0034, an unimplemented trait in a qualified path is E0277 - which qualifying harder will not fix - and a wrong associated-type name in a qualified path is E0576.
Decision summary
E0223, "ambiguous associated type", covers two shapes in this guide's probed set: an associated type named through a trait alone (Trait::X), where no implementation is named at all, and an associated type named through a concrete type (S::Item) without naming a trait. The second shape failed in every probed position - function parameter, let annotation, type alias - and failed even when only one trait defined the item and when only one of two traits was in scope: in the probed set the bare concrete-type form is not accepted, full stop. The repair names the choice: <Type as Trait>::Item, which also repairs the generic-bounds version of the collision, reported separately as E0221. The neighbors are distinct: a method, associated-function, or associated-constant collision is E0034, a qualified path naming a trait the type does not implement is E0277, a qualified path naming an associated type the trait does not define is E0576, and a bare path naming a nonexistent associated type keeps the E0223 header but shows a hypothetical-trait help instead of candidate replacements.
Checklist
- Read the help's shape first: candidate replacements naming your traits mean qualify the path; a hypothetical
Exampletrait means the name in the path may not exist. - Qualify with
<Type as Trait>::Item- do not hunt for a second trait first; in the probed set the bare form fails with one candidate too. - Ignore the standard-library entries in the help (
IntoIterator,IntoAsyncIterator) unless your type actually implements those traits - they are possibilities, not candidates. - Do not try to fix an associated-type path by narrowing imports; in the probed set the candidate set is the type's implementations, not the traits in scope.
- In generic code, either qualify as
<T as Trait>::Itemor bound the parameter by the one trait whose associated type you mean. - Tell the codes apart by what the path did: no trait named on a concrete type or trait is E0223, ambiguous bounds on a generic parameter is E0221, a value-item collision is E0034, an unimplemented trait is E0277, a wrong associated-type name in a qualified path is E0576 (a bare wrong name keeps the E0223 header, as the traps section shows).
Related guides on this site
- E0091 Unused Type Parameter Fix
- E0118 Inherent Impl on Non-Nominal Type Fix
- E0109 Generic Argument on Non-Generic Type Fix
- E0184 Copy on Type With Drop Fix
Sources
- Rust error codes index, E0223 - an attempt was made to retrieve an associated type, but the type was ambiguous; the erroneous example naming
Trait::Xwith no implementing type; the working version using<Struct as Trait>::X; the note that the associated type is only made concrete in implementations, and thatStruct::Xcannot simply be used. - The Rust Reference, Traits - a trait's interface consists of associated items (functions, types, and constants); associated types must never define the type - the type may only be specified in an implementation.
- The Rust Reference, Paths - fully qualified paths allow for disambiguating the path for trait implementations and for specifying canonical paths, with the
<S as T1>::f()/<S as T2>::f()example form.
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.