E0271 Type Mismatch Resolving Fix

Written November 27, 2026 · Tested with Rust 1.99.1 · 21 min read

By the end of this guide
  • The error: an implementation whose associated type disagrees with the bound
  • First fix: change the associated type in the implementation
  • Second fix: change the type named in the bound
  • Third fix: pass a type whose associated type already matches

Written November 27, 2026

Tested with Rust 1.99.1

What this guide is

E0271 is the error for a type that implements the right trait with the wrong associated type. A bound can pin an associated type to an exact type — T<Item = String>, Iterator<Item = u32> — and that pin is an equality, not a suggestion. The type being passed does implement the trait, so there is no missing implementation to write. What fails is the equality: the implementation assigns one type to the associated type, the bound demands another, and the compiler stops at the call with E0271, type mismatch resolving <S as T>::Item == String.

Because both sides of the equality are written down somewhere in the program, the repairs are a choice about which side is wrong. Change the associated type in the implementation, when the implementation was written against an older or mistaken expectation. Change the type named in the bound, when the bound is stricter than the function actually needs. Or leave both declarations alone and change what reaches the call: pass a wrapper whose associated type matches, convert the values an iterator yields, or build a generic wrapper from a value of the type the bound wants. The sections below take the shapes in order: the plain call-site mismatch, the two declaration-side repairs, the wrapper repair, the same mismatch with the bound in a where clause, the Iterator form — whose header is worded differently — with its bound and conversion repairs, a generic implementation that forwards its parameter into the associated type, and the neighboring errors E0277 and E0308, which look similar and are not this one.

The error: an implementation whose associated type disagrees with the bound

This program defines a trait with one associated type, implements it for S with Item = u32, and calls a function that requires Item = String:

Rust
trait T {
    type Item;
}

struct S;

impl T for S {
    type Item = u32;
}

fn needs<X: T<Item = String>>(_t: X) {}

