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

Wrong suggestion for &str += &str #52410

Closed
estebank opened this issue Jul 16, 2018 · 0 comments · Fixed by #52605
Closed

Wrong suggestion for &str += &str #52410

estebank opened this issue Jul 16, 2018 · 0 comments · Fixed by #52605
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@estebank
Copy link
Contributor

estebank commented Jul 16, 2018

Current output for &str += &str:

error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
  --> $DIR/issue-10401.rs:13:5
   |
LL |     a += { "b" };
   |     -^^^^^^^^^^^
   |     |
   |     cannot use `+=` on type `&str`
   |     `+` can't be used to concatenate two `&str` strings
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
   |
LL |     a.to_owned() += { "b" };
   |     ^^^^^^^^^^^^

It should at the very least not provide the incorrect suggestion, probably have custom help explaining that a should be a String, best would be to suggest new valid code (but it's probably too complex a case to do).

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 16, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jul 24, 2018
Do not suggest using `to_owned()` on `&str += &str`

 - Don't provide incorrect suggestion for `&str += &str` (fix rust-lang#52410)
 - On `&str + String` suggest `&str.to_owned() + &String` as a single suggestion
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

Successfully merging a pull request may close this issue.

1 participant