about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2024-12-11 18:00:56 -0300
committerSantiago Pastorino <spastorino@gmail.com>2025-03-06 17:58:32 -0300
commitdcdfd551f05073ececfa437be002ce7804b31c91 (patch)
tree813604b622c9bb09c15e1724a6cebfd9d340b53d /tests
parent57cb498989ac29fbe9938ed2f4a31a3eab6850dc (diff)
downloadrust-dcdfd551f05073ececfa437be002ce7804b31c91.tar.gz
rust-dcdfd551f05073ececfa437be002ce7804b31c91.zip
Add UseCloned trait related code
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/ergonomic-clones/closure.rs30
-rw-r--r--tests/ui/ergonomic-clones/dotuse.rs9
-rw-r--r--tests/ui/feature-gates/feature-gate-ergonomic-clones.rs19
-rw-r--r--tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr32
4 files changed, 73 insertions, 17 deletions
diff --git a/tests/ui/ergonomic-clones/closure.rs b/tests/ui/ergonomic-clones/closure.rs
index 340b9ece50e..19ef6f4e13d 100644
--- a/tests/ui/ergonomic-clones/closure.rs
+++ b/tests/ui/ergonomic-clones/closure.rs
@@ -3,6 +3,9 @@
 
 #![feature(ergonomic_clones)]
 
+use std::clone::UseCloned;
+use std::future::Future;
+
 fn ergonomic_clone_closure_no_captures() -> i32 {
     let cl = use || {
         1
@@ -10,7 +13,7 @@ fn ergonomic_clone_closure_no_captures() -> i32 {
     cl()
 }
 
-fn ergonomic_clone_closure_with_captures() -> String {
+fn ergonomic_clone_closure_move() -> String {
     let s = String::from("hi");
 
     let cl = use || {
@@ -19,14 +22,31 @@ fn ergonomic_clone_closure_with_captures() -> String {
     cl()
 }
 
-fn ergonomic_clone_async_closures() -> String {
+#[derive(Clone)]
+struct Foo;
+
+impl UseCloned for Foo {}
+
+fn ergonomic_clone_closure_use_cloned() -> Foo {
+    let f = Foo;
+
+    let f1 = use || {
+        f
+    };
+
+    let f2 = use || {
+        f
+    };
+
+    f
+}
+
+fn ergonomic_clone_async_closures() -> impl Future<Output = String> {
     let s = String::from("hi");
 
     async use {
         s
-    };
-
-    s
+    }
 }
 
 fn main() {}
diff --git a/tests/ui/ergonomic-clones/dotuse.rs b/tests/ui/ergonomic-clones/dotuse.rs
index 928c27296b1..4bab400fef2 100644
--- a/tests/ui/ergonomic-clones/dotuse.rs
+++ b/tests/ui/ergonomic-clones/dotuse.rs
@@ -2,11 +2,18 @@
 
 #![feature(ergonomic_clones)]
 
+use std::clone::UseCloned;
+
 fn basic_test(x: i32) -> i32 {
     x.use.use.abs()
 }
 
-fn do_not_move_test(x: String) -> String {
+#[derive(Clone)]
+struct Foo;
+
+impl UseCloned for Foo {}
+
+fn do_not_move_test(x: Foo) -> Foo {
     let s = x.use;
     x
 }
diff --git a/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs b/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs
index 0ffc3925005..8ae78e27d0e 100644
--- a/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs
+++ b/tests/ui/feature-gates/feature-gate-ergonomic-clones.rs
@@ -1,19 +1,28 @@
+use std::clone::UseCloned;
+//~^ ERROR use of unstable library feature `ergonomic_clones` [E0658]
+
 fn ergonomic_clone(x: i32) -> i32 {
     x.use
     //~^ ERROR `.use` calls are experimental [E0658]
 }
 
+#[derive(Clone)]
+struct Foo;
+
+impl UseCloned for Foo {}
+//~^ ERROR use of unstable library feature `ergonomic_clones` [E0658]
+
 fn ergonomic_closure_clone() {
-    let s1 = String::from("hi!");
+    let f1 = Foo;
 
-    let s2 = use || {
+    let f2 = use || {
         //~^ ERROR `.use` calls are experimental [E0658]
-        s1
+        f1
     };
 
-    let s3 = use || {
+    let f3 = use || {
         //~^ ERROR `.use` calls are experimental [E0658]
-        s1
+        f1
     };
 }
 
diff --git a/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr b/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr
index 366151c91a6..68d64715620 100644
--- a/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr
+++ b/tests/ui/feature-gates/feature-gate-ergonomic-clones.stderr
@@ -1,5 +1,5 @@
 error[E0658]: `.use` calls are experimental
-  --> $DIR/feature-gate-ergonomic-clones.rs:2:7
+  --> $DIR/feature-gate-ergonomic-clones.rs:5:7
    |
 LL |     x.use
    |       ^^^
@@ -9,9 +9,9 @@ LL |     x.use
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
 error[E0658]: `.use` calls are experimental
-  --> $DIR/feature-gate-ergonomic-clones.rs:9:14
+  --> $DIR/feature-gate-ergonomic-clones.rs:18:14
    |
-LL |     let s2 = use || {
+LL |     let f2 = use || {
    |              ^^^
    |
    = note: see issue #132290 <https://github.com/rust-lang/rust/issues/132290> for more information
@@ -19,15 +19,35 @@ LL |     let s2 = use || {
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
 error[E0658]: `.use` calls are experimental
-  --> $DIR/feature-gate-ergonomic-clones.rs:14:14
+  --> $DIR/feature-gate-ergonomic-clones.rs:23:14
    |
-LL |     let s3 = use || {
+LL |     let f3 = use || {
    |              ^^^
    |
    = note: see issue #132290 <https://github.com/rust-lang/rust/issues/132290> for more information
    = help: add `#![feature(ergonomic_clones)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error: aborting due to 3 previous errors
+error[E0658]: use of unstable library feature `ergonomic_clones`
+  --> $DIR/feature-gate-ergonomic-clones.rs:1:5
+   |
+LL | use std::clone::UseCloned;
+   |     ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #132290 <https://github.com/rust-lang/rust/issues/132290> for more information
+   = help: add `#![feature(ergonomic_clones)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0658]: use of unstable library feature `ergonomic_clones`
+  --> $DIR/feature-gate-ergonomic-clones.rs:12:6
+   |
+LL | impl UseCloned for Foo {}
+   |      ^^^^^^^^^
+   |
+   = note: see issue #132290 <https://github.com/rust-lang/rust/issues/132290> for more information
+   = help: add `#![feature(ergonomic_clones)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error: aborting due to 5 previous errors
 
 For more information about this error, try `rustc --explain E0658`.