Rollup merge of #92843 - camelid:str-concat-sugg, r=davidtwco
Improve string concatenation suggestion
Before:
error[E0369]: cannot add `&str` to `&str`
--> file.rs:2:22
|
2 | let _x = "hello" + " world";
| ------- ^ -------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
|
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
|
2 | let _x = "hello".to_owned() + " world";
| ~~~~~~~~~~~~~~~~~~
After:
error[E0369]: cannot add `&str` to `&str`
--> file.rs:2:22
|
2 | let _x = "hello" + " world";
| ------- ^ -------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
|
= note: string concatenation requires an owned `String` on the left
help: create an owned `String` from a string reference
|
2 | let _x = "hello".to_owned() + " world";
| +++++++++++
This commit is contained in:
commit
430673f265
6 changed files with 81 additions and 85 deletions
|
|
@ -7,10 +7,11 @@ LL | let _a = b + ", World!";
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &str
|
||||
|
|
||||
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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _a = b.to_owned() + ", World!";
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ LL | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &str
|
||||
|
|
||||
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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ LL | let x = "Hello " + "World!";
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &str
|
||||
|
|
||||
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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let x = "Hello ".to_owned() + "World!";
|
||||
| ~~~~~~~~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error[E0369]: cannot add `World` to `World`
|
||||
--> $DIR/issue-39018.rs:8:26
|
||||
|
|
@ -46,10 +47,10 @@ LL | let x = "Hello " + "World!".to_owned();
|
|||
| | `+` cannot be used to concatenate a `&str` with a `String`
|
||||
| &str
|
||||
|
|
||||
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
|
||||
help: create an owned `String` on the left and add a borrow on the right
|
||||
|
|
||||
LL | let x = "Hello ".to_owned() + &"World!".to_owned();
|
||||
| ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
|
||||
| +++++++++++ +
|
||||
|
||||
error[E0369]: cannot add `&String` to `&String`
|
||||
--> $DIR/issue-39018.rs:26:16
|
||||
|
|
@ -60,10 +61,12 @@ LL | let _ = &a + &b;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &String
|
||||
|
|
||||
help: 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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: remove the borrow to obtain an owned `String`
|
||||
|
|
||||
LL | let _ = a + &b;
|
||||
| ~
|
||||
LL - let _ = &a + &b;
|
||||
LL + let _ = a + &b;
|
||||
|
|
||||
|
||||
error[E0369]: cannot add `String` to `&String`
|
||||
--> $DIR/issue-39018.rs:27:16
|
||||
|
|
@ -74,10 +77,11 @@ LL | let _ = &a + b;
|
|||
| | `+` cannot be used to concatenate a `&str` with a `String`
|
||||
| &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
|
||||
help: remove the borrow on the left and add one on the right
|
||||
|
|
||||
LL | let _ = a + &b;
|
||||
| ~ ~~
|
||||
LL - let _ = &a + b;
|
||||
LL + let _ = a + &b;
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-39018.rs:29:17
|
||||
|
|
@ -97,10 +101,10 @@ LL | let _ = e + b;
|
|||
| | `+` cannot be used to concatenate a `&str` with a `String`
|
||||
| &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
|
||||
help: create an owned `String` on the left and add a borrow on the right
|
||||
|
|
||||
LL | let _ = e.to_owned() + &b;
|
||||
| ~~~~~~~~~~~~ ~~
|
||||
| +++++++++++ +
|
||||
|
||||
error[E0369]: cannot add `&String` to `&String`
|
||||
--> $DIR/issue-39018.rs:31:15
|
||||
|
|
@ -111,10 +115,11 @@ LL | let _ = e + &b;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = e.to_owned() + &b;
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error[E0369]: cannot add `&str` to `&String`
|
||||
--> $DIR/issue-39018.rs:32:15
|
||||
|
|
@ -125,10 +130,11 @@ LL | let _ = e + d;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = e.to_owned() + d;
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error[E0369]: cannot add `&&str` to `&String`
|
||||
--> $DIR/issue-39018.rs:33:15
|
||||
|
|
@ -139,10 +145,11 @@ LL | let _ = e + &d;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = e.to_owned() + &d;
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error[E0369]: cannot add `&&str` to `&&str`
|
||||
--> $DIR/issue-39018.rs:34:16
|
||||
|
|
@ -169,10 +176,11 @@ LL | let _ = c + &d;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &str
|
||||
|
|
||||
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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = c.to_owned() + &d;
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error[E0369]: cannot add `&str` to `&str`
|
||||
--> $DIR/issue-39018.rs:37:15
|
||||
|
|
@ -183,10 +191,11 @@ LL | let _ = c + d;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &str
|
||||
|
|
||||
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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = c.to_owned() + d;
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ LL | let c = a + b;
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let c = a.to_owned() + b;
|
||||
| ~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ LL | ...ཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔ
|
|||
| | `+` cannot be used to concatenate two `&str` strings
|
||||
| &str
|
||||
|
|
||||
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
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
help: create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༘༙༚༛༜༝༞༟༠༡༢༣༤༥༦༧༨༩༪༫༬༭༮༯༰༱༲༳༴༵༶༷༸༹༺༻༼༽༾༿ཀཁགགྷངཅཆཇཉཊཋཌཌྷཎཏཐདདྷནཔཕབབྷམཙཚཛཛྷཝཞཟའཡརལཤཥསཧཨཀྵཪཫཬཱཱཱིིུུྲྀཷླྀཹེཻོཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun.to_owned() + " really fun!";
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
| +++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue