You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0308]: mismatched types
--> src/main.rs:4:33
|
4 | let items_clone:Vec<i32> = ref_items.clone();
| ^^^^^^^^^^^^^^^^^
| |
| expected struct `std::vec::Vec`, found &[i32]
| help: try using a conversion method: `ref_items.clone().to_vec()`
|
= note: expected type `std::vec::Vec<i32>`
found type `&[i32]`
The suggested fix ref_items.clone().to_vec() will work, but to_vec already copies the data so the extra clone is wasteful. The error message should instead suggest ref_items.to_vec().
This is an error you can run into if ref_items was previously of type &Vec<i32> and you changed it to a slice after writing the rest of the code.
The text was updated successfully, but these errors were encountered:
Let's say you have the following (simplified) code: (Rust Playground)
This results in the following error:
The suggested fix
ref_items.clone().to_vec()
will work, butto_vec
already copies the data so the extraclone
is wasteful. The error message should instead suggestref_items.to_vec()
.This is an error you can run into if
ref_items
was previously of type&Vec<i32>
and you changed it to a slice after writing the rest of the code.The text was updated successfully, but these errors were encountered: