diff options
| author | Michael Gattozzi <mgattozzi@gmail.com> | 2017-01-14 15:25:33 -0500 |
|---|---|---|
| committer | Michael Gattozzi <mgattozzi@gmail.com> | 2017-01-28 17:26:27 -0500 |
| commit | b54f593cffc40e9d07650b36629e60c48da6b11d (patch) | |
| tree | ea53cd7052a5368be161eff34c03ff6abb496e5f /src/test/parse-fail | |
| parent | 0f8a296475d8bc27dfa48ec1053cec8fa2f73673 (diff) | |
| download | rust-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.stderr | 28 |
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 + |
