Rollup merge of #153549 - DanielEScherzer:test-references-binop, r=ehuss

tests/ui/binop: add annotations for reference rules
This commit is contained in:
Jonathan Brouwer
2026-03-10 22:46:56 +01:00
committed by GitHub
7 changed files with 62 additions and 53 deletions
+1
View File
@@ -1,4 +1,5 @@
//@ run-pass
//@ reference: expr.arith-logic.behavior
#![allow(unused_imports)]
#![deny(unused_assignments)]
@@ -1,4 +1,7 @@
//@ run-pass
//@ reference: expr.arith-logic.syntax
//@ reference: patterns.literal.syntax
//@ reference: patterns.literal.intro
// Check that issue #954 stays fixed
+1
View File
@@ -1,3 +1,4 @@
//@ reference: expr.arith-logic.behavior
// Test that binary operators consume their arguments
use std::ops::{Add, Sub, Mul, Div, Rem, BitAnd, BitXor, BitOr, Shl, Shr};
+40 -40
View File
@@ -1,5 +1,5 @@
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:7:10
--> $DIR/binop-consume-args.rs:8:10
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -9,7 +9,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:5:8
--> $DIR/binop-consume-args.rs:6:8
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -23,7 +23,7 @@ LL | fn add<A: Add<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:8:10
--> $DIR/binop-consume-args.rs:9:10
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -34,7 +34,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:5:30
--> $DIR/binop-consume-args.rs:6:30
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -46,7 +46,7 @@ LL | fn add<A: Add<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:13:10
--> $DIR/binop-consume-args.rs:14:10
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -56,7 +56,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:11:8
--> $DIR/binop-consume-args.rs:12:8
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -70,7 +70,7 @@ LL | fn sub<A: Sub<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:14:10
--> $DIR/binop-consume-args.rs:15:10
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -81,7 +81,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:11:30
--> $DIR/binop-consume-args.rs:12:30
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -93,7 +93,7 @@ LL | fn sub<A: Sub<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:19:10
--> $DIR/binop-consume-args.rs:20:10
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -103,7 +103,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:17:8
--> $DIR/binop-consume-args.rs:18:8
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -117,7 +117,7 @@ LL | fn mul<A: Mul<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:20:10
--> $DIR/binop-consume-args.rs:21:10
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -128,7 +128,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:17:30
--> $DIR/binop-consume-args.rs:18:30
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -140,7 +140,7 @@ LL | fn mul<A: Mul<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:25:10
--> $DIR/binop-consume-args.rs:26:10
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -150,7 +150,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:23:8
--> $DIR/binop-consume-args.rs:24:8
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -164,7 +164,7 @@ LL | fn div<A: Div<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:26:10
--> $DIR/binop-consume-args.rs:27:10
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -175,7 +175,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:23:30
--> $DIR/binop-consume-args.rs:24:30
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -187,7 +187,7 @@ LL | fn div<A: Div<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:31:10
--> $DIR/binop-consume-args.rs:32:10
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -197,7 +197,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:29:8
--> $DIR/binop-consume-args.rs:30:8
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -211,7 +211,7 @@ LL | fn rem<A: Rem<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:32:10
--> $DIR/binop-consume-args.rs:33:10
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -222,7 +222,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:29:30
--> $DIR/binop-consume-args.rs:30:30
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -234,7 +234,7 @@ LL | fn rem<A: Rem<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:37:10
--> $DIR/binop-consume-args.rs:38:10
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -244,7 +244,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:35:11
--> $DIR/binop-consume-args.rs:36:11
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -258,7 +258,7 @@ LL | fn bitand<A: BitAnd<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:38:10
--> $DIR/binop-consume-args.rs:39:10
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -269,7 +269,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:35:36
--> $DIR/binop-consume-args.rs:36:36
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -281,7 +281,7 @@ LL | fn bitand<A: BitAnd<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:43:10
--> $DIR/binop-consume-args.rs:44:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -291,7 +291,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:41:10
--> $DIR/binop-consume-args.rs:42:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -305,7 +305,7 @@ LL | fn bitor<A: BitOr<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:44:10
--> $DIR/binop-consume-args.rs:45:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -316,7 +316,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:41:34
--> $DIR/binop-consume-args.rs:42:34
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -328,7 +328,7 @@ LL | fn bitor<A: BitOr<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:49:10
--> $DIR/binop-consume-args.rs:50:10
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -338,7 +338,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:47:11
--> $DIR/binop-consume-args.rs:48:11
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -352,7 +352,7 @@ LL | fn bitxor<A: BitXor<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:50:10
--> $DIR/binop-consume-args.rs:51:10
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -363,7 +363,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:47:36
--> $DIR/binop-consume-args.rs:48:36
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -375,7 +375,7 @@ LL | fn bitxor<A: BitXor<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:55:10
--> $DIR/binop-consume-args.rs:56:10
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -385,7 +385,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:53:8
--> $DIR/binop-consume-args.rs:54:8
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -399,7 +399,7 @@ LL | fn shl<A: Shl<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:56:10
--> $DIR/binop-consume-args.rs:57:10
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -410,7 +410,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:53:30
--> $DIR/binop-consume-args.rs:54:30
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -422,7 +422,7 @@ LL | fn shl<A: Shl<B, Output=()>, B: Copy>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:61:10
--> $DIR/binop-consume-args.rs:62:10
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
@@ -432,7 +432,7 @@ LL | drop(lhs);
| ^^^ value used here after move
|
help: if `A` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:59:8
--> $DIR/binop-consume-args.rs:60:8
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
@@ -446,7 +446,7 @@ LL | fn shr<A: Shr<B, Output=()> + Copy, B>(lhs: A, rhs: B) {
| ++++++
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:62:10
--> $DIR/binop-consume-args.rs:63:10
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
@@ -457,7 +457,7 @@ LL | drop(rhs);
| ^^^ value used here after move
|
help: if `B` implemented `Clone`, you could clone the value
--> $DIR/binop-consume-args.rs:59:30
--> $DIR/binop-consume-args.rs:60:30
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| ^ consider constraining this type parameter with `Clone`
+1
View File
@@ -1,3 +1,4 @@
//@ reference: expr.arith-logic.behavior
// Test that move restrictions are enforced on overloaded binary operations
use std::ops::Add;
+13 -13
View File
@@ -1,5 +1,5 @@
error[E0382]: use of moved value: `x`
--> $DIR/binop-move-semantics.rs:8:5
--> $DIR/binop-move-semantics.rs:9:5
|
LL | fn double_move<T: Add<Output=()>>(x: T) {
| - move occurs because `x` has type `T`, which does not implement the `Copy` trait
@@ -12,7 +12,7 @@ LL | | x;
| `x` moved due to usage in operator
|
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/binop-move-semantics.rs:5:16
--> $DIR/binop-move-semantics.rs:6:16
|
LL | fn double_move<T: Add<Output=()>>(x: T) {
| ^ consider constraining this type parameter with `Clone`
@@ -26,7 +26,7 @@ LL | fn double_move<T: Add<Output=()> + Copy>(x: T) {
| ++++++
error[E0382]: borrow of moved value: `x`
--> $DIR/binop-move-semantics.rs:14:5
--> $DIR/binop-move-semantics.rs:15:5
|
LL | fn move_then_borrow<T: Add<Output=()> + Clone>(x: T) {
| - move occurs because `x` has type `T`, which does not implement the `Copy` trait
@@ -46,7 +46,7 @@ LL | fn move_then_borrow<T: Add<Output=()> + Clone + Copy>(x: T) {
| ++++++
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/binop-move-semantics.rs:21:5
--> $DIR/binop-move-semantics.rs:22:5
|
LL | fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
| - binding `x` declared here
@@ -60,7 +60,7 @@ LL | use_mut(n); use_imm(m);
| - borrow later used here
|
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/binop-move-semantics.rs:17:18
--> $DIR/binop-move-semantics.rs:18:18
|
LL | fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
| ^ consider constraining this type parameter with `Clone`
@@ -68,7 +68,7 @@ LL | let m = &x;
| - you could clone this value
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/binop-move-semantics.rs:23:5
--> $DIR/binop-move-semantics.rs:24:5
|
LL | fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
| ----- binding `y` declared here
@@ -82,7 +82,7 @@ LL | use_mut(n); use_imm(m);
| - borrow later used here
|
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/binop-move-semantics.rs:17:18
--> $DIR/binop-move-semantics.rs:18:18
|
LL | fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
| ^ consider constraining this type parameter with `Clone`
@@ -91,7 +91,7 @@ LL | let n = &mut y;
| - you could clone this value
error[E0507]: cannot move out of `*m` which is behind a mutable reference
--> $DIR/binop-move-semantics.rs:30:5
--> $DIR/binop-move-semantics.rs:31:5
|
LL | *m
| -^
@@ -105,7 +105,7 @@ LL | | *n;
note: calling this operator moves the left-hand side
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/binop-move-semantics.rs:26:24
--> $DIR/binop-move-semantics.rs:27:24
|
LL | fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
| ^ consider constraining this type parameter with `Clone`
@@ -114,13 +114,13 @@ LL | *m
| -- you could clone this value
error[E0507]: cannot move out of `*n` which is behind a shared reference
--> $DIR/binop-move-semantics.rs:32:5
--> $DIR/binop-move-semantics.rs:33:5
|
LL | *n;
| ^^ move occurs because `*n` has type `T`, which does not implement the `Copy` trait
|
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/binop-move-semantics.rs:26:24
--> $DIR/binop-move-semantics.rs:27:24
|
LL | fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
| ^ consider constraining this type parameter with `Clone`
@@ -129,7 +129,7 @@ LL | *n;
| -- you could clone this value
error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
--> $DIR/binop-move-semantics.rs:54:5
--> $DIR/binop-move-semantics.rs:55:5
|
LL | &mut f
| ------
@@ -144,7 +144,7 @@ LL | | &f;
| immutable borrow occurs here
error[E0502]: cannot borrow `f` as mutable because it is also borrowed as immutable
--> $DIR/binop-move-semantics.rs:62:5
--> $DIR/binop-move-semantics.rs:63:5
|
LL | &f
| --
+3
View File
@@ -1,4 +1,7 @@
//@ run-pass
//@ reference: expr.arith-logic.behavior
//@ reference: expr.array.index.trait
//@ reference: expr.negate.results
#![allow(unused_variables)]
use std::cmp;