about summary refs log tree commit diff
path: root/src/test/parse-fail
diff options
context:
space:
mode:
authorMichael Gattozzi <mgattozzi@gmail.com>2017-01-14 15:25:33 -0500
committerMichael Gattozzi <mgattozzi@gmail.com>2017-01-28 17:26:27 -0500
commitb54f593cffc40e9d07650b36629e60c48da6b11d (patch)
treeea53cd7052a5368be161eff34c03ff6abb496e5f /src/test/parse-fail
parent0f8a296475d8bc27dfa48ec1053cec8fa2f73673 (diff)
downloadrust-b54f593cffc40e9d07650b36629e60c48da6b11d.tar.gz
rust-b54f593cffc40e9d07650b36629e60c48da6b11d.zip
Add clearer error message using `&str + &str`
This is the first part of #39018. One of the common things for new users
coming from more dynamic languages like JavaScript, Python or Ruby is to
use `+` to concatenate strings. However, this doesn't work that way in
Rust unless the first type is a `String`. This commit adds a check for
this use case and outputs a new error as well as a suggestion to guide
the user towards the desired behavior. It also adds a new test case to
test the output of the error.
Diffstat (limited to 'src/test/parse-fail')
-rw-r--r--src/test/parse-fail/issue-39018.stderr28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/parse-fail/issue-39018.stderr b/src/test/parse-fail/issue-39018.stderr
new file mode 100644
index 00000000000..ee1a32c4c16
--- /dev/null
+++ b/src/test/parse-fail/issue-39018.stderr
@@ -0,0 +1,28 @@
+error[E0369]: binary operation `+` cannot be applied to type `&'static str`
+ --> src/test/ui/span/issue-39018.rs:2:13
+  |
+2 |     let x = "Hello " + "World!";
+  |             ^^^^^^^^
+  |
+note: `+` can't be used to concatenate two `&str` strings
+ --> src/test/ui/span/issue-39018.rs:2:13
+  |
+2 |     let x = "Hello " + "World!";
+  |             ^^^^^^^^
+help: to_owned() can be used to create an owned `String` from a string reference. This allows concatenation since the `String` is owned.
+  |     let x = "Hello ".to_owned() + "World!";
+
+error[E0369]: binary operation `+` cannot be applied to type `World`
+ --> src/test/ui/span/issue-39018.rs:7:13
+  |
+7 |     let y = World::Hello + World::Goodbye;
+  |             ^^^^^^^^^^^^
+  |
+note: an implementation of `std::ops::Add` might be missing for `World`
+ --> src/test/ui/span/issue-39018.rs:7:13
+  |
+7 |     let y = World::Hello + World::Goodbye;
+  |             ^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+