about summary refs log tree commit diff
path: root/src/test/ui/span
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-02-20 22:46:51 -0800
committerEsteban Küber <esteban@kuber.com.ar>2018-02-20 22:46:51 -0800
commit20bc72e693372940183e97a32e7d07d2f9180182 (patch)
tree1fc73a31b4bb40107398bfa52d9b712f7c8a20f4 /src/test/ui/span
parent1670a532dd769763f1d6ad9e5d624ec31361a098 (diff)
downloadrust-20bc72e693372940183e97a32e7d07d2f9180182.tar.gz
rust-20bc72e693372940183e97a32e7d07d2f9180182.zip
Handle custom diagnostic for `&str + String`
Diffstat (limited to 'src/test/ui/span')
-rw-r--r--src/test/ui/span/issue-39018.rs3
-rw-r--r--src/test/ui/span/issue-39018.stderr16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/test/ui/span/issue-39018.rs b/src/test/ui/span/issue-39018.rs
index 4c9d10ba46b..7b3288fd29c 100644
--- a/src/test/ui/span/issue-39018.rs
+++ b/src/test/ui/span/issue-39018.rs
@@ -17,6 +17,9 @@ pub fn main() {
     // that won't output for the above string concatenation
     let y = World::Hello + World::Goodbye;
     //~^ ERROR cannot be applied to type
+
+    let x = "Hello " + "World!".to_owned();
+    //~^ ERROR cannot be applied to type
 }
 
 enum World {
diff --git a/src/test/ui/span/issue-39018.stderr b/src/test/ui/span/issue-39018.stderr
index db662a1df59..70f8ecf42cb 100644
--- a/src/test/ui/span/issue-39018.stderr
+++ b/src/test/ui/span/issue-39018.stderr
@@ -16,5 +16,19 @@ error[E0369]: binary operation `+` cannot be applied to type `World`
    |
    = note: an implementation of `std::ops::Add` might be missing for `World`
 
-error: aborting due to 2 previous errors
+error[E0369]: binary operation `+` cannot be applied to type `&str`
+  --> $DIR/issue-39018.rs:21:13
+   |
+21 |     let x = "Hello " + "World!".to_owned();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `+` can't be used to concatenate a `&str` with a `String`
+help: `to_owned()` can be used to create an owned `String` from a string reference. 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
+   |
+21 |     let x = "Hello ".to_owned() + "World!".to_owned();
+   |             ^^^^^^^^^^^^^^^^^^^
+help: you also need to borrow the `String` on the right to get a `&str`
+   |
+21 |     let x = "Hello " + &"World!".to_owned();
+   |                        ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors