Skip to content

Wrong suggestion for &str += &str #52410

Closed
@estebank

Description

@estebank

Current output for &str += &str:

error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
  --> $DIR/issue-10401.rs:13:5
   |
LL |     a += { "b" };
   |     -^^^^^^^^^^^
   |     |
   |     cannot use `+=` on type `&str`
   |     `+` can't be used to concatenate two `&str` strings
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 |     a.to_owned() += { "b" };
   |     ^^^^^^^^^^^^

It should at the very least not provide the incorrect suggestion, probably have custom help explaining that a should be a String, best would be to suggest new valid code (but it's probably too complex a case to do).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions