Rust: error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == i32`
A trait's associated type (Iterator::Item, Future::Output) doesn't match what's expected.
error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == i32`expected `Iterator<Item = i32>`, found `Iterator<Item = &i32>`error[E0271]: expected `{closure}` to be a closure that returnstype mismatch resolvingE0271 expected associated type Meaning
Check what your iterator/future actually yields (&i32 vs i32, Result<T,E> vs T). Use .copied()/.cloned()/.map(|x| *x), ? on results, or adjust the bound Iterator<Item = &i32>. The message shows expected vs found.
Common causes
- Iterator yields references but code expects values
Resultinside a stream/iterator not handled- Future Output mismatch (
impl Future<Output = T>) - Closure returning another type than the bound
collectinto incompatible type
⚡ Quick fix
- Add
.copied()/.cloned()or dereference - Handle
Resultitems with?/collect::<Result<Vec<_>,_>>() - Adjust the trait bound's associated type
Detailed fix by platform
Rust
let v: Vec<i32> = items.iter().copied().collect();
How to diagnose
- Item — Yielded type?
- Expected — Bound type?
- Adapter — copied/cloned?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Blocking waiting for file lock on package cache / build directory Cargo: Blocking waiting for file lock on package cache / on build directory
- call of overloaded is ambiguous C++: error: call of overloaded 'f(int)' is ambiguous
- cannot use x as type in assignment/argument Go: cannot use "5" (untyped string constant) as int value in argument to f
Most viewed in Rust
- E0382 Rust: error[E0382]: borrow of moved value: `x`
- E0502 Rust: error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
- feature edition2024 is required / Cargo.lock version too new Cargo: error: failed to parse manifest — feature `edition2024` is required / lock file version 4 requires `-Znext-lockfile-bump`
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026