Rust

E0283 Type Annotations Needed Fix

E0283 is the ambiguity error: the compiler can see several types that would each satisfy the program, and it will not choose among them for you. A collect that could build a Vec or a String, an into that could land in several numeric types, a sum that could total in any integer type - each stops with E0283 until one annotation names the intended type. This guide separates the eleven shapes that produce it, matches each one to the annotation or turbofish that resolves it, and draws the line against E0282, where no type can be inferred at all.

Written November 25, 2026 · Tested with Rust 1.99.1 · 35 min read

By the end of this guide
  • The rule underneath: a generic result needs one deciding fact
  • How to read the diagnostic
  • The first failure: collecting reversed characters
  • The second failure: collecting a range

Written November 25, 2026

Tested with Rust 1.99.1

What this guide is

Error E0283 is a type annotation request caused by ambiguity. The error codes index puts it in one sentence: type inference did not result in one unique possible type, and extra information is required. The compiler is not saying it knows nothing about the type - it is saying it knows several complete answers and has no rule for preferring one. Its example is a collect over reversed characters: for a char iterator, Vec<char> and String are both suitable candidates, because both implement FromIterator<char>.

That is the boundary with the neighbor this guide is most often confused with. E0282 carries the same short message - "type annotations needed" - but it is the no-candidate case: a Vec::new() whose element type nothing in the program ever constrains, or a bare None. E0283 is the several-candidates case: a generic return type - collect, into, sum, try_into, a generic function of your own - where more than one type satisfies every constraint the program states. Both are repaired by supplying the missing type, but reading which code you got tells you what the compiler is stuck on: too many answers, or none. The traps at the end print both codes side by side, along with the unannotated parse shape, which on current Rust is neither - it is E0284.

The forms in this guide each reproduce E0283 with a small, complete program, and the source of the ambiguity differs each time: the collection type, the conversion target, the total type, the element collection for pairs, the target of a fallible conversion, the type parameter of a generic function. The repairs fall into two groups. Annotate the binding - let x: Vec<char> = ... - and inference works backward from the stated type. Or name the type parameter at the call itself, with the turbofish - collect::<Vec<char>>(), read::<i32>(...) - which is the only route when there is no binding to annotate, or when the ambiguity sits inside an expression.

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: a generic result needs one deciding fact

Every method and function behind these failures is generic over its result. collect is declared fn collect<B>(self) -> B where B: FromIterator<Self::Item> - the caller, not the iterator, chooses B, and any type implementing FromIterator for the item type is a legal choice. sum and product have the same shape over the Sum and Product traits. Into is fn into(self) -> T with T chosen by the caller, and implementing From for a type automatically provides the matching Into, so one source value usually has many legal targets. A generic function of your own, like the read and pick families below, puts its type parameter in the same position: decided by the caller, or not decided at all.

Inference resolves such a parameter from whatever the surrounding program states: a binding annotation, an argument it is passed to, a field type, a comparison against a concrete value. When one of those facts is present and pins a single type, the program compiles - the neighbors below are exactly the families with one such fact added. When the stated facts leave two or more types standing, the compiler stops with E0283 rather than guessing, because each candidate would give the program a different meaning: a reversed string held as text is not the same value as the same characters held as a vector.

That is also why a partial annotation is often enough. The index page makes the point with the first family: Vec<_> resolves the ambiguity, because once the collection is known to be a Vec, the element type is the iterator's item type and nothing is left open. The annotation has to decide the open parameter, not spell out the whole type.

How to read the diagnostic

Every failure in the eleven families prints the same header - the code and the words "type annotations needed" - and then the notes name the open trait and, in several families, the candidates. Ten of them underline the binding and the call with "type must be known at this point"; the eleventh, the generic-function family at the end of this guide, underlines the call alone and adds its own line naming the type parameter. The first family's, in full:

Terminal
$ rustc --edition 2021 fail_collect_chars.rs -o fail_collect_chars
error[E0283]: type annotations needed
    --> fail_collect_chars.rs:2:9
     |
   2 |     let x = "hello".chars().rev().collect();
     |         ^                         ------- type must be known at this point
     |
     = note: multiple `impl`s satisfying `_: FromIterator<char>` found in the `alloc` crate:
             - impl FromIterator<char> for Box<str>;
             - impl FromIterator<char> for ByteString;
             - impl FromIterator<char> for String;
note: required by a bound in `collect`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2073:19
     |
2073 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
help: consider giving `x` an explicit type
     |
   2 |     let x: Vec<_> = "hello".chars().rev().collect();
     |          ++++++++

error: aborting due to 1 previous error

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

