Account for UnOps in borrowck message
This commit is contained in:
parent
b367c25367
commit
0953608deb
4 changed files with 19 additions and 4 deletions
|
@ -16,6 +16,9 @@ borrowck_borrow_due_to_use_closure =
|
||||||
borrowck_borrow_due_to_use_coroutine =
|
borrowck_borrow_due_to_use_coroutine =
|
||||||
borrow occurs due to use in coroutine
|
borrow occurs due to use in coroutine
|
||||||
|
|
||||||
|
borrowck_calling_operator_moves =
|
||||||
|
calling this operator moves the value
|
||||||
|
|
||||||
borrowck_calling_operator_moves_lhs =
|
borrowck_calling_operator_moves_lhs =
|
||||||
calling this operator moves the left-hand side
|
calling this operator moves the left-hand side
|
||||||
|
|
||||||
|
|
|
@ -1050,7 +1050,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
);
|
);
|
||||||
err.subdiagnostic(self.dcx(), CaptureReasonNote::FnOnceMoveInCall { var_span });
|
err.subdiagnostic(self.dcx(), CaptureReasonNote::FnOnceMoveInCall { var_span });
|
||||||
}
|
}
|
||||||
CallKind::Operator { self_arg, .. } => {
|
CallKind::Operator { self_arg, trait_id, .. } => {
|
||||||
let self_arg = self_arg.unwrap();
|
let self_arg = self_arg.unwrap();
|
||||||
err.subdiagnostic(
|
err.subdiagnostic(
|
||||||
self.dcx(),
|
self.dcx(),
|
||||||
|
@ -1062,9 +1062,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if self.fn_self_span_reported.insert(fn_span) {
|
if self.fn_self_span_reported.insert(fn_span) {
|
||||||
|
let lang = self.infcx.tcx.lang_items();
|
||||||
err.subdiagnostic(
|
err.subdiagnostic(
|
||||||
self.dcx(),
|
self.dcx(),
|
||||||
CaptureReasonNote::LhsMoveByOperator { span: self_arg.span },
|
if [lang.not_trait(), lang.deref_trait(), lang.neg_trait()]
|
||||||
|
.contains(&Some(trait_id))
|
||||||
|
{
|
||||||
|
CaptureReasonNote::UnOpMoveByOperator { span: self_arg.span }
|
||||||
|
} else {
|
||||||
|
CaptureReasonNote::LhsMoveByOperator { span: self_arg.span }
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,6 +368,11 @@ pub(crate) enum CaptureReasonNote {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
|
#[note(borrowck_calling_operator_moves)]
|
||||||
|
UnOpMoveByOperator {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
#[note(borrowck_calling_operator_moves_lhs)]
|
#[note(borrowck_calling_operator_moves_lhs)]
|
||||||
LhsMoveByOperator {
|
LhsMoveByOperator {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
|
|
@ -9,7 +9,7 @@ LL |
|
||||||
LL | x.clone();
|
LL | x.clone();
|
||||||
| ^ value borrowed here after move
|
| ^ value borrowed here after move
|
||||||
|
|
|
|
||||||
note: calling this operator moves the left-hand side
|
note: calling this operator moves the value
|
||||||
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
|
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
|
||||||
help: consider cloning the value if the performance cost is acceptable
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
|
||||||
|
@ -57,7 +57,7 @@ LL | !*m;
|
||||||
| |move occurs because `*m` has type `T`, which does not implement the `Copy` trait
|
| |move occurs because `*m` has type `T`, which does not implement the `Copy` trait
|
||||||
| `*m` moved due to usage in operator
|
| `*m` moved due to usage in operator
|
||||||
|
|
|
|
||||||
note: calling this operator moves the left-hand side
|
note: calling this operator moves the value
|
||||||
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
|
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
|
||||||
|
|
||||||
error[E0507]: cannot move out of `*n` which is behind a shared reference
|
error[E0507]: cannot move out of `*n` which is behind a shared reference
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue