summaryrefslogtreecommitdiffstats
path: root/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs')
-rw-r--r--src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs
new file mode 100644
index 000000000..f1e043c30
--- /dev/null
+++ b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs
@@ -0,0 +1,159 @@
+#[derive(Clone)]
+enum Either {
+ One(X),
+ Two(X),
+}
+
+#[derive(Clone)]
+struct X(Y);
+
+#[derive(Clone)]
+struct Y;
+
+fn consume_fn<F: Fn()>(_f: F) { }
+
+fn consume_fnmut<F: FnMut()>(_f: F) { }
+
+pub fn main() { }
+
+fn move_into_fn() {
+ let e = Either::One(X(Y));
+ let mut em = Either::One(X(Y));
+
+ let x = X(Y);
+
+ // move into Fn
+
+ consume_fn(|| {
+ let X(_t) = x;
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &x
+ if let Either::One(_t) = e { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ while let Either::One(_t) = e { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ match e {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ Either::One(_t)
+ | Either::Two(_t) => (),
+ }
+ match e {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ Either::One(_t) => (),
+ Either::Two(ref _t) => (),
+ // FIXME: should suggest removing `ref` too
+ }
+
+ let X(mut _t) = x;
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &x
+ if let Either::One(mut _t) = em { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ while let Either::One(mut _t) = em { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ match em {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ Either::One(mut _t)
+ | Either::Two(mut _t) => (),
+ }
+ match em {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ Either::One(mut _t) => (),
+ Either::Two(ref _t) => (),
+ // FIXME: should suggest removing `ref` too
+ }
+ });
+}
+
+fn move_into_fnmut() {
+ let e = Either::One(X(Y));
+ let mut em = Either::One(X(Y));
+
+ let x = X(Y);
+
+ // move into FnMut
+
+ consume_fnmut(|| {
+ let X(_t) = x;
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &x
+ if let Either::One(_t) = e { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ while let Either::One(_t) = e { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ match e {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ Either::One(_t)
+ | Either::Two(_t) => (),
+ }
+ match e {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &e
+ Either::One(_t) => (),
+ Either::Two(ref _t) => (),
+ // FIXME: should suggest removing `ref` too
+ }
+
+ let X(mut _t) = x;
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &x
+ if let Either::One(mut _t) = em { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ while let Either::One(mut _t) = em { }
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ match em {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ Either::One(mut _t)
+ | Either::Two(mut _t) => (),
+ }
+ match em {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ Either::One(mut _t) => (),
+ Either::Two(ref _t) => (),
+ // FIXME: should suggest removing `ref` too
+ }
+ match em {
+ //~^ ERROR cannot move
+ //~| HELP consider borrowing here
+ //~| SUGGESTION &em
+ Either::One(mut _t) => (),
+ Either::Two(ref mut _t) => (),
+ // FIXME: should suggest removing `ref` too
+ }
+ });
+}