-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn process(items: impl IntoIterator<Item = String>) -> Vec<String> {
items.collect()
}
Current output
error[E0599]: `impl IntoIterator<Item = String>` is not an iterator
--> src/lib.rs:2:11
|
1 | fn process(items: impl IntoIterator<Item = String>) -> Vec<String> {
| -------------------------------- method `collect` not found for this type parameter
2 | items.collect()
| ^^^^^^^ `impl IntoIterator<Item = String>` is not an iterator
|
= note: the following trait bounds were not satisfied:
`impl IntoIterator<Item = String>: Iterator`
which is required by `&mut impl IntoIterator<Item = String>: Iterator`
help: consider restricting the type parameter to satisfy the trait bound
|
1 | fn process(items: impl IntoIterator<Item = String>) -> Vec<String> where impl IntoIterator<Item = String>: Iterator {
| ++++++++++++++++++++++++++++++++++++++++++++++++
Desired output
error[E0599]: `impl IntoIterator<Item = String>` is not an iterator
--> src/lib.rs:2:11
|
1 | fn process(items: impl IntoIterator<Item = String>) -> Vec<String> {
| -------------------------------- method `collect` not found for this type parameter
2 | items.collect()
| ^^^^^^^ `impl IntoIterator<Item = String>` is not an iterator
|
help: call `.into_iter()` first
|
2 | items.into_iter().collect()
| ++++++++++++
|
Rationale and extra context
It's an easy mistake that takes a moment to realize, so imo it would be cool to handle it better.
Other cases
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
d-sonuga commentedon Jan 3, 2024
@rustbot claim
into_iter()
whenIterator
method called onimpl IntoIterator
#119928Rollup merge of rust-lang#119928 - d-sonuga:into-iter-sugg, r=compile…
Unrolled build for rust-lang#119928
deltragon commentedon Feb 17, 2024
I believe this can be closed as fixed by #119928