diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-02-20 22:46:51 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-02-20 22:46:51 -0800 |
| commit | 20bc72e693372940183e97a32e7d07d2f9180182 (patch) | |
| tree | 1fc73a31b4bb40107398bfa52d9b712f7c8a20f4 /src/test/ui/span | |
| parent | 1670a532dd769763f1d6ad9e5d624ec31361a098 (diff) | |
| download | rust-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.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/span/issue-39018.stderr | 16 |
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 |
