summaryrefslogtreecommitdiffstats
path: root/tests/ui/moves
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/moves')
-rw-r--r--tests/ui/moves/issue-34721.fixed34
-rw-r--r--tests/ui/moves/issue-34721.rs34
-rw-r--r--tests/ui/moves/issue-34721.stderr28
3 files changed, 96 insertions, 0 deletions
diff --git a/tests/ui/moves/issue-34721.fixed b/tests/ui/moves/issue-34721.fixed
new file mode 100644
index 000000000..f135ad383
--- /dev/null
+++ b/tests/ui/moves/issue-34721.fixed
@@ -0,0 +1,34 @@
+// run-rustfix
+
+pub trait Foo {
+ fn zero(self) -> Self;
+}
+
+impl Foo for u32 {
+ fn zero(self) -> u32 { 0u32 }
+}
+
+pub mod bar {
+ pub use Foo;
+ pub fn bar<T: Foo>(x: T) -> T {
+ x.zero()
+ }
+}
+
+mod baz {
+ use bar;
+ use Foo;
+ pub fn baz<T: Foo + Copy>(x: T) -> T {
+ if 0 == 1 {
+ bar::bar(x.zero())
+ } else {
+ x.zero()
+ };
+ x.zero()
+ //~^ ERROR use of moved value
+ }
+}
+
+fn main() {
+ let _ = baz::baz(0u32);
+}
diff --git a/tests/ui/moves/issue-34721.rs b/tests/ui/moves/issue-34721.rs
new file mode 100644
index 000000000..14dd01766
--- /dev/null
+++ b/tests/ui/moves/issue-34721.rs
@@ -0,0 +1,34 @@
+// run-rustfix
+
+pub trait Foo {
+ fn zero(self) -> Self;
+}
+
+impl Foo for u32 {
+ fn zero(self) -> u32 { 0u32 }
+}
+
+pub mod bar {
+ pub use Foo;
+ pub fn bar<T: Foo>(x: T) -> T {
+ x.zero()
+ }
+}
+
+mod baz {
+ use bar;
+ use Foo;
+ pub fn baz<T: Foo>(x: T) -> T {
+ if 0 == 1 {
+ bar::bar(x.zero())
+ } else {
+ x.zero()
+ };
+ x.zero()
+ //~^ ERROR use of moved value
+ }
+}
+
+fn main() {
+ let _ = baz::baz(0u32);
+}
diff --git a/tests/ui/moves/issue-34721.stderr b/tests/ui/moves/issue-34721.stderr
new file mode 100644
index 000000000..f2bf22227
--- /dev/null
+++ b/tests/ui/moves/issue-34721.stderr
@@ -0,0 +1,28 @@
+error[E0382]: use of moved value: `x`
+ --> $DIR/issue-34721.rs:27:9
+ |
+LL | pub fn baz<T: Foo>(x: T) -> T {
+ | - move occurs because `x` has type `T`, which does not implement the `Copy` trait
+LL | if 0 == 1 {
+LL | bar::bar(x.zero())
+ | ------ `x` moved due to this method call
+LL | } else {
+LL | x.zero()
+ | ------ `x` moved due to this method call
+LL | };
+LL | x.zero()
+ | ^ value used here after move
+ |
+note: `Foo::zero` takes ownership of the receiver `self`, which moves `x`
+ --> $DIR/issue-34721.rs:4:13
+ |
+LL | fn zero(self) -> Self;
+ | ^^^^
+help: consider further restricting this bound
+ |
+LL | pub fn baz<T: Foo + Copy>(x: T) -> T {
+ | ++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0382`.