Skip to content

Commit

Permalink
Stop pointing to operators if their libcore method source is not avai…
Browse files Browse the repository at this point in the history
…lable
  • Loading branch information
oli-obk committed Dec 13, 2022
1 parent 59554a2 commit 6984085
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 70 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
if self.fn_self_span_reported.insert(fn_span) {
err.span_note(
// Check whether the source is accessible
if self.infcx.tcx.sess.source_map().is_span_accessible(self_arg.span) {
self_arg.span
} else {
fn_call_span
},
self_arg.span,
"calling this operator moves the left-hand side",
);
}
Expand Down
50 changes: 10 additions & 40 deletions src/test/ui/binop/binop-consume-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:6:5
|
LL | lhs + rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: consider further restricting this bound
|
LL | fn add<A: Add<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -45,10 +42,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:12:5
|
LL | lhs - rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: consider further restricting this bound
|
LL | fn sub<A: Sub<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -81,10 +75,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:18:5
|
LL | lhs * rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: consider further restricting this bound
|
LL | fn mul<A: Mul<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -117,10 +108,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:24:5
|
LL | lhs / rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: consider further restricting this bound
|
LL | fn div<A: Div<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -153,10 +141,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:30:5
|
LL | lhs % rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: consider further restricting this bound
|
LL | fn rem<A: Rem<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -189,10 +174,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:36:5
|
LL | lhs & rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
help: consider further restricting this bound
|
LL | fn bitand<A: BitAnd<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -225,10 +207,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:42:5
|
LL | lhs | rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
help: consider further restricting this bound
|
LL | fn bitor<A: BitOr<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -261,10 +240,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:48:5
|
LL | lhs ^ rhs;
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
help: consider further restricting this bound
|
LL | fn bitxor<A: BitXor<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -297,10 +273,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:54:5
|
LL | lhs << rhs;
| ^^^^^^^^^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
help: consider further restricting this bound
|
LL | fn shl<A: Shl<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down Expand Up @@ -333,10 +306,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/binop-consume-args.rs:60:5
|
LL | lhs >> rhs;
| ^^^^^^^^^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
help: consider further restricting this bound
|
LL | fn shr<A: Shr<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
Expand Down
14 changes: 2 additions & 12 deletions src/test/ui/binop/binop-move-semantics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ LL | | x;
| `x` moved due to usage in operator
|
note: calling this operator moves the left-hand side
--> $DIR/binop-move-semantics.rs:6:5
|
LL | / x
LL | | +
LL | | x;
| |_____^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: consider further restricting this bound
|
LL | fn double_move<T: Add<Output=()> + Copy>(x: T) {
Expand Down Expand Up @@ -79,12 +74,7 @@ LL | | *n;
| |______- `*m` moved due to usage in operator
|
note: calling this operator moves the left-hand side
--> $DIR/binop-move-semantics.rs:30:5
|
LL | / *m
LL | | +
LL | | *n;
| |______^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL

error[E0507]: cannot move out of `*n` which is behind a shared reference
--> $DIR/binop-move-semantics.rs:32:5
Expand Down
5 changes: 1 addition & 4 deletions src/test/ui/moves/move-fn-self-receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ LL | foo_add;
| ^^^^^^^ value used here after move
|
note: calling this operator moves the left-hand side
--> $DIR/move-fn-self-receiver.rs:58:5
|
LL | foo_add + Foo;
| ^^^^^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL

error[E0382]: use of moved value: `implicit_into_iter`
--> $DIR/move-fn-self-receiver.rs:63:5
Expand Down
10 changes: 2 additions & 8 deletions src/test/ui/unop-move-semantics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ LL | x.clone();
| ^^^^^^^^^ value borrowed here after move
|
note: calling this operator moves the left-hand side
--> $DIR/unop-move-semantics.rs:6:5
|
LL | !x;
| ^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
help: consider cloning the value if the performance cost is acceptable
|
LL | !x.clone();
Expand Down Expand Up @@ -56,10 +53,7 @@ LL | !*m;
| `*m` moved due to usage in operator
|
note: calling this operator moves the left-hand side
--> $DIR/unop-move-semantics.rs:24:5
|
LL | !*m;
| ^^^
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL

error[E0507]: cannot move out of `*n` which is behind a shared reference
--> $DIR/unop-move-semantics.rs:26:6
Expand Down

0 comments on commit 6984085

Please sign in to comment.