-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Handle more string addition cases with appropriate suggestions #60901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,145 @@ help: `to_owned()` can be used to create an owned `String` from a string referen | |
LL | let x = "Hello ".to_owned() + &"World!".to_owned(); | ||
| ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
error[E0369]: binary operation `+` cannot be applied to type `&std::string::String` | ||
--> $DIR/issue-39018.rs:26:16 | ||
| | ||
LL | let _ = &a + &b; | ||
| -- ^ -- &std::string::String | ||
| | | | ||
| | `+` can't be used to concatenate two `&str` strings | ||
| &std::string::String | ||
help: 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel a bit of information overload here; there's too much information packed in too little space. I'd consider giving things more "air" by e.g. moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, it would have been nice to have a method on I do agree colors make it less of a problem, but that still makes me somewhat dizzy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, these look much better when the text is much shorter than this. What we could do is make the help text short and only say what it should do (fix the types of the binop), and have a separate note talk about this, which would introduce a newline and look like this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems better, yeah. |
||
| | ||
LL | let _ = a + &b; | ||
| ^ | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&std::string::String` | ||
--> $DIR/issue-39018.rs:27:16 | ||
| | ||
LL | let _ = &a + b; | ||
| ---^-- | ||
| | | | ||
| | std::string::String | ||
| &std::string::String | ||
| `+` 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 | ||
| | ||
LL | let _ = &a.to_owned() + &b; | ||
| ^^^^^^^^^^^^^ ^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-39018.rs:29:17 | ||
| | ||
LL | let _ = a + b; | ||
| ^ | ||
| | | ||
| expected &str, found struct `std::string::String` | ||
| help: consider borrowing here: `&b` | ||
| | ||
= note: expected type `&str` | ||
found type `std::string::String` | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&std::string::String` | ||
--> $DIR/issue-39018.rs:30:15 | ||
| | ||
LL | let _ = e + b; | ||
| --^-- | ||
| | | | ||
| | std::string::String | ||
| &std::string::String | ||
| `+` can't be used to concatenate a `&str` with a `String` | ||
estebank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
| | ||
LL | let _ = e.to_owned() + &b; | ||
| ^^^^^^^^^^^^ ^^ | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&std::string::String` | ||
--> $DIR/issue-39018.rs:31:15 | ||
| | ||
LL | let _ = e + &b; | ||
| - ^ -- &std::string::String | ||
| | | | ||
| | `+` can't be used to concatenate two `&str` strings | ||
| &std::string::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 | ||
| | ||
LL | let _ = e.to_owned() + &b; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&std::string::String` | ||
--> $DIR/issue-39018.rs:32:15 | ||
| | ||
LL | let _ = e + d; | ||
| - ^ - &str | ||
| | | | ||
| | `+` can't be used to concatenate two `&str` strings | ||
| &std::string::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 | ||
| | ||
LL | let _ = e.to_owned() + d; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&std::string::String` | ||
--> $DIR/issue-39018.rs:33:15 | ||
| | ||
LL | let _ = e + &d; | ||
| - ^ -- &&str | ||
| | | | ||
| | `+` can't be used to concatenate two `&str` strings | ||
| &std::string::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 | ||
| | ||
LL | let _ = e.to_owned() + &d; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&&str` | ||
--> $DIR/issue-39018.rs:34:16 | ||
| | ||
LL | let _ = &c + &d; | ||
| -- ^ -- &&str | ||
| | | ||
| &&str | ||
| | ||
= note: an implementation of `std::ops::Add` might be missing for `&&str` | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&&str` | ||
--> $DIR/issue-39018.rs:35:16 | ||
| | ||
LL | let _ = &c + d; | ||
| -- ^ - &str | ||
| | | ||
| &&str | ||
| | ||
= note: an implementation of `std::ops::Add` might be missing for `&&str` | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&str` | ||
--> $DIR/issue-39018.rs:36:15 | ||
| | ||
LL | let _ = c + &d; | ||
| - ^ -- &&str | ||
| | | | ||
| | `+` can't be used to concatenate two `&str` strings | ||
| &str | ||
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 | ||
| | ||
LL | let _ = c.to_owned() + &d; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0369]: binary operation `+` cannot be applied to type `&str` | ||
--> $DIR/issue-39018.rs:37:15 | ||
| | ||
LL | let _ = c + d; | ||
| - ^ - &str | ||
| | | | ||
| | `+` can't be used to concatenate two `&str` strings | ||
| &str | ||
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 | ||
| | ||
LL | let _ = c.to_owned() + d; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 14 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0369`. | ||
Some errors have detailed explanations: E0308, E0369. | ||
For more information about an error, try `rustc --explain E0308`. |
Uh oh!
There was an error while loading. Please reload this page.