From 7c4eca06871f83257f9f503c3a91a8946026133a Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Tue, 18 Jan 2022 16:38:06 -0800 Subject: [PATCH] Make suggestions verbose --- compiler/rustc_typeck/src/check/op.rs | 10 ++- src/test/ui/issues/issue-47377.stderr | 11 +-- src/test/ui/issues/issue-47380.stderr | 11 +-- src/test/ui/span/issue-39018.stderr | 72 ++++++++++++------- .../ui/str/str-concat-on-double-ref.stderr | 11 +-- ...non-1-width-unicode-multiline-label.stderr | 15 ++-- 6 files changed, 84 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 82da66c09e4de..81662b752b7b0 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -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(), @@ -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); diff --git a/src/test/ui/issues/issue-47377.stderr b/src/test/ui/issues/issue-47377.stderr index e4b907070a681..4f0fd948e7604 100644 --- a/src/test/ui/issues/issue-47377.stderr +++ b/src/test/ui/issues/issue-47377.stderr @@ -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 diff --git a/src/test/ui/issues/issue-47380.stderr b/src/test/ui/issues/issue-47380.stderr index 7ad369fcd0e74..b04ac5536c41f 100644 --- a/src/test/ui/issues/issue-47380.stderr +++ b/src/test/ui/issues/issue-47380.stderr @@ -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 diff --git a/src/test/ui/span/issue-39018.stderr b/src/test/ui/span/issue-39018.stderr index 9cfb015e753f8..e2e7ce1ed18e7 100644 --- a/src/test/ui/span/issue-39018.stderr +++ b/src/test/ui/span/issue-39018.stderr @@ -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 @@ -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 @@ -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 @@ -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 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 251bc7ac0ead7..bd354679f7888 100644 --- a/src/test/ui/str/str-concat-on-double-ref.stderr +++ b/src/test/ui/str/str-concat-on-double-ref.stderr @@ -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 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 a97ecc4ce1591..bf277362dbab2 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,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