Skip to content

Rustc suggests .to_vec to convert a Vec<T> to Vec<U> #43149

Closed
@Eijebong

Description

@Eijebong

Hey all,

With the following piece of code (rust playground):

struct Foo {}
struct Bar {}

fn hey(pouet: Vec<Bar>){}

fn main() {
    let foo = vec![Foo {}];
    hey(foo);
}

rustc gives me the following error

error[E0308]: mismatched types
 --> a.rs:8:9
  |
8 |     hey(foo);
  |         ^^^ expected struct `Bar`, found struct `Foo`
  |
  = note: expected type `std::vec::Vec<Bar>`
             found type `std::vec::Vec<Foo>`
  = help: here are some functions which might fulfill your needs:
          - .to_vec()

which doesn't make sense since .to_vec() wouldn't in any case convert the inner type.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions