-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: "try using a conversion method: `*i.to_string().to_string()" #53348
Comments
Not sure if this is entirely correct but I'm pretty sure it has to do with precedence of the dereference. This code has the same issue: fn main() {
let hello = String::from("hello");
let mut vec: Vec<String> = Vec::new();
vec.push(*hello.to_string());
} while if you write: fn main() {
let hello = String::from("hello");
let mut vec: Vec<String> = Vec::new();
vec.push((*hello).to_string());
} it will compile fine. @matthiaskrgr Also just to note there were some other issues with the code you posted -- |
And also just wanted to point out that this is a redundant operation to begin with because you're trying to convert a fn main() {
let v = vec!["hello", "this", "is", "a", "test"];
let mut v2: Vec<String> = Vec::new();
let owned = v.into_iter().map(|s|s.to_owned()).collect::<Vec<_>>();
for i in owned {
v2.push(i);
}
} This is an equivalent example with strong typing on v2 to see that its still or if you still wanted to iterate over v (ignoring the move) you could do: fn main() {
let v = vec!["hello", "this", "is", "a", "test"];
let mut v2: Vec<String> = Vec::new();
for i in v {
v2.push(i.to_string());
}
} |
Yeah, I know the code is quite wonky, :) I was in the middle of a refactoring when I stumbled over the .to_string().to_string() oddity. |
…haelwoerister Do not suggest conversion method that is already there Fix rust-lang#53348.
Example I came up with (tried to reduce from a larger set of code I found this in)
This gives a rather confusing error message:
meta:
The text was updated successfully, but these errors were encountered: