diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-03-27 14:39:44 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-04-25 11:07:42 +0200 |
| commit | ca701d7aeb6cd16a6c1fe94230918535e9e3164d (patch) | |
| tree | f23aabaa729355a0317e492c31f8ac1b89eeba63 | |
| parent | b857a1a39fc29b8f241d8aa4c859ff4105cb160c (diff) | |
| download | rust-ca701d7aeb6cd16a6c1fe94230918535e9e3164d.tar.gz rust-ca701d7aeb6cd16a6c1fe94230918535e9e3164d.zip | |
Simplify a suggestion for str addition
| -rw-r--r-- | src/librustc_typeck/check/op.rs | 17 | ||||
| -rw-r--r-- | src/test/ui/span/issue-39018.stderr | 4 |
2 files changed, 8 insertions, 13 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 42296006b79..6968a37361a 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -244,8 +244,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let Some(missing_trait) = missing_trait { if missing_trait == "std::ops::Add" && - self.check_str_addition(expr, lhs_expr, lhs_ty, - rhs_expr, rhs_ty, &mut err) { + self.check_str_addition(lhs_expr, lhs_ty, + rhs_expr, rhs_ty_var, &mut err) { // This has nothing here because it means we did string // concatenation (e.g. "Hello " + "World!"). This means // we don't want the note in the else clause to be emitted @@ -266,7 +266,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } fn check_str_addition(&self, - expr: &'gcx hir::Expr, lhs_expr: &'gcx hir::Expr, lhs_ty: Ty<'tcx>, rhs_expr: &'gcx hir::Expr, @@ -281,18 +280,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err.note("`+` can't be used to concatenate two `&str` strings"); let codemap = self.tcx.sess.codemap(); let suggestion = - match (codemap.span_to_snippet(lhs_expr.span), - codemap.span_to_snippet(rhs_expr.span)) { - (Ok(lstring), Ok(rstring)) => - format!("{}.to_owned() + {}", lstring, rstring), + match codemap.span_to_snippet(lhs_expr.span) { + Ok(lstring) => format!("{}.to_owned()", lstring), _ => format!("<expression>") }; - err.span_suggestion(expr.span, - &format!("to_owned() can be used to create an owned `String` \ + err.span_suggestion(lhs_expr.span, + &format!("`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."), suggestion); + requires ownership of the string on the left:"), suggestion); is_string_addition = true; } diff --git a/src/test/ui/span/issue-39018.stderr b/src/test/ui/span/issue-39018.stderr index 46d39dac5ac..b588238202e 100644 --- a/src/test/ui/span/issue-39018.stderr +++ b/src/test/ui/span/issue-39018.stderr @@ -2,9 +2,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&'static str` --> $DIR/issue-39018.rs:12:13 | 12 | let x = "Hello " + "World!"; - | ^^^^^^^^----------- - | | - | 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. `"Hello ".to_owned() + "World!"` + | ^^^^^^^^ `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: `"Hello ".to_owned()` | = note: `+` can't be used to concatenate two `&str` strings |
