Skip to content

Commit

Permalink
Make suggestions verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Jan 19, 2022
1 parent 7507fb6 commit 7c4eca0
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_typeck/src/check/op.rs
Expand Up @@ -570,14 +570,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(op.span, "`+` cannot be used to concatenate two `&str` strings");
err.note(str_concat_note);
if let hir::ExprKind::AddrOf(_, _, lhs_inner_expr) = lhs_expr.kind {
err.span_suggestion(
err.span_suggestion_verbose(
lhs_expr.span.until(lhs_inner_expr.span),
rm_borrow_msg,
"".to_owned(),
Applicability::MachineApplicable
);
} else {
err.span_suggestion(
err.span_suggestion_verbose(
lhs_expr.span.shrink_to_hi(),
to_owned_msg,
".to_owned()".to_owned(),
Expand Down Expand Up @@ -608,7 +608,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
lhs_sugg,
(rhs_expr.span.shrink_to_lo(), "&".to_owned()),
];
err.multipart_suggestion(sugg_msg, suggestions, Applicability::MachineApplicable);
err.multipart_suggestion_verbose(
sugg_msg,
suggestions,
Applicability::MachineApplicable,
);
}
IsAssign::Yes => {
err.note(str_concat_note);
Expand Down
11 changes: 7 additions & 4 deletions src/test/ui/issues/issue-47377.stderr
Expand Up @@ -2,13 +2,16 @@ error[E0369]: cannot add `&str` to `&str`
--> $DIR/issue-47377.rs:4:14
|
LL | let _a = b + ", World!";
| --^ ---------- &str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ ---------- &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
|
LL | let _a = b.to_owned() + ", World!";
| +++++++++++

error: aborting due to previous error

Expand Down
11 changes: 7 additions & 4 deletions src/test/ui/issues/issue-47380.stderr
Expand Up @@ -2,13 +2,16 @@ error[E0369]: cannot add `&str` to `&str`
--> $DIR/issue-47380.rs:3:35
|
LL | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
| --^ ---------- &str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ ---------- &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
|
LL | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
| +++++++++++

error: aborting due to previous error

Expand Down
72 changes: 47 additions & 25 deletions src/test/ui/span/issue-39018.stderr
Expand Up @@ -2,13 +2,16 @@ error[E0369]: cannot add `&str` to `&str`
--> $DIR/issue-39018.rs:2:22
|
LL | let x = "Hello " + "World!";
| ---------^ -------- &str
| | ||
| | |`+` cannot be used to concatenate two `&str` strings
| | help: create an owned `String` from a string reference: `.to_owned()`
| -------- ^ -------- &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
|
LL | let x = "Hello ".to_owned() + "World!";
| +++++++++++

error[E0369]: cannot add `World` to `World`
--> $DIR/issue-39018.rs:8:26
Expand Down Expand Up @@ -57,9 +60,13 @@ LL | let _ = &a + &b;
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &String
| help: remove the borrow to obtain an owned `String`
|
= 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;
|

error[E0369]: cannot add `String` to `&String`
--> $DIR/issue-39018.rs:27:16
Expand Down Expand Up @@ -103,37 +110,46 @@ error[E0369]: cannot add `&String` to `&String`
--> $DIR/issue-39018.rs:31:15
|
LL | let _ = e + &b;
| --^ -- &String
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ -- &String
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &String
|
= 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
|
LL | let _ = e + d;
| --^ - &str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ - &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &String
|
= 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
|
LL | let _ = e + &d;
| --^ -- &&str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ -- &&str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &String
|
= 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
Expand All @@ -155,25 +171,31 @@ error[E0369]: cannot add `&&str` to `&str`
--> $DIR/issue-39018.rs:36:15
|
LL | let _ = c + &d;
| --^ -- &&str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ -- &&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
|
LL | let _ = c.to_owned() + &d;
| +++++++++++

error[E0369]: cannot add `&str` to `&str`
--> $DIR/issue-39018.rs:37:15
|
LL | let _ = c + d;
| --^ - &str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ - &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
|
LL | let _ = c.to_owned() + d;
| +++++++++++

error: aborting due to 14 previous errors

Expand Down
11 changes: 7 additions & 4 deletions src/test/ui/str/str-concat-on-double-ref.stderr
Expand Up @@ -2,13 +2,16 @@ error[E0369]: cannot add `&str` to `&String`
--> $DIR/str-concat-on-double-ref.rs:4:15
|
LL | let c = a + b;
| --^ - &str
| |||
| ||`+` cannot be used to concatenate two `&str` strings
| |help: create an owned `String` from a string reference: `.to_owned()`
| - ^ - &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &String
|
= 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

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

error: aborting due to previous error

Expand Down

0 comments on commit 7c4eca0

Please sign in to comment.