Fix binop span
This commit is contained in:
parent
234adf84bd
commit
2cb91816f2
@ -305,8 +305,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
};
|
||||
if let Some(missing_trait) = missing_trait {
|
||||
if op.node == hir::BinOpKind::Add &&
|
||||
self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty,
|
||||
rhs_ty, &mut err, true, op) {
|
||||
self.check_str_addition(
|
||||
lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, true, op) {
|
||||
// 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
|
||||
@ -400,8 +400,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
};
|
||||
if let Some(missing_trait) = missing_trait {
|
||||
if op.node == hir::BinOpKind::Add &&
|
||||
self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty,
|
||||
rhs_ty, &mut err, false, op) {
|
||||
self.check_str_addition(
|
||||
lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, false, op) {
|
||||
// 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
|
||||
@ -509,7 +509,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
/// to print the normal "implementation of `std::ops::Add` might be missing" note
|
||||
fn check_str_addition(
|
||||
&self,
|
||||
expr: &'gcx hir::Expr,
|
||||
lhs_expr: &'gcx hir::Expr,
|
||||
rhs_expr: &'gcx hir::Expr,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
@ -537,7 +536,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
&format!("{:?}", rhs_ty) == "&&str"
|
||||
) =>
|
||||
{
|
||||
if !is_assign {
|
||||
if !is_assign { // Do not supply this message if `&str += &str`
|
||||
err.span_label(
|
||||
op.span,
|
||||
"`+` can't be used to concatenate two `&str` strings",
|
||||
@ -570,8 +569,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
if (l_ty.sty == Str || &format!("{:?}", l_ty) == "std::string::String") &&
|
||||
&format!("{:?}", rhs_ty) == "std::string::String" =>
|
||||
{
|
||||
err.span_label(expr.span,
|
||||
"`+` can't be used to concatenate a `&str` with a `String`");
|
||||
err.span_label(
|
||||
op.span,
|
||||
"`+` can't be used to concatenate a `&str` with a `String`",
|
||||
);
|
||||
match (
|
||||
source_map.span_to_snippet(lhs_expr.span),
|
||||
source_map.span_to_snippet(rhs_expr.span),
|
||||
|
@ -3540,8 +3540,7 @@ impl<'a> Parser<'a> {
|
||||
let binary = self.mk_binary(source_map::respan(cur_op_span, ast_op), lhs, rhs);
|
||||
self.mk_expr(span, binary, ThinVec::new())
|
||||
}
|
||||
AssocOp::Assign =>
|
||||
self.mk_expr(span, ExprKind::Assign(lhs, rhs), ThinVec::new()),
|
||||
AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs), ThinVec::new()),
|
||||
AssocOp::ObsoleteInPlace =>
|
||||
self.mk_expr(span, ExprKind::ObsoleteInPlace(lhs, rhs), ThinVec::new()),
|
||||
AssocOp::AssignOp(k) => {
|
||||
|
@ -25,11 +25,10 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
|
||||
--> $DIR/issue-39018.rs:11:22
|
||||
|
|
||||
LL | let x = "Hello " + "World!".to_owned();
|
||||
| ---------^--------------------
|
||||
| | |
|
||||
| | std::string::String
|
||||
| -------- ^ ------------------- std::string::String
|
||||
| | |
|
||||
| | `+` can't be used to concatenate a `&str` with a `String`
|
||||
| &str
|
||||
| `+` can't be used to concatenate a `&str` with a `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 x = "Hello ".to_owned() + &"World!".to_owned();
|
||||
@ -52,11 +51,10 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
|
||||
--> $DIR/issue-39018.rs:27:16
|
||||
|
|
||||
LL | let _ = &a + b;
|
||||
| ---^--
|
||||
| | |
|
||||
| | std::string::String
|
||||
| -- ^ - std::string::String
|
||||
| | |
|
||||
| | `+` can't be used to concatenate a `&str` with a `String`
|
||||
| &std::string::String
|
||||
| `+` can't be used to concatenate a `&str` with a `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;
|
||||
@ -78,11 +76,10 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
|
||||
--> $DIR/issue-39018.rs:30:15
|
||||
|
|
||||
LL | let _ = e + b;
|
||||
| --^--
|
||||
| | |
|
||||
| | std::string::String
|
||||
| - ^ - std::string::String
|
||||
| | |
|
||||
| | `+` can't be used to concatenate a `&str` with a `String`
|
||||
| &std::string::String
|
||||
| `+` can't be used to concatenate a `&str` with a `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 _ = e.to_owned() + &b;
|
||||
|
Loading…
x
Reference in New Issue
Block a user