]> git.lizzy.rs Git - rust.git/blobdiff - src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs
Add test for copy type in move closure
[rust.git] / src / test / ui / closures / 2229_closure_analysis / run_pass / move_closure.rs
index 65c8a5a7850fec4ad66863570e43722459547e50..e1b61e85ec1927d18444a778bcb188820ce67bee 100644 (file)
@@ -3,6 +3,8 @@
 
 // Test that move closures compile properly with `capture_disjoint_fields` enabled.
 
+#![allow(unused)]
+
 fn simple_ref() {
     let mut s = 10;
     let ref_s = &mut s;
@@ -92,6 +94,15 @@ fn data_moved_but_not_fn_once() {
     c();
 }
 
+// Test that move closures can take ownership of Copy type
+fn returned_closure_owns_copy_type_data() -> impl Fn() -> i32 {
+    let x = 10;
+
+    let c = move || x;
+
+    c
+}
+
 fn main() {
     simple_ref();
     struct_contains_ref_to_another_struct();
@@ -100,4 +111,6 @@ fn main() {
 
     disjoint_via_ref();
     data_moved_but_not_fn_once();
+
+    returned_closure_owns_copy_type_data();
 }