Read it in order. The header never names the missing type - it cannot, because there is more than one. The note is where the information is. Here it lists the FromIterator<char> implementations the compiler found in the alloc crate - Box<str>, ByteString, and String are named, and a Vec satisfies the same bound - which is the ambiguity stated concretely: pick one of the candidates you can name in your own code, such as Vec, String, or Box<str>, and the error is gone. In other families the note takes different forms, and the form is a clue to the shape of the problem. A note saying "the type must implement From<u8>", as in the third family, names the trait with the target left open. A note saying "multiple impls satisfying" and pointing at two impl blocks in your own code, as in the eighth family, means the program itself created the candidates. The help at the end is uniform across the probed families: "consider giving the binding an explicit type" - or, where the open parameter belongs to a function, "consider specifying a concrete type for the type parameter", as the eleventh family shows. The notes and helps vary by shape; the reading above is scoped to the forms printed in this guide.

The first failure: collecting reversed characters

The example from the error codes index - a reversed character iterator collected with no target type:

Rust
fn main() {
    let x = "hello".chars().rev().collect();
    println!("{:?}", x);
}
Terminal
$ rustc --edition 2021 fail_collect_chars.rs -o fail_collect_chars
error[E0283]: type annotations needed
    --> fail_collect_chars.rs:2:9
     |
   2 |     let x = "hello".chars().rev().collect();
     |         ^                         ------- type must be known at this point
     |
     = note: multiple `impl`s satisfying `_: FromIterator<char>` found in the `alloc` crate:
             - impl FromIterator<char> for Box<str>;
             - impl FromIterator<char> for ByteString;
             - impl FromIterator<char> for String;
note: required by a bound in `collect`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2073:19
     |
2073 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
help: consider giving `x` an explicit type
     |
   2 |     let x: Vec<_> = "hello".chars().rev().collect();
     |          ++++++++

error: aborting due to 1 previous error

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

The iterator yields char values, and collect can build any type that implements FromIterator<char> - the diagnostic names Box<str>, ByteString, and String, and Vec<char> qualifies as well. Nothing in the program prefers one, and printing with {:?} does not help, because every candidate implements Debug. The fix annotates the binding with the intended collection:

Rust
fn main() {
    let x: Vec<char> = "hello".chars().rev().collect();
    println!("{:?}", x);
}
Terminal
$ rustc --edition 2021 fix_collect_chars.rs -o fix_collect_chars
$ ./fix_collect_chars
['o', 'l', 'l', 'e', 'h']

The output is ['o', 'l', 'l', 'e', 'h']: the characters of hello reversed, held as a vector. The same program annotated as a String instead compiles too and prints olleh - that shape is in the neighbors below, because choosing between them is the program's decision, not an error in either direction. The index page's partial form, Vec<_>, also resolves this family, because the element type follows from the iterator once the collection type is named.

The second failure: collecting a range

A range collected with no collection type at all:

