2

Improve string concatenation suggestion by camelid · Pull Request #92843 · rust-...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/92843
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Member

camelid commented 17 days ago

edited

Before:

error[E0369]: cannot add `&str` to `&str`
 --> file.rs:2:22
  |
2 |     let _x = "hello" + " world";
  |              ------- ^ -------- &str
  |              |       |
  |              |       `+` cannot 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
  |
2 |     let _x = "hello".to_owned() + " world";
  |              ~~~~~~~~~~~~~~~~~~

After:

error[E0369]: cannot add `&str` to `&str`
 --> file.rs:2:22
  |
2 |     let _x = "hello" + " world";
  |              ------- ^ -------- &str
  |              |       |
  |              |       `+` cannot be used to concatenate two `&str` strings
  |              &str
  |
  = note: string concatenation requires an owned `String` on the left
help: create an owned `String` from a string reference
  |
2 |     let _x = "hello".to_owned() + " world";
  |                     +++++++++++

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK