You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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";
| +++++++++++
Copy file name to clipboardExpand all lines: src/test/ui/issues/issue-47377.stderr
+3-2
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ LL | let _a = b + ", World!";
7
7
| | `+` cannot be used to concatenate two `&str` strings
8
8
| &str
9
9
|
10
-
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
10
+
= note: string concatenation requires an owned `String` on the left
11
+
help: create an owned `String` from a string reference
Copy file name to clipboardExpand all lines: src/test/ui/issues/issue-47380.stderr
+3-2
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ LL | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
7
7
| | `+` cannot be used to concatenate two `&str` strings
8
8
| &str
9
9
|
10
-
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
10
+
= note: string concatenation requires an owned `String` on the left
11
+
help: create an owned `String` from a string reference
11
12
|
12
13
LL | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
Copy file name to clipboardExpand all lines: src/test/ui/span/issue-39018.stderr
+31-22
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ LL | let x = "Hello " + "World!";
7
7
| | `+` cannot be used to concatenate two `&str` strings
8
8
| &str
9
9
|
10
-
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
10
+
= note: string concatenation requires an owned `String` on the left
11
+
help: create an owned `String` from a string reference
11
12
|
12
13
LL | let x = "Hello ".to_owned() + "World!";
13
-
| ~~~~~~~~~~~~~~~~~~~
14
+
| +++++++++++
14
15
15
16
error[E0369]: cannot add `World` to `World`
16
17
--> $DIR/issue-39018.rs:8:26
@@ -46,10 +47,10 @@ LL | let x = "Hello " + "World!".to_owned();
46
47
| | `+` cannot be used to concatenate a `&str` with a `String`
47
48
| &str
48
49
|
49
-
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
50
+
help: create an owned `String` on the left and add a borrow on the right
50
51
|
51
52
LL | let x = "Hello ".to_owned() + &"World!".to_owned();
52
-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53
+
| +++++++++++ +
53
54
54
55
error[E0369]: cannot add `&String` to `&String`
55
56
--> $DIR/issue-39018.rs:26:16
@@ -60,10 +61,12 @@ LL | let _ = &a + &b;
60
61
| | `+` cannot be used to concatenate two `&str` strings
61
62
| &String
62
63
|
63
-
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
64
+
= note: string concatenation requires an owned `String` on the left
65
+
help: remove the borrow to obtain an owned `String`
64
66
|
65
-
LL | let _ = a + &b;
66
-
| ~
67
+
LL - let _ = &a + &b;
68
+
LL + let _ = a + &b;
69
+
|
67
70
68
71
error[E0369]: cannot add `String` to `&String`
69
72
--> $DIR/issue-39018.rs:27:16
@@ -74,10 +77,11 @@ LL | let _ = &a + b;
74
77
| | `+` cannot be used to concatenate a `&str` with a `String`
75
78
| &String
76
79
|
77
-
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
80
+
help: remove the borrow on the left and add one on the right
78
81
|
79
-
LL | let _ = a + &b;
80
-
| ~ ~~
82
+
LL - let _ = &a + b;
83
+
LL + let _ = a + &b;
84
+
|
81
85
82
86
error[E0308]: mismatched types
83
87
--> $DIR/issue-39018.rs:29:17
@@ -97,10 +101,10 @@ LL | let _ = e + b;
97
101
| | `+` cannot be used to concatenate a `&str` with a `String`
98
102
| &String
99
103
|
100
-
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
104
+
help: create an owned `String` on the left and add a borrow on the right
101
105
|
102
106
LL | let _ = e.to_owned() + &b;
103
-
| ~~~~~~~~~~~~ ~~
107
+
| +++++++++++ +
104
108
105
109
error[E0369]: cannot add `&String` to `&String`
106
110
--> $DIR/issue-39018.rs:31:15
@@ -111,10 +115,11 @@ LL | let _ = e + &b;
111
115
| | `+` cannot be used to concatenate two `&str` strings
112
116
| &String
113
117
|
114
-
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
118
+
= note: string concatenation requires an owned `String` on the left
119
+
help: create an owned `String` from a string reference
115
120
|
116
121
LL | let _ = e.to_owned() + &b;
117
-
| ~~~~~~~~~~~~
122
+
| +++++++++++
118
123
119
124
error[E0369]: cannot add `&str` to `&String`
120
125
--> $DIR/issue-39018.rs:32:15
@@ -125,10 +130,11 @@ LL | let _ = e + d;
125
130
| | `+` cannot be used to concatenate two `&str` strings
126
131
| &String
127
132
|
128
-
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
133
+
= note: string concatenation requires an owned `String` on the left
134
+
help: create an owned `String` from a string reference
129
135
|
130
136
LL | let _ = e.to_owned() + d;
131
-
| ~~~~~~~~~~~~
137
+
| +++++++++++
132
138
133
139
error[E0369]: cannot add `&&str` to `&String`
134
140
--> $DIR/issue-39018.rs:33:15
@@ -139,10 +145,11 @@ LL | let _ = e + &d;
139
145
| | `+` cannot be used to concatenate two `&str` strings
140
146
| &String
141
147
|
142
-
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
148
+
= note: string concatenation requires an owned `String` on the left
149
+
help: create an owned `String` from a string reference
143
150
|
144
151
LL | let _ = e.to_owned() + &d;
145
-
| ~~~~~~~~~~~~
152
+
| +++++++++++
146
153
147
154
error[E0369]: cannot add `&&str` to `&&str`
148
155
--> $DIR/issue-39018.rs:34:16
@@ -169,10 +176,11 @@ LL | let _ = c + &d;
169
176
| | `+` cannot be used to concatenate two `&str` strings
170
177
| &str
171
178
|
172
-
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
179
+
= note: string concatenation requires an owned `String` on the left
180
+
help: create an owned `String` from a string reference
173
181
|
174
182
LL | let _ = c.to_owned() + &d;
175
-
| ~~~~~~~~~~~~
183
+
| +++++++++++
176
184
177
185
error[E0369]: cannot add `&str` to `&str`
178
186
--> $DIR/issue-39018.rs:37:15
@@ -183,10 +191,11 @@ LL | let _ = c + d;
183
191
| | `+` cannot be used to concatenate two `&str` strings
184
192
| &str
185
193
|
186
-
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
194
+
= note: string concatenation requires an owned `String` on the left
195
+
help: create an owned `String` from a string reference
Copy file name to clipboardExpand all lines: src/test/ui/str/str-concat-on-double-ref.stderr
+3-2
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ LL | let c = a + b;
7
7
| | `+` cannot be used to concatenate two `&str` strings
8
8
| &String
9
9
|
10
-
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
10
+
= note: string concatenation requires an owned `String` on the left
11
+
help: create an owned `String` from a string reference
| | `+` cannot be used to concatenate two `&str` strings
8
8
| &str
9
9
|
10
-
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
10
+
= note: string concatenation requires an owned `String` on the left
11
+
help: create an owned `String` from a string reference
11
12
|
12
13
LL | let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༘༙༚༛༜༝༞༟༠༡༢༣༤༥༦༧༨༩༪༫༬༭༮༯༰༱༲༳༴༵༶༷༸༹༺༻༼༽༾༿ཀཁགགྷངཅཆཇཉཊཋཌཌྷཎཏཐདདྷནཔཕབབྷམཙཚཛཛྷཝཞཟའཡརལཤཥསཧཨཀྵཪཫཬཱཱཱིིུུྲྀཷླྀཹེཻོཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun.to_owned() + " really fun!";
0 commit comments