Rust
fn main() {
    let v = (0..3).collect();
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 fail_collect_type.rs -o fail_collect_type
error[E0283]: type annotations needed
    --> fail_collect_type.rs:2:9
     |
   2 |     let v = (0..3).collect();
     |         ^          ------- type must be known at this point
     |
     = note: the type must implement `FromIterator<i32>`
note: required by a bound in `collect`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2073:19
     |
2073 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
help: consider giving `v` an explicit type
     |
   2 |     let v: Vec<_> = (0..3).collect();
     |          ++++++++

error: aborting due to 1 previous error

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

The note here is shorter - "the type must implement FromIterator<i32>" - without a candidate list, but the situation is the same: a Vec, a HashSet, a VecDeque, and every other FromIterator<i32> type satisfies the program as written. The fix names the collection:

Rust
fn main() {
    let v: Vec<i32> = (0..3).collect();
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 fix_collect_type.rs -o fix_collect_type
$ ./fix_collect_type
[0, 1, 2]

The output is [0, 1, 2]. The element type is stated in the annotation for clarity; Vec<_> would resolve this family too, since the range fixes the element type at i32. Contrast the trap at the end where the same collect is used only through len(): there the compiler reports E0282 instead, because len is a method many unrelated types share and the diagnostic takes the no-unique-candidate path - the code differs even though the repair is the same annotation.

The third failure: an unannotated into

A conversion whose target type nothing states:

Rust
fn main() {
    let x = 5u8;
    let y = x.into();
    println!("{}", y);
}
Terminal
$ rustc --edition 2021 fail_into_u8.rs -o fail_into_u8
error[E0283]: type annotations needed
 --> fail_into_u8.rs:3:9
  |
3 |     let y = x.into();
  |         ^     ---- type must be known at this point
  |
  = note: the type must implement `From<u8>`
  = note: required for `u8` to implement `Into<_>`
help: consider giving `y` an explicit type
  |
3 |     let y: /* Type */ = x.into();
  |          ++++++++++++

error: aborting due to 1 previous error

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

A u8 converts, through From implementations that automatically provide Into, into every wider integer type and more. The note - "the type must implement From<u8>" - states the open end: the source is fixed, the target is the generic parameter, and printing the result does not narrow it because every candidate implements Display. The fix annotates the target:

Rust
fn main() {
    let x = 5u8;
    let y: u32 = x.into();
    println!("{}", y);
}
Terminal
$ rustc --edition 2021 fix_into_u8.rs -o fix_into_u8
$ ./fix_into_u8
5

The output is 5. The conversion itself was never in doubt - only its destination was. Where the value flows onward into a position with a known type - a function argument, a struct field, a return - that position does the same job as the annotation, which is why into failures tend to appear exactly at let bindings whose values are only printed or returned generically.

The fourth failure: an unannotated sum

An iterator total with no stated type:

Rust
fn main() {
    let s = (1..=3).sum();
    println!("{}", s);
}
Terminal
$ rustc --edition 2021 fail_sum.rs -o fail_sum
error[E0283]: type annotations needed
    --> fail_sum.rs:2:9
     |
   2 |     let s = (1..=3).sum();
     |         ^           --- type must be known at this point
     |
     = note: the type must implement `Sum<i32>`
help: the trait `Sum` is implemented for `i32`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/accum.rs:50:9
     |
  50 |         impl Sum for $a {
     |         ^^^^^^^^^^^^^^^
...
 206 | integer_sum_product! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
     | ---------------------------------------------------------------------------- in this macro invocation
note: required by a bound in `std::iter::Iterator::sum`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:3668:12
     |
3665 |     fn sum<S>(self) -> S
     |        --- required by a bound in this associated function
...
3668 |         S: [const] Sum<Self::Item>,
     |            ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
     = note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider giving `s` an explicit type, where the type for type parameter `S` is specified
     |
   2 |     let s: i32 = (1..=3).sum();
     |          +++++

error: aborting due to 1 previous error

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

sum is generic over the total's type, bounded by the Sum trait, and the diagnostic's help names one implementation directly: "the trait Sum is implemented for i32". Every integer type implements Sum<i32> for this iterator, so the candidates are the integer types themselves. The fix states the total type:

Rust
fn main() {
    let s: i32 = (1..=3).sum();
    println!("{}", s);
}
Terminal
$ rustc --edition 2021 fix_sum.rs -o fix_sum
$ ./fix_sum
6

The output is 6. The annotation is doing real work here beyond satisfying the compiler: the choice of total type decides overflow behavior and precision, which is the practical reason the compiler refuses to pick one - a total accumulated in i32 and the same total accumulated in i64 are different programs once the values grow.

The fifth failure: an unannotated product

The multiplicative counterpart of the sum:

Rust
fn main() {
    let p = (1..=3).product();
    println!("{}", p);
}
Terminal
$ rustc --edition 2021 fail_product.rs -o fail_product
error[E0283]: type annotations needed
    --> fail_product.rs:2:9
     |
   2 |     let p = (1..=3).product();
     |         ^           ------- type must be known at this point
     |
     = note: the type must implement `Product<i32>`
help: the trait `Product` is implemented for `i32`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/accum.rs:61:9
     |
  61 |         impl Product for $a {
     |         ^^^^^^^^^^^^^^^^^^^
...
 206 | integer_sum_product! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
     | ---------------------------------------------------------------------------- in this macro invocation
note: required by a bound in `std::iter::Iterator::product`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:3700:12
     |
3697 |     fn product<P>(self) -> P
     |        ------- required by a bound in this associated function
...
3700 |         P: [const] Product<Self::Item>,
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::product`
     = note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider giving `p` an explicit type, where the type for type parameter `P` is specified
     |
   2 |     let p: i32 = (1..=3).product();
     |          +++++

error: aborting due to 1 previous error

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

product is generic in the same way, over the Product trait, and the diagnostic mirrors the sum's, down to naming i32 in its help. The fix is the same annotation:

Rust
fn main() {
    let p: i32 = (1..=3).product();
    println!("{}", p);
}
Terminal
$ rustc --edition 2021 fix_product.rs -o fix_product
$ ./fix_product
6

The output is 6 - 1 times 2 times 3. The pair of families is worth seeing together because they show the pattern is in the method's declaration, not the arithmetic: any method generic over its result type with several trait implementations produces this error when the result is left open, whatever the method computes.

The sixth failure: a generic parse function

A generic helper over FromStr, called with nothing to pin its type parameter:

Rust
use std::str::FromStr;
fn read<T: FromStr>(s: &str) -> T where T::Err: std::fmt::Debug { s.parse().unwrap() }
fn main() {
    let v = read("42");
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 fail_generic_fromstr.rs -o fail_generic_fromstr
error[E0283]: type annotations needed
 --> fail_generic_fromstr.rs:4:9
  |
4 |     let v = read("42");
  |         ^   ---------- type must be known at this point
  |
  = note: the type must implement `FromStr`
  = help: the following types implement trait `FromStr`:
            ByteString
            CString
            IpAddr
            Ipv4Addr
            Ipv6Addr
            NonZero<i128>
            NonZero<i16>
            NonZero<i32>
          and 32 others
  = note: cannot satisfy `<_ as FromStr>::Err == _`
note: required by a bound in `read`
 --> fail_generic_fromstr.rs:2:12
  |
2 | fn read<T: FromStr>(s: &str) -> T where T::Err: std::fmt::Debug { s.parse().unwrap() }
  |            ^^^^^^^ required by this bound in `read`
help: consider giving `v` an explicit type
  |
4 |     let v: /* Type */ = read("42");
  |          ++++++++++++

error: aborting due to 1 previous error

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

The helper's T appears only in its return type, so the call site is the only place it can be decided. The diagnostic lists types that implement FromStr - ByteString, CString, the address types, the NonZero types, "and 32 others" - which is the candidate set stated as a trait roster. There is no binding annotation that names T directly here, because annotating v would also work, but the direct repair names the parameter at the call, with the turbofish:

Rust
use std::str::FromStr;
fn read<T: FromStr>(s: &str) -> T where T::Err: std::fmt::Debug { s.parse().unwrap() }
fn main() {
    let v = read::<i32>("42");
    println!("{:?}", v);
}
Terminal
$ rustc --edition 2021 fix_generic_fromstr.rs -o fix_generic_fromstr
$ ./fix_generic_fromstr
42

The output is 42. Note what did not happen inside the helper: its own s.parse() compiled without annotation, because there T is already the function's parameter and the parse target is that parameter, not an open choice. The ambiguity exists only where the parameter is still unbound - at the call.

The seventh failure: a try_into with no target

A fallible conversion out of a vector, with the destination unstated:

Rust
fn main() {
    let v = vec![1, 2];
    let a = v.try_into().unwrap();
    println!("{:?}", a);
}
Terminal
$ rustc --edition 2021 fail_try_into.rs -o fail_try_into
error[E0283]: type annotations needed
 --> fail_try_into.rs:3:9
  |
3 |     let a = v.try_into().unwrap();
  |         ^     -------- type must be known at this point
  |
  = note: multiple `impl`s satisfying `_: TryFrom<Vec<i32>>` found in the following crates: `alloc`, `core`:
          - impl<T, A, N> TryFrom<Vec<T, A>> for [T; N]
            where the constant `N` has type `usize`, T: Destruct, A: Allocator, A: Destruct;
          - impl<T, N> TryFrom<Vec<T>> for Box<[T; N]>
            where the constant `N` has type `usize`;
          - impl<T, U> TryFrom<U> for T
            where U: Into<T>;
  = note: cannot satisfy `<_ as TryFrom<Vec<i32>>>::Error == _`
  = note: required for `Vec<i32>` to implement `TryInto<_>`
help: consider giving `a` an explicit type
  |
3 |     let a: /* Type */ = v.try_into().unwrap();
  |          ++++++++++++

error: aborting due to 1 previous error

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

The note lists the TryFrom<Vec<i32>> implementations it found - an array [T; N], a boxed array Box<[T; N]>, and the blanket implementation through Into - and adds that it cannot satisfy the conversion's Error type either, since the error type follows from the target that was never chosen. unwrap does not narrow anything: every candidate's error type implements Debug. The fix annotates the array type, length included:

Rust
fn main() {
    let v = vec![1, 2];
    let a: [i32; 2] = v.try_into().unwrap();
    println!("{:?}", a);
}
Terminal
$ rustc --edition 2021 fix_try_into.rs -o fix_try_into
$ ./fix_try_into
[1, 2]

The output is [1, 2]. The length in the annotation is load-bearing in a way the earlier families' annotations were not: the target [i32; 2] is also the success condition of the conversion, since a vector of any other length fails the try_into at run time instead.

The eighth failure: a type with two Into implementations

The ambiguity created by the program itself - a type with two Into implementations, converted with no annotation. This is the shape of the second example on the error codes index page, extended with a second implementation so both candidates are real:

Rust
struct Foo;
impl Into<u32> for Foo { fn into(self) -> u32 { 1 } }
impl Into<u64> for Foo { fn into(self) -> u64 { 2 } }
fn main() {
    let foo = Foo;
    let bar = foo.into();
    println!("{}", bar);
}
Terminal
$ rustc --edition 2021 fail_foo_into.rs -o fail_foo_into
error[E0283]: type annotations needed
 --> fail_foo_into.rs:6:9
  |
6 |     let bar = foo.into();
  |         ^^^       ---- type must be known at this point
  |
note: multiple `impl`s satisfying `Foo: Into<_>` found
 --> fail_foo_into.rs:2:1
  |
2 | impl Into<u32> for Foo { fn into(self) -> u32 { 1 } }
  | ^^^^^^^^^^^^^^^^^^^^^^
3 | impl Into<u64> for Foo { fn into(self) -> u64 { 2 } }
  | ^^^^^^^^^^^^^^^^^^^^^^
  = note: and another `impl` found in the `core` crate:
          - impl<T, U> Into<U> for T
            where U: From<T>;
help: consider giving `bar` an explicit type
  |
6 |     let bar: /* Type */ = foo.into();
  |            ++++++++++++

error: aborting due to 1 previous error

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

This diagnostic points into the program's own code: "multiple impls satisfying Foo: Into<_> found", with spans on both impl blocks and a note about the blanket Into implementation in core. When the candidate list is your own impls, the compiler is reporting a decision the program's design created. The fix states which conversion the binding wants:

Rust
struct Foo;
impl Into<u32> for Foo { fn into(self) -> u32 { 1 } }
impl Into<u64> for Foo { fn into(self) -> u64 { 2 } }
fn main() {
    let foo = Foo;
    let bar: u32 = foo.into();
    println!("{}", bar);
}
Terminal
$ rustc --edition 2021 fix_foo_into.rs -o fix_foo_into
$ ./fix_foo_into
1

The output is 1 - the u32 implementation's value, not the u64 implementation's 2. Had the intended target been u64, the annotation let bar: u64 would have printed 2 with no other change. The index page's own repair for its single-impl example is the fully qualified call, naming the trait's type parameter in the path; that form is in the alternatives below.

The ninth failure: collecting split text

Text split and collected, with the collection unstated:

Rust
fn main() {
    let parts = "a b c".split(' ').collect();
    println!("{:?}", parts);
}
Terminal
$ rustc --edition 2021 fail_split_collect.rs -o fail_split_collect
error[E0283]: type annotations needed
    --> fail_split_collect.rs:2:9
     |
   2 |     let parts = "a b c".split(' ').collect();
     |         ^^^^^                      ------- type must be known at this point
     |
     = note: the type must implement `FromIterator<&str>`
note: required by a bound in `collect`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2073:19
     |
2073 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
help: consider giving `parts` an explicit type
     |
   2 |     let parts: Vec<_> = "a b c".split(' ').collect();
     |              ++++++++

error: aborting due to 1 previous error

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

Splitting yields &str pieces, and the open choice is again the FromIterator<&str> target - a Vec of the pieces, a single rejoined String, and other collection types all satisfy the program. The fix names the vector:

Rust
fn main() {
    let parts: Vec<&str> = "a b c".split(' ').collect();
    println!("{:?}", parts);
}
Terminal
$ rustc --edition 2021 fix_split_collect.rs -o fix_split_collect
$ ./fix_split_collect
["a", "b", "c"]

The output is ["a", "b", "c"]. This family and the first are the same method failing on different iterators; what changes between them is the item type named in the note - FromIterator<char> there, FromIterator<&str> here - and reading that item type is the quickest way to confirm the error is about the collection and not the elements.

The tenth failure: collecting pairs

Key-value pairs collected with no target:

Rust
fn main() {
    let m = [(1, "a"), (2, "b")].into_iter().collect();
    println!("{:?}", m);
}
Terminal
$ rustc --edition 2021 fail_collect_tuples.rs -o fail_collect_tuples
error[E0283]: type annotations needed
    --> fail_collect_tuples.rs:2:9
     |
   2 |     let m = [(1, "a"), (2, "b")].into_iter().collect();
     |         ^                                    ------- type must be known at this point
     |
     = note: the type must implement `FromIterator<(i32, &str)>`
note: required by a bound in `collect`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2073:19
     |
2073 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
help: consider giving `m` an explicit type
     |
   2 |     let m: Vec<_> = [(1, "a"), (2, "b")].into_iter().collect();
     |          ++++++++

error: aborting due to 1 previous error

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

Pairs are the item type where the candidate set is most visible in ordinary code: the same iterator of (i32, &str) pairs collects into a HashMap, a BTreeMap, or a plain Vec of pairs, each a different data structure with different behavior. The fix names the map - and, because printing a map's debug form would order its entries by the map's internal order rather than the program's, the fixed program reads two deterministic facts back out of it:

Rust
fn main() {
    let m: std::collections::HashMap<i32, &str> = [(1, "a"), (2, "b")].into_iter().collect();
    println!("{} {}", m.len(), m.get(&2).unwrap());
}
Terminal
$ rustc --edition 2021 fix_collect_tuples.rs -o fix_collect_tuples
$ ./fix_collect_tuples
2 b

The output is 2 b: two entries, and the value stored under key 2 is b. Of all the families, this is the one where the annotation most plainly is the program's meaning: the compiler cannot choose between a lookup structure and a list, and it should not.

The eleventh failure: a generic function with no pinning argument

A generic function whose type parameter appears in no argument, called bare:

Rust
fn pick<T: Default + std::fmt::Debug>() { let v: T = Default::default(); println!("{:?}", v); }
fn main() { pick(); }
Terminal
$ rustc --edition 2021 fail_generic_pick.rs -o fail_generic_pick
error[E0283]: type annotations needed
 --> fail_generic_pick.rs:2:13
  |
2 | fn main() { pick(); }
  |             ^^^^ cannot infer type of the type parameter `T` declared on the function `pick`
  |
  = note: the type must implement `Default`
  = note: the type must also implement `Debug`
note: required by a bound in `pick`
 --> fail_generic_pick.rs:1:12
  |
1 | fn pick<T: Default + std::fmt::Debug>() { let v: T = Default::default(); println!("{:?}", v); }
  |            ^^^^^^^ required by this bound in `pick`
note: required by a bound in `pick`
 --> fail_generic_pick.rs:1:22
  |
1 | fn pick<T: Default + std::fmt::Debug>() { let v: T = Default::default(); println!("{:?}", v); }
  |                      ^^^^^^^^^^^^^^^ required by this bound in `pick`
help: consider specifying a concrete type for the type parameter `T`
  |
2 | fn main() { pick::</* Type */>(); }
  |                 ++++++++++++++

error: aborting due to 1 previous error

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

This diagnostic has a different header line from the other ten: "cannot infer type of the type parameter T declared on the function pick", with the span on the call itself. The notes name both bounds - the type must implement Default, and it must also implement Debug - and the help offers the turbofish directly: "consider specifying a concrete type for the type parameter T". That is the fix:

Rust
fn pick<T: Default + std::fmt::Debug>() { let v: T = Default::default(); println!("{:?}", v); }
fn main() { pick::<i32>(); }
Terminal
$ rustc --edition 2021 fix_generic_pick.rs -o fix_generic_pick
$ ./fix_generic_pick
0

The output is 0, the i32 default. A parameter that no argument mentions can only be decided at the call like this, or by annotating a binding that receives the function's result - pick returns nothing, so the turbofish is the only route in this family, which is why functions with return-only type parameters are the shape readers meet this error in most often outside the iterator methods.

Seven more shapes that fail the same way

The same header - "type annotations needed" with code E0283, exactly one error and no other code - for seven more programs. Each is repaired by the same moves as the families above: annotate the binding, or name the type parameter at the call:

A mapped range, collected with no target:

Rust
fn main() {
    let v = (0..3).map(|n| n * 2).collect();
    println!("{:?}", v);
}

A filtered range, collected with no target:

Rust
fn main() {
    let v = (0..10).filter(|n| n % 2 == 0).collect();
    println!("{:?}", v);
}

The bytes of a string, collected with no target:

Rust
fn main() {
    let v = "hi".bytes().collect();
    println!("{:?}", v);
}

A sum over float references - the fourth family with the item type changed, still open over the total type:

Rust
fn main() {
    let s = [1.0, 2.0].iter().sum();
    println!("{}", s);
}

A vector converted with into, where the source was itself built by from - the third family with a collection as the value:

Rust
fn main() {
    let v = Vec::from([1, 2]);
    let w = v.into();
    println!("{:?}", w);
}

A boxed string converted onward with into:

Rust
fn main() {
    let s = String::from("hi");
    let b = s.into_boxed_str();
    let c = b.into();
    println!("{}", c);
}

An enumerated character iterator, collected with no target:

Rust
fn main() {
    let v = "ab".chars().enumerate().collect();
    println!("{:?}", v);
}

When the annotation belongs on the call

Two repairs cover the cases where annotating a binding is not the natural place to decide the type.

Name the collection in the turbofish. collect takes its target as a type parameter, so the parameter can be given on the method call itself - the form the index page shows alongside the annotation:

Rust
fn main() {
    let x = "hello".chars().rev().collect::<Vec<char>>();
    println!("{:?}", x);
}
Terminal
$ rustc --edition 2021 alt_collect_turbofish.rs -o alt_collect_turbofish
$ ./alt_collect_turbofish
['o', 'l', 'l', 'e', 'h']

The output is ['o', 'l', 'l', 'e', 'h'], identical to the first family's annotation fix. The turbofish form is the one to reach for when the value is used inside a larger expression and there is no binding to annotate.

Name the conversion in the path. For an into whose target matters at one expression, the fully qualified call states the trait and its parameter directly:

Rust
fn main() {
    let x = 5u8;
    let y = <u8 as Into<u32>>::into(x);
    println!("{}", y);
}
Terminal
$ rustc --edition 2021 alt_into_qualified.rs -o alt_into_qualified
$ ./alt_into_qualified
5

The output is 5, as in the third family. This is the repair the index page gives for its Into example - Into::<u32>::into(foo) in its notation - and it resolves the ambiguity at the exact expression that has it, leaving the surrounding bindings unannotated.

The neighbors that compile

These programs use the same generic methods with no error, each because one fact in the program already decides the type.

Parsing with an annotated binding: parse is generic in the same way as the families - its target implements FromStr - and the annotation decides it:

Rust
fn main() {
    let n: i32 = "42".parse().unwrap();
    println!("{}", n);
}
Terminal
$ rustc --edition 2021 ok_parse_annotated.rs -o ok_parse_annotated
$ ./ok_parse_annotated
42

The output is 42. This is also the shape to contrast with the first trap: the same parse with the annotation removed is E0284, not E0283, on current Rust.

Collecting into a String: the first family with the other candidate chosen by annotation:

Rust
fn main() {
    let x: String = "hello".chars().rev().collect();
    println!("{}", x);
}
Terminal
$ rustc --edition 2021 ok_collect_string.rs -o ok_collect_string
$ ./ok_collect_string
olleh

The output is olleh - the reversed characters as text rather than as a vector of characters.

The partial annotation: Vec<_> decides the collection and leaves the element type to the iterator, exactly as the index page describes:

Rust
fn main() {
    let x: Vec<_> = "hello".chars().rev().collect();
    println!("{:?}", x);
}
Terminal
$ rustc --edition 2021 ok_collect_partial.rs -o ok_collect_partial
$ ./ok_collect_partial
['o', 'l', 'l', 'e', 'h']

The output is ['o', 'l', 'l', 'e', 'h'].

A range collected into Vec<_>: here even the element type is left open with _, and the program still compiles, because the range's own item type is i32 by the integer default and nothing competes with it:

Rust
fn main() {
    let x: Vec<_> = (0..10).collect();
    println!("{:?}", x);
}
Terminal
$ rustc --edition 2021 ok_collect_vec_elem.rs -o ok_collect_vec_elem
$ ./ok_collect_vec_elem
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

The output is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. The underscore is a request for inference, not an absence of it - it works precisely when the remaining facts leave exactly one type standing.

An into with the target annotated, the third family repaired in place:

Rust
fn main() {
    let x = 5u8;
    let y: u32 = x.into();
    println!("{}", y);
}
Terminal
$ rustc --edition 2021 ok_into_annotated.rs -o ok_into_annotated
$ ./ok_into_annotated
5

The output is 5.

A sum with the total type annotated, the fourth family repaired in place:

Rust
fn main() {
    let s: i32 = (1..=3).sum();
    println!("{}", s);
}
Terminal
$ rustc --edition 2021 ok_sum_annotated.rs -o ok_sum_annotated
$ ./ok_sum_annotated
6

The output is 6.

The fixes in reach order

  • The binding is the open end: annotate it - let x: Vec<char>, let y: u32, let s: i32. The first five, seventh, ninth, and tenth families are this repair, and it is the first thing to try.
  • A partial annotation may be all that is needed: Vec<_> decides the collection when the element type already follows from the iterator. The first and second families, and the partial-annotation neighbor.
  • There is no binding to annotate, or the ambiguity is inside an expression: name the type parameter at the call - collect::<Vec<char>>(), read::<i32>(...), pick::<i32>(). The sixth and eleventh families, and the alternatives.
  • The candidates are your own impls: the annotation states which impl the program means, and the choice changes the value, not just the type. The eighth family.
  • The target carries a run-time condition: annotate the full target, length included, as with the array in the seventh family.
  • The header is not E0283: an unannotated parse is E0284, a type nothing constrains is E0282, a wrong-type assignment is E0308, and a method call on an ambiguous numeric literal is E0689 - all in the traps.

Traps

  • An unannotated parse is E0284, not E0283. Readers reasonably expect the most famous generic-return method to be this guide's first family; on current Rust it reports a sibling code, because the diagnostic centers on the associated error type it cannot satisfy - "cannot satisfy <_ as FromStr>::Err == _":
Rust
fn main() {
    let n = "42".parse().unwrap();
    println!("{}", n);
}
Terminal
$ rustc --edition 2021 trap_parse.rs -o trap_parse
error[E0284]: type annotations needed
    --> trap_parse.rs:2:9
     |
   2 |     let n = "42".parse().unwrap();
     |         ^        ----- type must be known at this point
     |
     = note: cannot satisfy `<_ as FromStr>::Err == _`
     = note: the type must also implement `FromStr`
note: required by a bound in `core::str::<impl str>::parse`
    --> /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/str/mod.rs:2782:21
     |
2782 |     pub fn parse<F: FromStr>(&self) -> Result<F, F::Err> {
     |                     ^^^^^^^ required by this bound in `core::str::<impl str>::parse`
help: consider giving `n` an explicit type
     |
   2 |     let n: /* Type */ = "42".parse().unwrap();
     |          ++++++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0284`.
Trap
The repair is the same in practice - annotate the binding, as in the neighbors, or use parse::<i32>() - but the code on the header is E0284, and the E0284 page is the one its "for more information" line names. - A bare None is E0282. Nothing about an unadorned None offers the compiler even one candidate element type, and printing it with {:?} constrains nothing:
Rust
fn main() {
    let o = None;
    println!("{:?}", o);
}
Terminal
$ rustc --edition 2021 trap_none.rs -o trap_none
error[E0282]: type annotations needed for `Option<_>`
 --> trap_none.rs:2:9
  |
2 |     let o = None;
  |         ^   ---- type must be known at this point
  |
help: consider giving `o` an explicit type, where the type for type parameter `T` is specified
  |
2 |     let o: Option<T> = None;
  |          +++++++++++

error: aborting due to 1 previous error

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

The header's short message is identical to E0283's - "type annotations needed" - and only the code separates them: E0282 is the no-candidate case, whose index example is a bare Vec::new(). Annotating - let o: Option<i32> = None; - repairs it the same way, but the distinction matters when reading a diagnostic: E0283 means several types fit, E0282 means none was ever pinned down. - A collect used only through len() is E0282, not E0283. The second family's iterator with a weaker use:

Rust
fn main() {
    let s = (0..3).collect();
    println!("{}", s.len());
}
Terminal
$ rustc --edition 2021 trap_collect_len.rs -o trap_collect_len
error[E0282]: type annotations needed
 --> trap_collect_len.rs:2:9
  |
2 |     let s = (0..3).collect();
  |         ^
3 |     println!("{}", s.len());
  |                    - type must be known at this point
  |
help: consider giving `s` an explicit type
  |
2 |     let s: Vec<_> = (0..3).collect();
  |          ++++++++

error: aborting due to 1 previous error

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

The span structure differs from every family in this guide: the underline sits on the binding alone, and the "type must be known at this point" marker lands on the len() call in the next statement. Same method, same missing annotation, different code - because len is shared by types that are not FromIterator candidates in the compiler's accounting here. The annotation repairs both codes identically. - A string assigned to an integer binding is E0308, a plain mismatch. Not every "type annotations needed" hunt starts from a generic method - where the stated type and the value's type simply disagree, the code is the ordinary mismatch:

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

error: aborting due to 1 previous error

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

The span says "expected integer, found &str". No annotation is missing; the stated annotation is the problem, and the repair is to parse the text - the annotated parse in the neighbors - or change the binding's type. - A method call on an ambiguous numeric literal is E0689. Calling pow on a literal whose binding has no annotation fails before any trait ambiguity arises, with its own code and its own suggested repair:

Rust
fn main() {
    let x = 5;
    let y = x.pow(2);
    println!("{}", y);
}
Terminal
$ rustc --edition 2021 trap_pow.rs -o trap_pow
error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}`
 --> trap_pow.rs:3:15
  |
3 |     let y = x.pow(2);
  |               ^^^
  |
help: you must specify a type for this binding, like `i32`
  |
2 |     let x: i32 = 5;
  |          +++++

error: aborting due to 1 previous error

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

The header names the real issue - "can't call method pow on ambiguous numeric type {integer}" - and the help prescribes the annotation on the literal's binding. It looks like this guide's error from a distance, since an annotation fixes it, but the compiler never reached a choice among implementations: the receiver's type itself was never settled.

Checklist

  • The header checked: E0283 means several types satisfy the program - if the code is E0282, E0284, E0308, or E0689, the traps name the difference before any edit.
  • The note read before editing: a candidate list (the types the compiler is choosing among), a trait name with the target open, or your own impl blocks pointed at - each tells you where the ambiguity lives.
  • The intended type decided by the program's meaning, not by which candidate silences the error: a Vec<char> and a String hold the same characters differently, and a HashMap and a Vec of pairs are different structures.
  • The annotation placed where it decides the open parameter: on the binding, or in the turbofish when there is no binding or the call sits inside an expression.
  • A partial annotation considered: Vec<_> is enough when the rest of the type follows from facts already in the program.
  • For a conversion, the target checked against the value's later use - the annotation is the only place the destination is stated, so it has to match what the rest of the program expects.
  • For try_into, the full target stated, including an array's length, since the target is also the conversion's success condition.
  • The fixed program run, and its output checked against what the program was meant to print - with two Into impls, the wrong annotation compiles and prints the other impl's value.

Sources

  • Rust, Error codes index: E0283 — for the definition of the error as type inference not resulting in one unique possible type, for its collect example with Vec and String as suitable candidates, for the partial Vec underscore annotation and the collect turbofish as repairs, and for its Into example repaired by specifying the trait's type parameter.
  • Rust, Error codes index: E0282 — for the neighboring error with the same short message, for its bare Vec::new example as the case where no type can be inferred, and for its annotation and path repairs.
  • Rust, Error codes index: E0284 — for the sibling error where the compiler cannot unambiguously infer the return type of a generic function or method, and for its repair of using a concrete type for the intermediate expression.
  • The Rust Standard Library, Iterator — for collect as a method generic over a FromIterator result type, and for sum and product as methods generic over the Sum and Product traits.
  • The Rust Standard Library, Into — for Into as a value-to-value conversion generic over its target type, and for implementing From automatically providing the matching Into implementation.
  • The Rust Standard Library, FromStr — for FromStr as the trait behind str parse, for its associated Err type, and for from_str being used implicitly through parse.

Keep Exploring