Rollup merge of #52605 - estebank:str-plus-eq, r=oli-obk

Do not suggest using `to_owned()` on `&str += &str`

 - Don't provide incorrect suggestion for `&str += &str` (fix #52410)
 - On `&str + String` suggest `&str.to_owned() + &String` as a single suggestion
This commit is contained in:
kennytm 2018-07-24 09:49:52 +08:00 committed by GitHub
commit 5b7e3a1746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 42 deletions

View file

@ -5,11 +5,6 @@ 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" };
| ^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -23,12 +23,8 @@ LL | let x = "Hello " + "World!".to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `+` can't be used to concatenate a `&str` with a `String`
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 | let x = "Hello ".to_owned() + "World!".to_owned();
| ^^^^^^^^^^^^^^^^^^^
help: you also need to borrow the `String` on the right to get a `&str`
|
LL | let x = "Hello " + &"World!".to_owned();
| ^^^^^^^^^^^^^^^^^^^^
LL | let x = "Hello ".to_owned() + &"World!".to_owned();
| ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors