Skip to content

diagnostics: can we suggest &* here? #53879

Closed
@matthiaskrgr

Description

@matthiaskrgr

I spent {way too much} time on this yesterday:

extern crate clap;
fn main() {
    let v = "0.1".to_string();
    let app = clap::App::new("hello world").version(v);
}

this code fails to build with

error[E0277]: the trait bound `&str: std::convert::From<std::string::String>` is not satisfied
 --> src/main.rs:4:45
  |
4 |     let app = clap::App::new("hello world").version(v);
  |                                             ^^^^^^^ the trait `std::convert::From<std::string::String>` is not implemented for `&str`
  |
  = note: required because of the requirements on the impl of `std::convert::Into<&str>` for `std::string::String`
error: aborting due to previous error

passing v by reference doesn't help either ( .version(&v), the msg is almost identical then).

What fixed this for me in the end was .version(&*v).

Is there a way we could suggest to the user to use &* in this example?

the version method signature can be found here

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions