is_assign,
) {
(Ok(l), Ok(r), false) => {
+ let to_string = if l.starts_with("&") {
+ // let a = String::new(); let b = String::new();
+ // let _ = &a + b;
+ format!("{}", &l[1..])
+ } else {
+ format!("{}.to_owned()", l)
+ };
err.multipart_suggestion(
msg,
vec![
- (lhs_expr.span, format!("{}.to_owned()", l)),
+ (lhs_expr.span, to_string),
(rhs_expr.span, format!("&{}", r)),
],
Applicability::MachineApplicable,
| &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 _ = &a.to_owned() + &b;
- | ^^^^^^^^^^^^^ ^^
+LL | let _ = a + &b;
+ | ^ ^^
error[E0308]: mismatched types
--> $DIR/issue-39018.rs:29:17