diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2018-02-24 15:52:09 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-24 15:52:09 -0800 |
| commit | 7738eb4ddb3d17b2958c3844d4580672ef422372 (patch) | |
| tree | fcf617f5b7d792778099f682fa83b5a129f18b2b /src/test/ui/span | |
| parent | d45c4a6d27773b06efb2ea8cae4983cbdf0cfc34 (diff) | |
| parent | 20bc72e693372940183e97a32e7d07d2f9180182 (diff) | |
| download | rust-7738eb4ddb3d17b2958c3844d4580672ef422372.tar.gz rust-7738eb4ddb3d17b2958c3844d4580672ef422372.zip | |
Rollup merge of #48392 - estebank:string, r=petrochenkov
Handle custom diagnostic for `&str + String` Now all of `&str + &str`, `&str + String` and `String + String` have relevant diagnostic output.
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 |
