Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostics: can we suggest &* here? #53879

Closed
matthiaskrgr opened this issue Sep 1, 2018 · 3 comments
Closed

diagnostics: can we suggest &* here? #53879

matthiaskrgr opened this issue Sep 1, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@matthiaskrgr
Copy link
Member

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

@Havvy
Copy link
Contributor

Havvy commented Sep 1, 2018

version signature:

pub fn version<S: Into<&'b str>>(self, ver: S) -> Self

Looks like you can just do let v = "0.1"; and pass it in that way? Or even const VERSION: &str = "0.1";

@Havvy Havvy added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 1, 2018
@matthiaskrgr
Copy link
Member Author

Indeed, but in my original code I had a function to generate the version which returned a String,

@memoryruins
Copy link
Contributor

A similar issue was opened last week on clap's repository clap-rs/clap#1336

Centril added a commit to Centril/rust that referenced this issue Mar 27, 2019
…avus

Add suggestion to use `&*var` when `&str: From<String>` is expected

Fix rust-lang#53879.
Centril added a commit to Centril/rust that referenced this issue Mar 27, 2019
…avus

Add suggestion to use `&*var` when `&str: From<String>` is expected

Fix rust-lang#53879.
cuviper added a commit to cuviper/rust that referenced this issue Mar 28, 2019
…avus

Add suggestion to use `&*var` when `&str: From<String>` is expected

Fix rust-lang#53879.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

3 participants