-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
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`D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.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
With new rustc 1.53.0 IntoIterator for arrays, I naively tried this code and the errors message looks scary and for beginners might be very hard to understand.
Given the following code:
fn main() {
let vec = vec![10];
for i in vec.iter().chain([20]){
}
}The current output is:
Compiling playground v0.0.1 (/playground)
error[E0271]: type mismatch resolving `<[{integer}; 1] as IntoIterator>::Item == &{integer}`
--> src/main.rs:3:25
|
3 | for i in vec.iter().chain([20]){
| ^^^^^ expected integer, found `&{integer}`
error[E0271]: type mismatch resolving `<std::array::IntoIter<{integer}, 1_usize> as Iterator>::Item == &{integer}`
--> src/main.rs:3:14
|
3 | for i in vec.iter().chain([20]){
| ^^^^^^^^^^^^^^^^^^^^^^ expected `&{integer}`, found integer
|
= note: required because of the requirements on the impl of `Iterator` for `std::iter::Chain<std::slice::Iter<'_, {integer}>, std::array::IntoIter<{integer}, 1_usize>>`
= note: required because of the requirements on the impl of `IntoIterator` for `std::iter::Chain<std::slice::Iter<'_, {integer}>, std::array::IntoIter<{integer}, 1_usize>>`
= note: required by `into_iter`
error[E0271]: type mismatch resolving `<std::array::IntoIter<{integer}, 1_usize> as Iterator>::Item == &{integer}`
--> src/main.rs:3:14
|
3 | for i in vec.iter().chain([20]){
| ^^^^^^^^^^^^^^^^^^^^^^ expected `&{integer}`, found integer
|
= note: required because of the requirements on the impl of `Iterator` for `std::iter::Chain<std::slice::Iter<'_, {integer}>, std::array::IntoIter<{integer}, 1_usize>>`
= note: required by `std::iter::Iterator::next`
error: aborting due to 3 previous errors
Ideally the output should look like:
Thanks to @CAD97 for suggested output
error[E0271]: type mismatch resolving `<[{integer}; 1] as IntoIterator>::Item == &{integer}`
--> src/main.rs:3:25
|
3 | for i in vec.iter().chain([20]) {}
| ^^^^^ expected integer, found `&{integer}`
= help: try iterating by reference instead
for i in vec.iter().chain(&[20]) {}
^
= help: try copying the iterated items
for i in vec.iter().copied().chain([20]) {}
^^^^^^^^^
= help: try iterating by value instead
for i in vec.into_iter().chain([20]) {}
^^^^^^^^^^^^
EDIT: URLO thread https://users.rust-lang.org/t/rust-1-53-intoiterator/61350
bluss and estebank
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`D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.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.