diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /tests/ui/binop | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/binop')
-rw-r--r-- | tests/ui/binop/binop-move-semantics.stderr | 2 | ||||
-rw-r--r-- | tests/ui/binop/borrow-suggestion-109352-2.rs | 27 | ||||
-rw-r--r-- | tests/ui/binop/borrow-suggestion-109352-2.stderr | 64 | ||||
-rw-r--r-- | tests/ui/binop/borrow-suggestion-109352.fixed | 27 | ||||
-rw-r--r-- | tests/ui/binop/borrow-suggestion-109352.rs | 27 | ||||
-rw-r--r-- | tests/ui/binop/borrow-suggestion-109352.stderr | 45 |
6 files changed, 191 insertions, 1 deletions
diff --git a/tests/ui/binop/binop-move-semantics.stderr b/tests/ui/binop/binop-move-semantics.stderr index 8645169b9..1dd8c9a87 100644 --- a/tests/ui/binop/binop-move-semantics.stderr +++ b/tests/ui/binop/binop-move-semantics.stderr @@ -27,7 +27,7 @@ LL | x | - value moved here LL | + LL | x.clone(); - | ^^^^^^^^^ value borrowed here after move + | ^ value borrowed here after move | help: consider cloning the value if the performance cost is acceptable | diff --git a/tests/ui/binop/borrow-suggestion-109352-2.rs b/tests/ui/binop/borrow-suggestion-109352-2.rs new file mode 100644 index 000000000..43dab9529 --- /dev/null +++ b/tests/ui/binop/borrow-suggestion-109352-2.rs @@ -0,0 +1,27 @@ +struct Bar; + +impl std::ops::Mul for &mut Bar { + type Output = Bar; + + fn mul(self, _rhs: Self) -> Self::Output { + unimplemented!() + } +} + +fn main() { + let ref_mut_bar: &mut Bar = &mut Bar; + let ref_bar: &Bar = &Bar; + let owned_bar: Bar = Bar; + + let _ = ref_mut_bar * ref_mut_bar; + + // FIXME: we should be able to suggest borrowing both side + let _ = owned_bar * owned_bar; + //~^ ERROR cannot multiply + let _ = ref_bar * ref_bar; + //~^ ERROR cannot multiply + let _ = ref_bar * ref_mut_bar; + //~^ ERROR cannot multiply + let _ = ref_mut_bar * ref_bar; + //~^ ERROR mismatched types +} diff --git a/tests/ui/binop/borrow-suggestion-109352-2.stderr b/tests/ui/binop/borrow-suggestion-109352-2.stderr new file mode 100644 index 000000000..18ed08d73 --- /dev/null +++ b/tests/ui/binop/borrow-suggestion-109352-2.stderr @@ -0,0 +1,64 @@ +error[E0369]: cannot multiply `Bar` by `Bar` + --> $DIR/borrow-suggestion-109352-2.rs:19:23 + | +LL | let _ = owned_bar * owned_bar; + | --------- ^ --------- Bar + | | + | Bar + | +note: an implementation of `Mul` might be missing for `Bar` + --> $DIR/borrow-suggestion-109352-2.rs:1:1 + | +LL | struct Bar; + | ^^^^^^^^^^ must implement `Mul` +note: the trait `Mul` must be implemented + --> $SRC_DIR/core/src/ops/arith.rs:LL:COL + +error[E0369]: cannot multiply `&Bar` by `&Bar` + --> $DIR/borrow-suggestion-109352-2.rs:21:21 + | +LL | let _ = ref_bar * ref_bar; + | ------- ^ ------- &Bar + | | + | &Bar + | + = note: an implementation for `&mut Bar * &mut Bar` exists +help: consider making this expression a mutable borrow + --> $DIR/borrow-suggestion-109352-2.rs:21:13 + | +LL | let _ = ref_bar * ref_bar; + | ^^^^^^^ +help: consider making this expression a mutable borrow + --> $DIR/borrow-suggestion-109352-2.rs:21:23 + | +LL | let _ = ref_bar * ref_bar; + | ^^^^^^^ + +error[E0369]: cannot multiply `&Bar` by `&mut Bar` + --> $DIR/borrow-suggestion-109352-2.rs:23:21 + | +LL | let _ = ref_bar * ref_mut_bar; + | ------- ^ ----------- &mut Bar + | | + | &Bar + | + = note: an implementation for `&mut Bar * &mut Bar` exists +help: consider making this expression a mutable borrow + --> $DIR/borrow-suggestion-109352-2.rs:23:13 + | +LL | let _ = ref_bar * ref_mut_bar; + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/borrow-suggestion-109352-2.rs:25:27 + | +LL | let _ = ref_mut_bar * ref_bar; + | ^^^^^^^ types differ in mutability + | + = note: expected mutable reference `&mut Bar` + found reference `&Bar` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0308, E0369. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/binop/borrow-suggestion-109352.fixed b/tests/ui/binop/borrow-suggestion-109352.fixed new file mode 100644 index 000000000..3374a9d78 --- /dev/null +++ b/tests/ui/binop/borrow-suggestion-109352.fixed @@ -0,0 +1,27 @@ +// run-rustfix + +struct Foo; + +impl std::ops::Mul for &Foo { + type Output = Foo; + + fn mul(self, _rhs: Self) -> Self::Output { + unimplemented!() + } +} + +fn main() { + let ref_mut_foo: &mut Foo = &mut Foo; + let ref_foo: &Foo = &Foo; + let owned_foo: Foo = Foo; + + let _ = ref_foo * ref_foo; + let _ = ref_foo * ref_mut_foo; + + let _ = &*ref_mut_foo * ref_foo; + //~^ ERROR cannot multiply + let _ = &*ref_mut_foo * &*ref_mut_foo; + //~^ ERROR cannot multiply + let _ = &*ref_mut_foo * &owned_foo; + //~^ ERROR cannot multiply +} diff --git a/tests/ui/binop/borrow-suggestion-109352.rs b/tests/ui/binop/borrow-suggestion-109352.rs new file mode 100644 index 000000000..4e8510e0d --- /dev/null +++ b/tests/ui/binop/borrow-suggestion-109352.rs @@ -0,0 +1,27 @@ +// run-rustfix + +struct Foo; + +impl std::ops::Mul for &Foo { + type Output = Foo; + + fn mul(self, _rhs: Self) -> Self::Output { + unimplemented!() + } +} + +fn main() { + let ref_mut_foo: &mut Foo = &mut Foo; + let ref_foo: &Foo = &Foo; + let owned_foo: Foo = Foo; + + let _ = ref_foo * ref_foo; + let _ = ref_foo * ref_mut_foo; + + let _ = ref_mut_foo * ref_foo; + //~^ ERROR cannot multiply + let _ = ref_mut_foo * ref_mut_foo; + //~^ ERROR cannot multiply + let _ = ref_mut_foo * &owned_foo; + //~^ ERROR cannot multiply +} diff --git a/tests/ui/binop/borrow-suggestion-109352.stderr b/tests/ui/binop/borrow-suggestion-109352.stderr new file mode 100644 index 000000000..71e44f54b --- /dev/null +++ b/tests/ui/binop/borrow-suggestion-109352.stderr @@ -0,0 +1,45 @@ +error[E0369]: cannot multiply `&mut Foo` by `&Foo` + --> $DIR/borrow-suggestion-109352.rs:21:25 + | +LL | let _ = ref_mut_foo * ref_foo; + | ----------- ^ ------- &Foo + | | + | &mut Foo + | + = note: an implementation for `&Foo * &Foo` exists +help: consider reborrowing this side + | +LL | let _ = &*ref_mut_foo * ref_foo; + | ++ + +error[E0369]: cannot multiply `&mut Foo` by `&mut Foo` + --> $DIR/borrow-suggestion-109352.rs:23:25 + | +LL | let _ = ref_mut_foo * ref_mut_foo; + | ----------- ^ ----------- &mut Foo + | | + | &mut Foo + | + = note: an implementation for `&Foo * &Foo` exists +help: consider reborrowing both sides + | +LL | let _ = &*ref_mut_foo * &*ref_mut_foo; + | ++ ++ + +error[E0369]: cannot multiply `&mut Foo` by `&Foo` + --> $DIR/borrow-suggestion-109352.rs:25:25 + | +LL | let _ = ref_mut_foo * &owned_foo; + | ----------- ^ ---------- &Foo + | | + | &mut Foo + | + = note: an implementation for `&Foo * &Foo` exists +help: consider reborrowing this side + | +LL | let _ = &*ref_mut_foo * &owned_foo; + | ++ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0369`. |