From 3c3a35213c508eeb7f5e121ad299a135122733ed Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Sat, 7 Mar 2026 13:04:19 -0800 Subject: [PATCH] tests/ui/binop: add annotations for reference rules --- tests/ui/binop/augmented-assignment.rs | 1 + tests/ui/binop/binary-minus-without-space.rs | 3 + tests/ui/binop/binop-consume-args.rs | 1 + tests/ui/binop/binop-consume-args.stderr | 80 ++++++++++---------- tests/ui/binop/binop-move-semantics.rs | 1 + tests/ui/binop/binop-move-semantics.stderr | 26 +++---- tests/ui/binop/operator-overloading.rs | 3 + 7 files changed, 62 insertions(+), 53 deletions(-) diff --git a/tests/ui/binop/augmented-assignment.rs b/tests/ui/binop/augmented-assignment.rs index 755ecb466ceb7..a8de7ae1d3fc8 100644 --- a/tests/ui/binop/augmented-assignment.rs +++ b/tests/ui/binop/augmented-assignment.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: expr.arith-logic.behavior #![allow(unused_imports)] #![deny(unused_assignments)] diff --git a/tests/ui/binop/binary-minus-without-space.rs b/tests/ui/binop/binary-minus-without-space.rs index c80c0c88fcbc4..64243ebbb94eb 100644 --- a/tests/ui/binop/binary-minus-without-space.rs +++ b/tests/ui/binop/binary-minus-without-space.rs @@ -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 diff --git a/tests/ui/binop/binop-consume-args.rs b/tests/ui/binop/binop-consume-args.rs index 8d6c725d75603..1bd803ce4c8f0 100644 --- a/tests/ui/binop/binop-consume-args.rs +++ b/tests/ui/binop/binop-consume-args.rs @@ -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}; diff --git a/tests/ui/binop/binop-consume-args.stderr b/tests/ui/binop/binop-consume-args.stderr index d9d92a44766db..2b2bb10620498 100644 --- a/tests/ui/binop/binop-consume-args.stderr +++ b/tests/ui/binop/binop-consume-args.stderr @@ -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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -23,7 +23,7 @@ LL | fn add + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -46,7 +46,7 @@ LL | fn add, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -70,7 +70,7 @@ LL | fn sub + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -93,7 +93,7 @@ LL | fn sub, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -117,7 +117,7 @@ LL | fn mul + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -140,7 +140,7 @@ LL | fn mul, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -164,7 +164,7 @@ LL | fn div + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -187,7 +187,7 @@ LL | fn div, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -211,7 +211,7 @@ LL | fn rem + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -234,7 +234,7 @@ LL | fn rem, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -258,7 +258,7 @@ LL | fn bitand + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -281,7 +281,7 @@ LL | fn bitand, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -305,7 +305,7 @@ LL | fn bitor + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -328,7 +328,7 @@ LL | fn bitor, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -352,7 +352,7 @@ LL | fn bitxor + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -375,7 +375,7 @@ LL | fn bitxor, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -399,7 +399,7 @@ LL | fn shl + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -422,7 +422,7 @@ LL | fn shl, 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -446,7 +446,7 @@ LL | fn shr + 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, 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, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` diff --git a/tests/ui/binop/binop-move-semantics.rs b/tests/ui/binop/binop-move-semantics.rs index b5133ea7c92a0..c49613c02d501 100644 --- a/tests/ui/binop/binop-move-semantics.rs +++ b/tests/ui/binop/binop-move-semantics.rs @@ -1,3 +1,4 @@ +//@ reference: expr.arith-logic.behavior // Test that move restrictions are enforced on overloaded binary operations use std::ops::Add; diff --git a/tests/ui/binop/binop-move-semantics.stderr b/tests/ui/binop/binop-move-semantics.stderr index 2e661c44abd1a..029a94a49452a 100644 --- a/tests/ui/binop/binop-move-semantics.stderr +++ b/tests/ui/binop/binop-move-semantics.stderr @@ -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>(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>(x: T) { | ^ consider constraining this type parameter with `Clone` @@ -26,7 +26,7 @@ LL | fn double_move + 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 + 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 + 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>(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>(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>(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>(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>(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>(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 | -- diff --git a/tests/ui/binop/operator-overloading.rs b/tests/ui/binop/operator-overloading.rs index 7f29856194e09..76a9ed079a099 100644 --- a/tests/ui/binop/operator-overloading.rs +++ b/tests/ui/binop/operator-overloading.rs @@ -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;