mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Add test for copy type in move closure
This commit is contained in:
parent
10b536fc71
commit
36f51c96dc
@ -195,6 +195,21 @@ fn box_mut_2() {
|
||||
//~| 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();
|
||||
|
@ -88,6 +88,39 @@ LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
|
||||
= 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
|
||||
|
|
||||
@ -424,6 +457,6 @@ note: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
|
||||
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`.
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user