Skip to content

Commit 7c4eca0

Browse files
committed
Make suggestions verbose
1 parent 7507fb6 commit 7c4eca0

File tree

6 files changed

+84
-46
lines changed

6 files changed

+84
-46
lines changed

compiler/rustc_typeck/src/check/op.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
570570
err.span_label(op.span, "`+` cannot be used to concatenate two `&str` strings");
571571
err.note(str_concat_note);
572572
if let hir::ExprKind::AddrOf(_, _, lhs_inner_expr) = lhs_expr.kind {
573-
err.span_suggestion(
573+
err.span_suggestion_verbose(
574574
lhs_expr.span.until(lhs_inner_expr.span),
575575
rm_borrow_msg,
576576
"".to_owned(),
577577
Applicability::MachineApplicable
578578
);
579579
} else {
580-
err.span_suggestion(
580+
err.span_suggestion_verbose(
581581
lhs_expr.span.shrink_to_hi(),
582582
to_owned_msg,
583583
".to_owned()".to_owned(),
@@ -608,7 +608,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608608
lhs_sugg,
609609
(rhs_expr.span.shrink_to_lo(), "&".to_owned()),
610610
];
611-
err.multipart_suggestion(sugg_msg, suggestions, Applicability::MachineApplicable);
611+
err.multipart_suggestion_verbose(
612+
sugg_msg,
613+
suggestions,
614+
Applicability::MachineApplicable,
615+
);
612616
}
613617
IsAssign::Yes => {
614618
err.note(str_concat_note);

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ 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
8-
| |help: create an owned `String` from a string reference: `.to_owned()`
5+
| - ^ ---------- &str
6+
| | |
7+
| | `+` cannot be used to concatenate two `&str` strings
98
| &str
109
|
1110
= note: string concatenation requires an owned `String` on the left
11+
help: create an owned `String` from a string reference
12+
|
13+
LL | let _a = b.to_owned() + ", World!";
14+
| +++++++++++
1215

1316
error: aborting due to previous error
1417

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ 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
8-
| |help: create an owned `String` from a string reference: `.to_owned()`
5+
| - ^ ---------- &str
6+
| | |
7+
| | `+` cannot be used to concatenate two `&str` strings
98
| &str
109
|
1110
= note: string concatenation requires an owned `String` on the left
11+
help: create an owned `String` from a string reference
12+
|
13+
LL | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
14+
| +++++++++++
1215

1316
error: aborting due to previous error
1417

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

+47-25
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ 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
8-
| | help: create an owned `String` from a string reference: `.to_owned()`
5+
| -------- ^ -------- &str
6+
| | |
7+
| | `+` cannot be used to concatenate two `&str` strings
98
| &str
109
|
1110
= note: string concatenation requires an owned `String` on the left
11+
help: create an owned `String` from a string reference
12+
|
13+
LL | let x = "Hello ".to_owned() + "World!";
14+
| +++++++++++
1215

1316
error[E0369]: cannot add `World` to `World`
1417
--> $DIR/issue-39018.rs:8:26
@@ -57,9 +60,13 @@ LL | let _ = &a + &b;
5760
| | |
5861
| | `+` cannot be used to concatenate two `&str` strings
5962
| &String
60-
| help: remove the borrow to obtain an owned `String`
6163
|
6264
= note: string concatenation requires an owned `String` on the left
65+
help: remove the borrow to obtain an owned `String`
66+
|
67+
LL - let _ = &a + &b;
68+
LL + let _ = a + &b;
69+
|
6370

6471
error[E0369]: cannot add `String` to `&String`
6572
--> $DIR/issue-39018.rs:27:16
@@ -103,37 +110,46 @@ error[E0369]: cannot add `&String` to `&String`
103110
--> $DIR/issue-39018.rs:31:15
104111
|
105112
LL | let _ = e + &b;
106-
| --^ -- &String
107-
| |||
108-
| ||`+` cannot be used to concatenate two `&str` strings
109-
| |help: create an owned `String` from a string reference: `.to_owned()`
113+
| - ^ -- &String
114+
| | |
115+
| | `+` cannot be used to concatenate two `&str` strings
110116
| &String
111117
|
112118
= note: string concatenation requires an owned `String` on the left
119+
help: create an owned `String` from a string reference
120+
|
121+
LL | let _ = e.to_owned() + &b;
122+
| +++++++++++
113123

114124
error[E0369]: cannot add `&str` to `&String`
115125
--> $DIR/issue-39018.rs:32:15
116126
|
117127
LL | let _ = e + d;
118-
| --^ - &str
119-
| |||
120-
| ||`+` cannot be used to concatenate two `&str` strings
121-
| |help: create an owned `String` from a string reference: `.to_owned()`
128+
| - ^ - &str
129+
| | |
130+
| | `+` cannot be used to concatenate two `&str` strings
122131
| &String
123132
|
124133
= note: string concatenation requires an owned `String` on the left
134+
help: create an owned `String` from a string reference
135+
|
136+
LL | let _ = e.to_owned() + d;
137+
| +++++++++++
125138

126139
error[E0369]: cannot add `&&str` to `&String`
127140
--> $DIR/issue-39018.rs:33:15
128141
|
129142
LL | let _ = e + &d;
130-
| --^ -- &&str
131-
| |||
132-
| ||`+` cannot be used to concatenate two `&str` strings
133-
| |help: create an owned `String` from a string reference: `.to_owned()`
143+
| - ^ -- &&str
144+
| | |
145+
| | `+` cannot be used to concatenate two `&str` strings
134146
| &String
135147
|
136148
= note: string concatenation requires an owned `String` on the left
149+
help: create an owned `String` from a string reference
150+
|
151+
LL | let _ = e.to_owned() + &d;
152+
| +++++++++++
137153

138154
error[E0369]: cannot add `&&str` to `&&str`
139155
--> $DIR/issue-39018.rs:34:16
@@ -155,25 +171,31 @@ error[E0369]: cannot add `&&str` to `&str`
155171
--> $DIR/issue-39018.rs:36:15
156172
|
157173
LL | let _ = c + &d;
158-
| --^ -- &&str
159-
| |||
160-
| ||`+` cannot be used to concatenate two `&str` strings
161-
| |help: create an owned `String` from a string reference: `.to_owned()`
174+
| - ^ -- &&str
175+
| | |
176+
| | `+` cannot be used to concatenate two `&str` strings
162177
| &str
163178
|
164179
= note: string concatenation requires an owned `String` on the left
180+
help: create an owned `String` from a string reference
181+
|
182+
LL | let _ = c.to_owned() + &d;
183+
| +++++++++++
165184

166185
error[E0369]: cannot add `&str` to `&str`
167186
--> $DIR/issue-39018.rs:37:15
168187
|
169188
LL | let _ = c + d;
170-
| --^ - &str
171-
| |||
172-
| ||`+` cannot be used to concatenate two `&str` strings
173-
| |help: create an owned `String` from a string reference: `.to_owned()`
189+
| - ^ - &str
190+
| | |
191+
| | `+` cannot be used to concatenate two `&str` strings
174192
| &str
175193
|
176194
= note: string concatenation requires an owned `String` on the left
195+
help: create an owned `String` from a string reference
196+
|
197+
LL | let _ = c.to_owned() + d;
198+
| +++++++++++
177199

178200
error: aborting due to 14 previous errors
179201

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ 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
8-
| |help: create an owned `String` from a string reference: `.to_owned()`
5+
| - ^ - &str
6+
| | |
7+
| | `+` cannot be used to concatenate two `&str` strings
98
| &String
109
|
1110
= note: string concatenation requires an owned `String` on the left
11+
help: create an owned `String` from a string reference
12+
|
13+
LL | let c = a.to_owned() + b;
14+
| +++++++++++
1215

1316
error: aborting due to previous error
1417

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

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

1316
error: aborting due to previous error
1417

0 commit comments

Comments
 (0)