fn main() {
    needs(S);
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
error[E0271]: type mismatch resolving `<S as T>::Item == String`
  --> main.rs:14:11
   |
14 |     needs(S);
   |     ----- ^ type mismatch resolving `<S as T>::Item == String`
   |     |
   |     required by a bound introduced by this call
   |
note: expected this to be `String`
  --> main.rs:8:17
   |
 8 |     type Item = u32;
   |                 ^^^
note: required by a bound in `needs`
  --> main.rs:11:15
   |
11 | fn needs<X: T<Item = String>>(_t: X) {}
   |               ^^^^^^^^^^^^^ required by this bound in `needs`

error: aborting due to 1 previous error

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

The diagnostic names all three parties, and reading it in order settles which repair applies. The header states the equality that failed, in the compiler's projection spelling: <S as T>::Item == String — the associated type Item, as implemented by S for T, was required to equal String. The first note, "expected this to be String", points into the implementation, at the line type Item = u32; — that assignment is the received side of the equality. The second note, "required by a bound in needs", points at the function's bound, the side that set the expectation. Nothing is underlined in the trait definition itself: the trait only declares that an Item exists, and both the implementation and the bound are legal statements about it. They simply disagree, and the call is where the disagreement is discovered.

First fix: change the associated type in the implementation

If S is supposed to produce text — the bound states the design, and the implementation is the side that drifted — the repair is one line in the implementation:

Rust
trait T {
    type Item;
}

struct S;

impl T for S {
    type Item = String;
}

fn needs<X: T<Item = String>>(_t: X) {}

fn main() {
    needs(S);
    println!("needs accepted S");
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
needs accepted S

The program prints needs accepted S and exits with status 0. This is the repair to reach for when the implementation is yours and the bound comes from code you do not control — a library function, a trait in another crate that your type must fit. Its cost is that the associated type is part of the implementation's contract: every other use of S as a T sees the new Item, so changing it is a design change for the type, not a local patch at the call site. Where the implementation's method bodies compute the associated type, they change with it.

Second fix: change the type named in the bound

If the implementation states the design and the bound was written wider than the function needs — copied from another function, or written before the implementation settled — the repair is on the function's side:

Rust
trait T {
    type Item;
}

struct S;

impl T for S {
    type Item = u32;
}

fn needs<X: T<Item = u32>>(_t: X) {}

fn main() {
    needs(S);
    println!("needs accepted S");
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
needs accepted S

The program prints needs accepted S and exits with status 0. A bound is a promise the function makes to its callers about what it accepts, and narrowing or correcting the pinned type widens what the function can be called with. The check before taking this repair is the function body: if the body genuinely works with String values — formats them, concatenates them, returns them as text — then the bound is the truth and this repair would only move the failure inside the body. If the body never uses the item as a String, the bound was the stale side. When the associated type is not actually needed at one exact type, the bound can also drop the pin entirely — X: T accepts any implementation — but that gives up the guarantee the pin existed to state, and the body then has to work for every Item.

Third fix: pass a type whose associated type already matches

Sometimes neither declaration is wrong: the bound is the design, the implementation is the design, and the call is passing the wrong representative of the data. The repair is at the call — pass a wrapper type whose implementation assigns the type the bound names:

Rust
trait T {
    type Item;
}

struct S;

impl T for S {
    type Item = u32;
}

struct AsText;

impl T for AsText {
    type Item = String;
}

fn needs<X: T<Item = String>>(_t: X) {}

fn main() {
    let _s = S;
    needs(AsText);
    println!("needs accepted AsText");
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
needs accepted AsText

The program prints needs accepted AsText and exits with status 0. In real code the wrapper is not an empty marker: it holds the original value and its implementation converts — formatting a number as text, parsing text into a number, decoding bytes — so the associated type it declares is the type its methods actually produce. The wrapper is also the only repair available when both declarations belong to someone else: you cannot edit a library's bound or a library type's implementation, but you can always introduce your own type that stands between them. That is the same move the orphan rule prescribes for missing implementations, applied here to a mismatched one.

The same mismatch with the bound in a where clause

Where the bound is written makes no difference to the error. This program is the erroneous example from the official page for E0271, with the bound in a where clause and the implementation on the standard library type i8:

Rust
trait Trait {
    type AssociatedType;
}

fn foo<T>(_t: T)
where
    T: Trait<AssociatedType = u32>,
{
    println!("in foo");
}

impl Trait for i8 {
    type AssociatedType = &'static str;
}

fn main() {
    foo(3_i8);
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
error[E0271]: type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
  --> main.rs:17:9
   |
17 |     foo(3_i8);
   |     --- ^^^^ type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
   |     |
   |     required by a bound introduced by this call
   |
note: expected this to be `u32`
  --> main.rs:13:27
   |
13 |     type AssociatedType = &'static str;
   |                           ^^^^^^^^^^^^
note: required by a bound in `foo`
  --> main.rs:7:14
   |
 5 | fn foo<T>(_t: T)
   |    --- required by a bound in this function
 6 | where
 7 |     T: Trait<AssociatedType = u32>,
   |              ^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to 1 previous error

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

Every part of the diagnostic is the same as the inline-bound form: the failed equality in the header, the implementation's assignment under "expected this to be", and the bound — now spread over the function's where clause — under "required by a bound in foo". Choosing between fn foo<T: Trait<AssociatedType = u32>> and the where spelling is a formatting decision; the equality being checked, and the repairs for it, are identical.

The Iterator form: the header names what the iterator yields

The most common E0271 in ordinary code involves the standard library's own associated type, Iterator::Item. A generic function pins the item type it consumes, and the iterator passed to it yields a different one:

Rust
fn first<I: Iterator<Item = String>>(mut iter: I) -> String {
    iter.next().unwrap_or_default()
}

fn main() {
    let nums = vec![1u32, 2, 3];
    println!("{}", first(nums.into_iter()));
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
error[E0271]: expected `IntoIter<u32>` to be an iterator that yields `String`, but it yields `u32`
 --> main.rs:7:26
  |
7 |     println!("{}", first(nums.into_iter()));
  |                    ----- ^^^^^^^^^^^^^^^^ expected `String`, found `u32`
  |                    |
  |                    required by a bound introduced by this call
  |
note: required by a bound in `first`
 --> main.rs:1:22
  |
1 | fn first<I: Iterator<Item = String>>(mut iter: I) -> String {
  |                      ^^^^^^^^^^^^^ required by this bound in `first`

error: aborting due to 1 previous error

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

The fault is the same equality — <IntoIter<u32> as Iterator>::Item is u32, and the bound requires String — but the header says it in iterator vocabulary instead of the projection spelling: "expected IntoIter<u32> to be an iterator that yields String, but it yields u32". There is also no "expected this to be" note pointing into an implementation, because the implementation is the standard library's: Vec's iterator assigns Item from the vector's element type, and the span under the call, "expected String, found u32", carries that half of the disagreement. Recognizing this header as E0271 matters because the wording mentions neither "type mismatch resolving" nor the associated type by name — the code in the first line is the reliable signal.

The two declaration-side repairs exist here too, in the forms this family allows. The implementation side cannot be edited — IntoIter belongs to the standard library — but the bound side can, when the function can honestly consume the item type the iterator yields:

Rust
fn first<I: Iterator<Item = u32>>(mut iter: I) -> u32 {
    iter.next().unwrap_or_default()
}

fn main() {
    let nums = vec![1u32, 2, 3];
    println!("{}", first(nums.into_iter()));
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
1

The program prints 1 and exits with status 0. And where the function's requirement is the real one — it needs text — the call-side repair is a conversion in the iterator chain, which changes what the iterator yields before the function ever sees it:

Rust
fn first<I: Iterator<Item = String>>(mut iter: I) -> String {
    iter.next().unwrap_or_default()
}

fn main() {
    let nums = vec![1u32, 2, 3];
    println!("{}", first(nums.into_iter().map(|n| n.to_string())));
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
1

The program prints 1 and exits with status 0. The map adapter produces a new iterator whose Item is String, so the equality the bound states now holds. This is the general shape of the conversion repair for iterators: .map() with a formatting, parsing, or casting closure brings the yielded type to the bound, and it is priced per element — the conversion runs for every item the function actually pulls, and for a function like first, which pulls one, the rest of the chain is never converted at all.

A generic implementation: the associated type is forwarded from a parameter

An implementation does not have to name a concrete type in its associated type assignment. A generic implementation can forward its own parameter, and then the equality is decided by the value the caller constructs:

Rust
trait T {
    type Item;
}

struct Wrapper<U>(U);

impl<U> T for Wrapper<U> {
    type Item = U;
}

fn needs<X: T<Item = String>>(_t: X) {}

fn main() {
    needs(Wrapper(42u32));
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
error[E0271]: type mismatch resolving `<Wrapper<u32> as T>::Item == String`
  --> main.rs:14:11
   |
14 |     needs(Wrapper(42u32));
   |     ----- ^^^^^^^^^^^^^^ type mismatch resolving `<Wrapper<u32> as T>::Item == String`
   |     |
   |     required by a bound introduced by this call
   |
note: expected this to be `String`
  --> main.rs:8:17
   |
 8 |     type Item = U;
   |                 ^
note: required by a bound in `needs`
  --> main.rs:11:15
   |
11 | fn needs<X: T<Item = String>>(_t: X) {}
   |               ^^^^^^^^^^^^^ required by this bound in `needs`

error: aborting due to 1 previous error

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

Read the implementation's side carefully here: the "expected this to be String" note points at type Item = U;, and U is not a mistake in the implementation — it is the mechanism by which the wrapper adopts the type of whatever it wraps. <Wrapper<u32> as T>::Item resolves through that assignment to u32, and u32 is what fails the equality. The repair is therefore at the construction, not in either declaration: build the wrapper from a value of the type the bound names:

Rust
trait T {
    type Item;
}

struct Wrapper<U>(U);

impl<U> T for Wrapper<U> {
    type Item = U;
}

fn needs<X: T<Item = String>>(_t: X) {}

fn main() {
    needs(Wrapper("hi".to_string()));
    println!("needs accepted the wrapper");
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
needs accepted the wrapper

The program prints needs accepted the wrapper and exits with status 0. Forwarding implementations are everywhere in adapter code — wrappers, decorators, and iterator adapters all set their associated types from their parameters or from the types they wrap — so when an E0271 note points at an assignment that names a parameter rather than a concrete type, follow the resolution one step further: the type that failed the equality is the type argument the value was constructed with, and that construction is the line to change, by converting the wrapped value first if its type is fixed by the data.

Neighboring error: no implementation at all is E0277

E0271 requires an implementation that exists and assigns the wrong type. When the type does not implement the trait in the first place, the code is different. This function requires Display, and the struct passed to it implements nothing:

Rust
struct S;

fn show<X: std::fmt::Display>(x: X) {
    println!("{}", x);
}

fn main() {
    show(S);
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
error[E0277]: `S` doesn't implement `std::fmt::Display`
 --> main.rs:8:10
  |
8 |     show(S);
  |     ---- ^ unsatisfied trait bound
  |     |
  |     required by a bound introduced by this call
  |
help: the trait `std::fmt::Display` is not implemented for `S`
 --> main.rs:1:1
  |
1 | struct S;
  | ^^^^^^^^
note: required by a bound in `show`
 --> main.rs:3:12
  |
3 | fn show<X: std::fmt::Display>(x: X) {
  |            ^^^^^^^^^^^^^^^^^ required by this bound in `show`

error: aborting due to 1 previous error

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

That is E0277, the trait bound is not satisfied: the label says "unsatisfied trait bound" rather than naming an equality, and the help says the trait "is not implemented" for the type. The split is exact. An associated type pin, T<Item = String>, is a compound requirement — implement T, and implement it with this Item — and the compiler reports the two halves under two codes: no implementation at all is E0277, an implementation whose Item disagrees is E0271. The repairs differ accordingly: E0277 is repaired by writing the missing implementation, and no edit to a bound or an associated type creates one.

Two common iterator and conversion failures land on the E0277 side of this split, and both are worth recognizing before reaching for this guide's repairs. Collecting an iterator into a container of a different element type — let v: Vec<String> = vec![1u32, 2].into_iter().collect(); — reports E0277, "a value of type Vec<String> cannot be built from an iterator over elements of type u32", because the failing requirement is the FromIterator<u32> implementation for Vec<String>, which does not exist; the bound in collect names no associated type of the passed value. Converting a value with .into() where no conversion exists — let s: String = 42u32.into(); — is likewise E0277, "the trait bound String: From<u32> is not satisfied". An item type is involved in both programs, but the requirement that failed is an implementation's existence, not an equality — and the repair is the conversion or the container type, reached through the E0277 reading of the diagnostic.

Neighboring error: a plain value of the wrong type is E0308

When no trait and no associated type are involved at all — a value simply is not the type its position requires — the code is E0308:

Rust
fn main() {
    let x: u32 = "hi";
    println!("{}", x);
}
Terminal
$ rustc --edition 2021 main.rs -o main.bin
error[E0308]: mismatched types
 --> main.rs:2:18
  |
2 |     let x: u32 = "hi";
  |            ---   ^^^^ expected `u32`, found `&str`
  |            |
  |            expected due to this

error: aborting due to 1 previous error

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

The header is "mismatched types" with no projection and no trait name, the two types are stated directly — expected u32, found &str — and no note points at a bound or an implementation, because neither exists in this program. The confusion to avoid runs in one direction: an E0271 header contains the words "type mismatch", but its fault is never the underlined value alone. If the diagnostic names an associated type, a projection <S as T>::Item, or what an iterator yields, the disagreement is between a bound and an implementation, and converting the argument the way an E0308 repair would is only one of the options — the bound and the implementation are the other two, and they are usually the honest sides to change.

The exact rule: a bound's associated type binding is an equality the implementation must meet

The official page for E0271 defines the fault in one sentence: a type mismatched an associated type of a trait. Its erroneous example is the where-clause program above — a function that can only be used with a type implementing the trait with its associated type assigned to u32, called with an i8 whose implementation assigns &'static str — and its two fixes are the two declaration-side repairs in this guide: change the associated type in the function's bound, or change it in the trait implementation for the type. The page carries no note retiring or replacing this code; E0271 is the current code for this fault.

The Reference's page on associated items states the mechanism the equality runs on. An associated type declaration in a trait declares the signature; an associated type definition in an implementation assigns the concrete type, written type Assoc = Type;; and if a type Item has an associated type Assoc from a trait Trait, then <Item as Trait>::Assoc is an alias of the type specified in the associated type definition. That alias is what a bound's binding is checked against: T<Item = String> requires the alias <T as Trait>::Item to resolve to exactly String, the implementation's assignment is what it resolves to, and any difference between the two is E0271. A forwarding assignment, type Item = U;, makes the alias resolve to whatever the implementation's parameter is bound to at the use, which is why the generic-wrapper form of this error is decided at the construction site.

The fixes, ranked

  • First, change the associated type in the implementation, when the implementation is yours and the bound states the design — above all when the bound belongs to library code you cannot edit. One line, type Item = String;, makes every call site that requires that type pass at once.
  • Second, change the type named in the bound, when the bound is yours and was written stricter than the function body needs. Check the body first: if it uses the item at the pinned type, the bound is the truth and this repair only moves the error.
  • Third, convert at the call, when neither declaration should move: a .map() in an iterator chain that brings the yielded type to the bound, a wrapper type whose implementation assigns the required type, or a different construction of a generic wrapper so its forwarded associated type resolves to the required type.
  • Fourth, drop the pin from the bound — X: T in place of X: T<Item = String> — only when the function genuinely works for every associated type. This accepts the most callers and guarantees the least; it is a design change to the function's contract, not a repair of the disagreement.

Which fix for which cause

  • Implementation assigns one type, a call-site bound pins another, implementation is yours and the bound is the design: E0271, header "type mismatch resolving <S as T>::Item == String", note "expected this to be" pointing at the implementation's assignment. Change the associated type in the implementation.
  • Same disagreement, bound is yours and the body does not use the item at the pinned type: E0271 with the same notes. Change the type named in the bound.
  • The bound is written in a where clause instead of inline: the same E0271, the same three-part diagnostic. The repairs are unchanged; the spelling of the bound is not a cause.
  • A generic function pins Iterator<Item = String> and the passed iterator yields another type: E0271, header "expected IntoIter<u32> to be an iterator that yields String, but it yields u32". Change the bound if the function can consume the yielded type; otherwise convert in the chain with .map().
  • An implementation forwards its parameter, type Item = U;, and the note points at that assignment: E0271 decided by the construction. Build the wrapper from a value of the required type, converting the wrapped value first if needed.
  • Both declarations belong to other crates: E0271 with no side yours to edit. Introduce a wrapper type of your own whose implementation assigns the required associated type, and pass that.
  • The type does not implement the trait at all: E0277, "the trait bound … is not satisfied", help naming the missing implementation. Write the implementation; no associated type edit substitutes for it.
  • Collecting an iterator into a container of a different element type, or a .into() conversion that does not exist: E0277, even though an item type is involved — the failed requirement is a FromIterator or From implementation, not an associated type equality. Fix the container type, the conversion, or convert the items first.
  • A value is simply not the type its position requires, with no trait involved: E0308, "mismatched types", expected and found stated directly. Convert the value or correct the annotation.

Checklist

  • Read the header first. "Type mismatch resolving" with a projection, or a sentence about what an iterator yields, is E0271; "the trait bound … is not satisfied" is E0277; "mismatched types" with two plain types is E0308. The repairs for the three do not substitute for each other.
  • Find both sides of the equality before editing. The "expected this to be" note points at the implementation's assignment; the "required by a bound in" note points at the bound. One of those two lines, or the call between them, is the repair site.
  • Decide which side owns the truth. The bound is the design when the function's body uses the item at the pinned type or the bound is library code; the implementation is the design when the bound was copied or written before the implementation settled.
  • Check whether the implementation's assignment names a parameter. If it does, the failing type is the type argument at the construction, and the construction — not the implementation — is where the fix lands.
  • For iterators, remember the implementation is the standard library's and cannot be edited. The choice is the bound or a conversion in the chain, and a .map() conversion is paid only for the elements actually pulled.
  • Do not answer E0271 by writing a new implementation. The type already implements the trait; a second implementation is a conflicting implementation, a different error. And do not answer E0277 by editing an associated type — there is no implementation for the edit to land in.

Sources

  • Rust Compiler Error Index, E0271 — for a type mismatching an associated type of a trait, for the erroneous example of a where-clause bound requiring AssociatedType = u32 called with an implementation assigning &'static str, and for resolving the issue by changing the associated type in the function's bound or in the trait implementation.
  • The Rust Reference, Associated items — for associated type declarations declaring the signature and associated type definitions in implementations assigning the concrete type, and for <Item as Trait>::Assoc being an alias of the type specified in the associated type definition.
  • Rust Compiler Error Index, E0277 — for using a type that does not implement a trait in a place that expected that trait, and for fixing it by implementing the trait for the type.
  • Rust Compiler Error Index, E0308 — for the expected type not matching the received type, and for the error occurring when an expression is used where an expression of a different type was expected, most commonly an argument of a different type than the declaration.

Keep Exploring