//~| NOTE: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
}
+// 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 = #[rustc_capture_analysis] move || x;
+ //~^ ERROR: attributes on expressions are experimental
+ //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
+ //~| First Pass analysis includes:
+ //~| NOTE: Capturing x[] -> ImmBorrow
+ //~| Min Capture analysis includes:
+ //~| NOTE: Min Capture x[] -> ByValue
+
+ c
+}
+
fn main() {
simple_move_closure();
simple_ref();
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
+error[E0658]: attributes on expressions are experimental
+ --> $DIR/move_closure.rs:202:13
+ |
+LL | let c = #[rustc_capture_analysis] move || x;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
+ = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
+
+error: First Pass analysis includes:
+ --> $DIR/move_closure.rs:202:39
+ |
+LL | let c = #[rustc_capture_analysis] move || x;
+ | ^^^^^^^^^
+ |
+note: Capturing x[] -> ImmBorrow
+ --> $DIR/move_closure.rs:202:47
+ |
+LL | let c = #[rustc_capture_analysis] move || x;
+ | ^
+
+error: Min Capture analysis includes:
+ --> $DIR/move_closure.rs:202:39
+ |
+LL | let c = #[rustc_capture_analysis] move || x;
+ | ^^^^^^^^^
+ |
+note: Min Capture x[] -> ByValue
+ --> $DIR/move_closure.rs:202:47
+ |
+LL | let c = #[rustc_capture_analysis] move || x;
+ | ^
+
error: First Pass analysis includes:
--> $DIR/move_closure.rs:15:5
|
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
| ^^^^^^^
-error: aborting due to 30 previous errors
+error: aborting due to 33 previous errors
For more information about this error, try `rustc --explain E0658`.
// 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;
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();
disjoint_via_ref();
data_moved_but_not_fn_once();
+
+ returned_closure_owns_copy_type_data();
}