Skip to content

Commit 7507fb6

Browse files
committed
Shorten and improve messages
1 parent 6e42bc3 commit 7507fb6

File tree

6 files changed

+58
-112
lines changed

6 files changed

+58
-112
lines changed

compiler/rustc_typeck/src/check/op.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
549549
is_assign: IsAssign,
550550
op: hir::BinOp,
551551
) -> bool {
552-
let str_concat_note = "String concatenation appends the string on the right to the
553-
string on the left and may require reallocation.
554-
This requires ownership of the string on the left.";
552+
let str_concat_note = "string concatenation requires an owned `String` on the left";
555553
let rm_borrow_msg = "remove the borrow to obtain an owned `String`";
556-
let to_owned_msg = "use `to_owned()` to create an owned `String` from a string reference";
554+
let to_owned_msg = "create an owned `String` from a string reference";
557555

558556
let string_type = self.tcx.get_diagnostic_item(sym::String);
559557
let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() {
@@ -603,7 +601,7 @@ This requires ownership of the string on the left.";
603601
sugg_msg = "remove the borrow on the left and add one on the right";
604602
(lhs_expr.span.until(lhs_inner_expr.span), "".to_owned())
605603
} else {
606-
sugg_msg = "call `.to_owned()` on the left and add a borrow on the right";
604+
sugg_msg = "create an owned `String` on the left and add a borrow on the right";
607605
(lhs_expr.span.shrink_to_hi(), ".to_owned()".to_owned())
608606
};
609607
let suggestions = vec![

src/test/ui/issues/issue-47377.stderr

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ error[E0369]: cannot add `&str` to `&str`
22
--> $DIR/issue-47377.rs:4:14
33
|
44
LL | let _a = b + ", World!";
5-
| - ^ ---------- &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
5+
| --^ ---------- &str
6+
| |||
7+
| ||`+` cannot be used to concatenate two `&str` strings
8+
| |help: create an owned `String` from a string reference: `.to_owned()`
89
| &str
910
|
10-
= note: String concatenation appends the string on the right to the
11-
string on the left and may require reallocation.
12-
This requires ownership of the string on the left.
13-
help: use `to_owned()` to create an owned `String` from a string reference
14-
|
15-
LL | let _a = b.to_owned() + ", World!";
16-
| +++++++++++
11+
= note: string concatenation requires an owned `String` on the left
1712

1813
error: aborting due to previous error
1914

src/test/ui/issues/issue-47380.stderr

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ error[E0369]: cannot add `&str` to `&str`
22
--> $DIR/issue-47380.rs:3:35
33
|
44
LL | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
5-
| - ^ ---------- &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
5+
| --^ ---------- &str
6+
| |||
7+
| ||`+` cannot be used to concatenate two `&str` strings
8+
| |help: create an owned `String` from a string reference: `.to_owned()`
89
| &str
910
|
10-
= note: String concatenation appends the string on the right to the
11-
string on the left and may require reallocation.
12-
This requires ownership of the string on the left.
13-
help: use `to_owned()` to create an owned `String` from a string reference
14-
|
15-
LL | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
16-
| +++++++++++
11+
= note: string concatenation requires an owned `String` on the left
1712

1813
error: aborting due to previous error
1914

src/test/ui/span/issue-39018.stderr

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ error[E0369]: cannot add `&str` to `&str`
22
--> $DIR/issue-39018.rs:2:22
33
|
44
LL | let x = "Hello " + "World!";
5-
| -------- ^ -------- &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
5+
| ---------^ -------- &str
6+
| | ||
7+
| | |`+` cannot be used to concatenate two `&str` strings
8+
| | help: create an owned `String` from a string reference: `.to_owned()`
89
| &str
910
|
10-
= note: String concatenation appends the string on the right to the
11-
string on the left and may require reallocation.
12-
This requires ownership of the string on the left.
13-
help: use `to_owned()` to create an owned `String` from a string reference
14-
|
15-
LL | let x = "Hello ".to_owned() + "World!";
16-
| +++++++++++
11+
= note: string concatenation requires an owned `String` on the left
1712

1813
error[E0369]: cannot add `World` to `World`
1914
--> $DIR/issue-39018.rs:8:26
@@ -49,7 +44,7 @@ LL | let x = "Hello " + "World!".to_owned();
4944
| | `+` cannot be used to concatenate a `&str` with a `String`
5045
| &str
5146
|
52-
help: call `.to_owned()` on the left and add a borrow on the right
47+
help: create an owned `String` on the left and add a borrow on the right
5348
|
5449
LL | let x = "Hello ".to_owned() + &"World!".to_owned();
5550
| +++++++++++ +
@@ -64,9 +59,7 @@ LL | let _ = &a + &b;
6459
| &String
6560
| help: remove the borrow to obtain an owned `String`
6661
|
67-
= note: String concatenation appends the string on the right to the
68-
string on the left and may require reallocation.
69-
This requires ownership of the string on the left.
62+
= note: string concatenation requires an owned `String` on the left
7063

7164
error[E0369]: cannot add `String` to `&String`
7265
--> $DIR/issue-39018.rs:27:16
@@ -101,7 +94,7 @@ LL | let _ = e + b;
10194
| | `+` cannot be used to concatenate a `&str` with a `String`
10295
| &String
10396
|
104-
help: call `.to_owned()` on the left and add a borrow on the right
97+
help: create an owned `String` on the left and add a borrow on the right
10598
|
10699
LL | let _ = e.to_owned() + &b;
107100
| +++++++++++ +
@@ -110,52 +103,37 @@ error[E0369]: cannot add `&String` to `&String`
110103
--> $DIR/issue-39018.rs:31:15
111104
|
112105
LL | let _ = e + &b;
113-
| - ^ -- &String
114-
| | |
115-
| | `+` cannot be used to concatenate two `&str` strings
106+
| --^ -- &String
107+
| |||
108+
| ||`+` cannot be used to concatenate two `&str` strings
109+
| |help: create an owned `String` from a string reference: `.to_owned()`
116110
| &String
117111
|
118-
= note: String concatenation appends the string on the right to the
119-
string on the left and may require reallocation.
120-
This requires ownership of the string on the left.
121-
help: use `to_owned()` to create an owned `String` from a string reference
122-
|
123-
LL | let _ = e.to_owned() + &b;
124-
| +++++++++++
112+
= note: string concatenation requires an owned `String` on the left
125113

126114
error[E0369]: cannot add `&str` to `&String`
127115
--> $DIR/issue-39018.rs:32:15
128116
|
129117
LL | let _ = e + d;
130-
| - ^ - &str
131-
| | |
132-
| | `+` cannot be used to concatenate two `&str` strings
118+
| --^ - &str
119+
| |||
120+
| ||`+` cannot be used to concatenate two `&str` strings
121+
| |help: create an owned `String` from a string reference: `.to_owned()`
133122
| &String
134123
|
135-
= note: String concatenation appends the string on the right to the
136-
string on the left and may require reallocation.
137-
This requires ownership of the string on the left.
138-
help: use `to_owned()` to create an owned `String` from a string reference
139-
|
140-
LL | let _ = e.to_owned() + d;
141-
| +++++++++++
124+
= note: string concatenation requires an owned `String` on the left
142125

143126
error[E0369]: cannot add `&&str` to `&String`
144127
--> $DIR/issue-39018.rs:33:15
145128
|
146129
LL | let _ = e + &d;
147-
| - ^ -- &&str
148-
| | |
149-
| | `+` cannot be used to concatenate two `&str` strings
130+
| --^ -- &&str
131+
| |||
132+
| ||`+` cannot be used to concatenate two `&str` strings
133+
| |help: create an owned `String` from a string reference: `.to_owned()`
150134
| &String
151135
|
152-
= note: String concatenation appends the string on the right to the
153-
string on the left and may require reallocation.
154-
This requires ownership of the string on the left.
155-
help: use `to_owned()` to create an owned `String` from a string reference
156-
|
157-
LL | let _ = e.to_owned() + &d;
158-
| +++++++++++
136+
= note: string concatenation requires an owned `String` on the left
159137

160138
error[E0369]: cannot add `&&str` to `&&str`
161139
--> $DIR/issue-39018.rs:34:16
@@ -177,35 +155,25 @@ error[E0369]: cannot add `&&str` to `&str`
177155
--> $DIR/issue-39018.rs:36:15
178156
|
179157
LL | let _ = c + &d;
180-
| - ^ -- &&str
181-
| | |
182-
| | `+` cannot be used to concatenate two `&str` strings
158+
| --^ -- &&str
159+
| |||
160+
| ||`+` cannot be used to concatenate two `&str` strings
161+
| |help: create an owned `String` from a string reference: `.to_owned()`
183162
| &str
184163
|
185-
= note: String concatenation appends the string on the right to the
186-
string on the left and may require reallocation.
187-
This requires ownership of the string on the left.
188-
help: use `to_owned()` to create an owned `String` from a string reference
189-
|
190-
LL | let _ = c.to_owned() + &d;
191-
| +++++++++++
164+
= note: string concatenation requires an owned `String` on the left
192165

193166
error[E0369]: cannot add `&str` to `&str`
194167
--> $DIR/issue-39018.rs:37:15
195168
|
196169
LL | let _ = c + d;
197-
| - ^ - &str
198-
| | |
199-
| | `+` cannot be used to concatenate two `&str` strings
170+
| --^ - &str
171+
| |||
172+
| ||`+` cannot be used to concatenate two `&str` strings
173+
| |help: create an owned `String` from a string reference: `.to_owned()`
200174
| &str
201175
|
202-
= note: String concatenation appends the string on the right to the
203-
string on the left and may require reallocation.
204-
This requires ownership of the string on the left.
205-
help: use `to_owned()` to create an owned `String` from a string reference
206-
|
207-
LL | let _ = c.to_owned() + d;
208-
| +++++++++++
176+
= note: string concatenation requires an owned `String` on the left
209177

210178
error: aborting due to 14 previous errors
211179

src/test/ui/str/str-concat-on-double-ref.stderr

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ error[E0369]: cannot add `&str` to `&String`
22
--> $DIR/str-concat-on-double-ref.rs:4:15
33
|
44
LL | let c = a + b;
5-
| - ^ - &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
5+
| --^ - &str
6+
| |||
7+
| ||`+` cannot be used to concatenate two `&str` strings
8+
| |help: create an owned `String` from a string reference: `.to_owned()`
89
| &String
910
|
10-
= note: String concatenation appends the string on the right to the
11-
string on the left and may require reallocation.
12-
This requires ownership of the string on the left.
13-
help: use `to_owned()` to create an owned `String` from a string reference
14-
|
15-
LL | let c = a.to_owned() + b;
16-
| +++++++++++
11+
= note: string concatenation requires an owned `String` on the left
1712

1813
error: aborting due to previous error
1914

src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
error[E0369]: cannot add `&str` to `&str`
22
--> $DIR/non-1-width-unicode-multiline-label.rs:5:260
33
|
4-
LL | ...ཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗ྘ྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྽྾྿࿀࿁࿂࿃࿄࿅࿆࿇...࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
5-
| -------------- ^ -------------- &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
8-
| &str
4+
LL | ...྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗ྘ྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྽྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿍࿎...࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
5+
| ---------------^ -------------- &str
6+
| | ||
7+
| | |`+` cannot be used to concatenate two `&str` strings
8+
| | help: create an owned `String` from a string reference: `.to_owned()`
9+
| &str
910
|
10-
= note: String concatenation appends the string on the right to the
11-
string on the left and may require reallocation.
12-
This requires ownership of the string on the left.
13-
help: use `to_owned()` to create an owned `String` from a string reference
14-
|
15-
LL | let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༘༙༚༛༜༝༞༟༠༡༢༣༤༥༦༧༨༩༪༫༬༭༮༯༰༱༲༳༴༵༶༷༸༹༺༻༼༽༾༿ཀཁགགྷངཅཆཇ཈ཉཊཋཌཌྷཎཏཐདདྷནཔཕབབྷམཙཚཛཛྷཝཞཟའཡརལཤཥསཧཨཀྵཪཫཬ཭཮཯཰ཱཱཱིིུུྲྀཷླྀཹེཻོཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗ྘ྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྽྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun.to_owned() + " really fun!";
16-
| +++++++++++
11+
= note: string concatenation requires an owned `String` on the left
1712

1813
error: aborting due to previous error
1914

0 commit comments

Comments
 (0)