Skip to content

Suggest .collect() when Expected: FromIterator<Item> and <Found as FromIterator<Item> #159493

Closed

Description

@estebank

Code

fn main() {
    let input = "lowercase";
    let uppercase: String = input.chars().map(|c| c.to_ascii_uppercase());
}

Current output

error[E0308]: mismatched types
  --> $DIR/string-from-char-iterator-without-collect.rs:10:29
   |
LL |     let uppercase: String = input.chars().map(|c| c.to_ascii_uppercase());
   |                    ------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Map<Chars<'_>, {closure@...}>`
   |                    |
   |                    expected due to this
   |
   = note: expected struct `String`
              found struct `Map<Chars<'_>, {closure@$DIR/string-from-char-iterator-without-collect.rs:10:47: 10:50}>`

Desired output

error[E0308]: mismatched types
  --> $DIR/string-from-char-iterator-without-collect.rs:10:29
   |
LL |     let uppercase: String = input.chars().map(|c| c.to_ascii_uppercase());
   |                    ------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Map<Chars<'_>, {closure@...}>`
   |                    |
   |                    expected due to this
   |
   = note: expected struct `String`
              found struct `Map<Chars<'_>, {closure@$DIR/string-from-char-iterator-without-collect.rs:10:47: 10:50}>`
help: you can collect the `Iterator<Item = char>` into a `String`
   |
LL |     let uppercase: String = input.chars().map(|c| c.to_ascii_uppercase()).collect();
   |                                                                          ++++++++++

Rationale and extra context

No response

Other cases

Rust Version

1.97

Anything else?

No response

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.
    on Jul 18, 2026
  2. mejrs commented on Jul 19, 2026

    @mejrs
    Member

    Fixed in #156121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions