Skip to content

Commit

Permalink
Account for &String + String
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed May 17, 2019
1 parent ee0bf5e commit 8895fb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/span/issue-39018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ LL | let _ = &a + b;
| &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
Expand Down

0 comments on commit 8895fb9

Please sign in to comment.