Shorten and improve messages
This commit is contained in:
parent
6e42bc378f
commit
7507fb6306
@ -549,11 +549,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
is_assign: IsAssign,
|
||||
op: hir::BinOp,
|
||||
) -> bool {
|
||||
let str_concat_note = "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.";
|
||||
let str_concat_note = "string concatenation requires an owned `String` on the left";
|
||||
let rm_borrow_msg = "remove the borrow to obtain an owned `String`";
|
||||
let to_owned_msg = "use `to_owned()` to create an owned `String` from a string reference";
|
||||
let to_owned_msg = "create an owned `String` from a string reference";
|
||||
|
||||
let string_type = self.tcx.get_diagnostic_item(sym::String);
|
||||
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.";
|
||||
sugg_msg = "remove the borrow on the left and add one on the right";
|
||||
(lhs_expr.span.until(lhs_inner_expr.span), "".to_owned())
|
||||
} else {
|
||||
sugg_msg = "call `.to_owned()` on the left and add a borrow on the right";
|
||||
sugg_msg = "create an owned `String` on the left and add a borrow on the right";
|
||||
(lhs_expr.span.shrink_to_hi(), ".to_owned()".to_owned())
|
||||
};
|
||||
let suggestions = vec![
|
||||
|
@ -2,18 +2,13 @@ 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
|
||||
| --^ ---------- &str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &str
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _a = b.to_owned() + ", World!";
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,18 +2,13 @@ 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
|
||||
| --^ ---------- &str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &str
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,18 +2,13 @@ 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
|
||||
| ---------^ -------- &str
|
||||
| | ||
|
||||
| | |`+` cannot be used to concatenate two `&str` strings
|
||||
| | help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &str
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let x = "Hello ".to_owned() + "World!";
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error[E0369]: cannot add `World` to `World`
|
||||
--> $DIR/issue-39018.rs:8:26
|
||||
@ -49,7 +44,7 @@ LL | let x = "Hello " + "World!".to_owned();
|
||||
| | `+` cannot be used to concatenate a `&str` with a `String`
|
||||
| &str
|
||||
|
|
||||
help: call `.to_owned()` on the left and add a borrow on the right
|
||||
help: create an owned `String` on the left and add a borrow on the right
|
||||
|
|
||||
LL | let x = "Hello ".to_owned() + &"World!".to_owned();
|
||||
| +++++++++++ +
|
||||
@ -64,9 +59,7 @@ LL | let _ = &a + &b;
|
||||
| &String
|
||||
| help: remove the borrow to obtain an owned `String`
|
||||
|
|
||||
= note: 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
|
||||
|
||||
error[E0369]: cannot add `String` to `&String`
|
||||
--> $DIR/issue-39018.rs:27:16
|
||||
@ -101,7 +94,7 @@ LL | let _ = e + b;
|
||||
| | `+` cannot be used to concatenate a `&str` with a `String`
|
||||
| &String
|
||||
|
|
||||
help: call `.to_owned()` on the left and add a borrow on the right
|
||||
help: create an owned `String` on the left and add a borrow on the right
|
||||
|
|
||||
LL | let _ = e.to_owned() + &b;
|
||||
| +++++++++++ +
|
||||
@ -110,52 +103,37 @@ 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
|
||||
| --^ -- &String
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &String
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = e.to_owned() + &b;
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
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
|
||||
| --^ - &str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &String
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = e.to_owned() + d;
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
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
|
||||
| --^ -- &&str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &String
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = e.to_owned() + &d;
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error[E0369]: cannot add `&&str` to `&&str`
|
||||
--> $DIR/issue-39018.rs:34:16
|
||||
@ -177,35 +155,25 @@ 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
|
||||
| --^ -- &&str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &str
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = c.to_owned() + &d;
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
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
|
||||
| --^ - &str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &str
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = c.to_owned() + d;
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
@ -2,18 +2,13 @@ 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
|
||||
| --^ - &str
|
||||
| |||
|
||||
| ||`+` cannot be used to concatenate two `&str` strings
|
||||
| |help: create an owned `String` from a string reference: `.to_owned()`
|
||||
| &String
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let c = a.to_owned() + b;
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,19 +1,14 @@
|
||||
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
|
||||
| &str
|
||||
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
|
||||
|
|
||||
= note: 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: use `to_owned()` to create an owned `String` from a string reference
|
||||
|
|
||||
LL | let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༘༙༚༛༜༝༞༟༠༡༢༣༤༥༦༧༨༩༪༫༬༭༮༯༰༱༲༳༴༵༶༷༸༹༺༻༼༽༾༿ཀཁགགྷངཅཆཇཉཊཋཌཌྷཎཏཐདདྷནཔཕབབྷམཙཚཛཛྷཝཞཟའཡརལཤཥསཧཨཀྵཪཫཬཱཱཱིིུུྲྀཷླྀཹེཻོཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun.to_owned() + " really fun!";
|
||||
| +++++++++++
|
||||
= note: string concatenation requires an owned `String` on the left
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user