From 7507fb6306d540a6f07f6f325d25925311b037a2 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Tue, 18 Jan 2022 16:32:58 -0800 Subject: [PATCH] Shorten and improve messages --- compiler/rustc_typeck/src/check/op.rs | 8 +- src/test/ui/issues/issue-47377.stderr | 15 +-- src/test/ui/issues/issue-47380.stderr | 15 +-- src/test/ui/span/issue-39018.stderr | 98 +++++++------------ .../ui/str/str-concat-on-double-ref.stderr | 15 +-- ...non-1-width-unicode-multiline-label.stderr | 19 ++-- 6 files changed, 58 insertions(+), 112 deletions(-) diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index c7bb66f339c..82da66c09e4 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -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![ diff --git a/src/test/ui/issues/issue-47377.stderr b/src/test/ui/issues/issue-47377.stderr index 97fbb53bd02..e4b907070a6 100644 --- a/src/test/ui/issues/issue-47377.stderr +++ b/src/test/ui/issues/issue-47377.stderr @@ -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 diff --git a/src/test/ui/issues/issue-47380.stderr b/src/test/ui/issues/issue-47380.stderr index 7a73d41a035..7ad369fcd0e 100644 --- a/src/test/ui/issues/issue-47380.stderr +++ b/src/test/ui/issues/issue-47380.stderr @@ -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 diff --git a/src/test/ui/span/issue-39018.stderr b/src/test/ui/span/issue-39018.stderr index 9e466f3a9a0..9cfb015e753 100644 --- a/src/test/ui/span/issue-39018.stderr +++ b/src/test/ui/span/issue-39018.stderr @@ -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 diff --git a/src/test/ui/str/str-concat-on-double-ref.stderr b/src/test/ui/str/str-concat-on-double-ref.stderr index d239ec0d9fc..251bc7ac0ea 100644 --- a/src/test/ui/str/str-concat-on-double-ref.stderr +++ b/src/test/ui/str/str-concat-on-double-ref.stderr @@ -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 diff --git a/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr b/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr index 55e993db3d3..a97ecc4ce15 100644 --- a/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr +++ b/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr @@ -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