Update test cases

This commit is contained in:
Aman Arora 2021-04-01 16:32:25 -04:00
parent 18af989c06
commit da86348707
9 changed files with 527 additions and 113 deletions

View File

@ -0,0 +1,133 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
//~^ NOTE: the lint level is defined here
// Test cases for types that implement a insignificant drop (stlib defined)
// `t` needs Drop because one of its elements needs drop,
// therefore precise capture might affect drop ordering
fn test1_all_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let t2 = (String::new(), String::new());
let c = || { let _ = (&t, &t1, &t2); {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1, &t2)` causes `t`, `t1`, `t2` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2.0;
} };
c();
}
// String implements drop and therefore should be migrated.
// But in this test cases, `t2` is completely captured and when it is dropped won't be affected
fn test2_only_precise_paths_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let t2 = (String::new(), String::new());
let c = || { let _ = (&t, &t1); {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1)` causes `t`, `t1` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2;
} };
c();
}
// If a variable would've not been captured by value then it would've not been
// dropped with the closure and therefore doesn't need migration.
fn test3_only_by_value_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
println!("{}", t1.1);
} };
c();
}
// Copy types get copied into the closure instead of move. Therefore we don't need to
// migrate then as their drop order isn't tied to the closure.
fn test4_only_non_copy_types_need_migration() {
let t = (String::new(), String::new());
// `t1` is Copy because all of its elements are Copy
let t1 = (0i32, 0i32);
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
let _t1 = t1.0;
} };
c();
}
fn test5_only_drop_types_need_migration() {
struct S(i32, i32);
let t = (String::new(), String::new());
// `s` doesn't implement Drop or any elements within it, and doesn't need migration
let s = S(0i32, 0i32);
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
let _s = s.0;
} };
c();
}
// Since we are using a move closure here, both `t` and `t1` get moved
// even though they are being used by ref inside the closure.
fn test6_move_closures_non_copy_types_might_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let c = move || { let _ = (&t1, &t); {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = (&t1, &t)` causes `t1`, `t` to be fully captured
println!("{} {}", t1.1, t.1);
} };
c();
}
// Test migration analysis in case of Drop + Non Drop aggregates.
// Note we need migration here only because the non-copy (because Drop type) is captured,
// otherwise we won't need to, since we can get away with just by ref capture in that case.
fn test7_drop_non_drop_aggregate_need_migration() {
let t = (String::new(), String::new(), 0i32);
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
} };
c();
}
fn main() {
test1_all_need_migration();
test2_only_precise_paths_need_migration();
test3_only_by_value_need_migration();
test4_only_non_copy_types_need_migration();
test5_only_drop_types_need_migration();
test6_move_closures_non_copy_types_might_need_migration();
test7_drop_non_drop_aggregate_need_migration();
}

View File

@ -1,3 +1,5 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
//~^ NOTE: the lint level is defined here
@ -11,8 +13,9 @@ fn test1_all_need_migration() {
let t2 = (String::new(), String::new());
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t, t1, t2));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1, &t2)` causes `t`, `t1`, `t2` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2.0;
@ -29,8 +32,8 @@ fn test2_only_precise_paths_need_migration() {
let t2 = (String::new(), String::new());
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t, t1));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1)` causes `t`, `t1` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2;
@ -45,8 +48,8 @@ fn test3_only_by_value_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
println!("{}", t1.1);
};
@ -63,8 +66,8 @@ fn test4_only_non_copy_types_need_migration() {
let t1 = (0i32, 0i32);
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
let _t1 = t1.0;
};
@ -81,8 +84,8 @@ fn test5_only_drop_types_need_migration() {
let s = S(0i32, 0i32);
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
let _s = s.0;
};
@ -96,8 +99,8 @@ fn test6_move_closures_non_copy_types_might_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let c = move || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t1, t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = (&t1, &t)` causes `t1`, `t` to be fully captured
println!("{} {}", t1.1, t.1);
};
@ -111,8 +114,8 @@ fn test7_drop_non_drop_aggregate_need_migration() {
let t = (String::new(), String::new(), 0i32);
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
};

View File

@ -1,25 +1,33 @@
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:13:13
--> $DIR/insignificant_drop.rs:15:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | let _t1 = t1.0;
LL | |
... |
LL | | let _t2 = t2.0;
LL | | };
| |_____^
|
note: the lint level is defined here
--> $DIR/insignificant_drop.rs:1:9
--> $DIR/insignificant_drop.rs:3:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: drop(&(t, t1, t2));
help: `let _ = (&t, &t1, &t2)` causes `t`, `t1`, `t2` to be fully captured
|
LL | let c = || { let _ = (&t, &t1, &t2); {
LL |
LL |
LL |
LL | let _t = t.0;
LL | let _t1 = t1.0;
...
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:31:13
--> $DIR/insignificant_drop.rs:34:13
|
LL | let c = || {
| _____________^
@ -31,10 +39,18 @@ LL | | let _t2 = t2;
LL | | };
| |_____^
|
= note: drop(&(t, t1));
help: `let _ = (&t, &t1)` causes `t`, `t1` to be fully captured
|
LL | let c = || { let _ = (&t, &t1); {
LL |
LL |
LL | let _t = t.0;
LL | let _t1 = t1.0;
LL | let _t2 = t2;
...
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:47:13
--> $DIR/insignificant_drop.rs:50:13
|
LL | let c = || {
| _____________^
@ -45,10 +61,18 @@ LL | | println!("{}", t1.1);
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | println!("{}", t1.1);
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:65:13
--> $DIR/insignificant_drop.rs:68:13
|
LL | let c = || {
| _____________^
@ -59,10 +83,18 @@ LL | | let _t1 = t1.0;
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | let _t1 = t1.0;
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:83:13
--> $DIR/insignificant_drop.rs:86:13
|
LL | let c = || {
| _____________^
@ -73,10 +105,18 @@ LL | | let _s = s.0;
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | let _s = s.0;
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:98:13
--> $DIR/insignificant_drop.rs:101:13
|
LL | let c = move || {
| _____________^
@ -86,10 +126,17 @@ LL | | println!("{} {}", t1.1, t.1);
LL | | };
| |_____^
|
= note: drop(&(t1, t));
help: `let _ = (&t1, &t)` causes `t1`, `t` to be fully captured
|
LL | let c = move || { let _ = (&t1, &t); {
LL |
LL |
LL | println!("{} {}", t1.1, t.1);
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:113:13
--> $DIR/insignificant_drop.rs:116:13
|
LL | let c = || {
| _____________^
@ -99,7 +146,14 @@ LL | | let _t = t.0;
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | } };
|
error: aborting due to 7 previous errors

View File

@ -0,0 +1,56 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#[derive(Debug)]
struct Foo(i32);
impl Drop for Foo {
fn drop(&mut self) {
println!("{:?} dropped", self.0);
}
}
struct ConstainsDropField(Foo, Foo);
// Test that lint is triggered if a path that implements Drop is not captured by move
fn test_precise_analysis_drop_paths_not_captured_by_move() {
let t = ConstainsDropField(Foo(10), Foo(20));
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
let _t = &t.1;
} };
c();
}
struct S;
impl Drop for S {
fn drop(&mut self) {
}
}
struct T(S, S);
struct U(T, T);
// Test precise analysis for the lint works with paths longer than one.
fn test_precise_analysis_long_path_missing() {
let u = U(T(S, S), T(S, S));
let c = || { let _ = &u; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &u` causes `u` to be fully captured
let _x = u.0.0;
let _x = u.0.1;
let _x = u.1.0;
} };
c();
}
fn main() {
test_precise_analysis_drop_paths_not_captured_by_move();
test_precise_analysis_long_path_missing();
}

View File

@ -1,5 +1,6 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
//~^ NOTE: the lint level is defined here
#[derive(Debug)]
struct Foo(i32);
@ -11,35 +12,13 @@ impl Drop for Foo {
struct ConstainsDropField(Foo, Foo);
#[derive(Debug)]
struct ContainsAndImplsDrop(Foo);
impl Drop for ContainsAndImplsDrop {
fn drop(&mut self) {
println!("{:?} dropped", self.0);
}
}
// Test that even if all paths starting at root variable that implement Drop are captured,
// the lint is triggered if the root variable implements drop and isn't captured.
fn test_precise_analysis_parent_root_impl_drop_not_captured() {
let t = ContainsAndImplsDrop(Foo(10));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
let _t = t.0;
};
c();
}
// Test that lint is triggered if a path that implements Drop is not captured by move
fn test_precise_analysis_drop_paths_not_captured_by_move() {
let t = ConstainsDropField(Foo(10), Foo(20));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
let _t = &t.1;
};
@ -61,8 +40,8 @@ fn test_precise_analysis_long_path_missing() {
let u = U(T(S, S), T(S, S));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(u));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &u` causes `u` to be fully captured
let _x = u.0.0;
let _x = u.0.1;
let _x = u.1.0;
@ -72,7 +51,6 @@ fn test_precise_analysis_long_path_missing() {
}
fn main() {
test_precise_analysis_parent_root_impl_drop_not_captured();
test_precise_analysis_drop_paths_not_captured_by_move();
test_precise_analysis_long_path_missing();
}

View File

@ -1,23 +1,5 @@
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/precise.rs:27:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | };
| |_____^
|
note: the lint level is defined here
--> $DIR/precise.rs:1:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: drop(&(t));
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/precise.rs:40:13
--> $DIR/precise.rs:19:13
|
LL | let c = || {
| _____________^
@ -28,10 +10,23 @@ LL | | let _t = &t.1;
LL | | };
| |_____^
|
= note: drop(&(t));
note: the lint level is defined here
--> $DIR/precise.rs:3:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | let _t = &t.1;
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/precise.rs:63:13
--> $DIR/precise.rs:42:13
|
LL | let c = || {
| _____________^
@ -43,7 +38,15 @@ LL | | let _x = u.1.0;
LL | | };
| |_____^
|
= note: drop(&(u));
help: `let _ = &u` causes `u` to be fully captured
|
LL | let c = || { let _ = &u; {
LL |
LL |
LL | let _x = u.0.0;
LL | let _x = u.0.1;
LL | let _x = u.1.0;
...
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

View File

@ -0,0 +1,136 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
//~^ NOTE: the lint level is defined here
// Test cases for types that implement a significant drop (user defined)
#[derive(Debug)]
struct Foo(i32);
impl Drop for Foo {
fn drop(&mut self) {
println!("{:?} dropped", self.0);
}
}
#[derive(Debug)]
struct ConstainsDropField(Foo, Foo);
// `t` needs Drop because one of its elements needs drop,
// therefore precise capture might affect drop ordering
fn test1_all_need_migration() {
let t = (Foo(0), Foo(0));
let t1 = (Foo(0), Foo(0));
let t2 = (Foo(0), Foo(0));
let c = || { let _ = (&t, &t1, &t2); {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1, &t2)` causes `t`, `t1`, `t2` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2.0;
} };
c();
}
// String implements drop and therefore should be migrated.
// But in this test cases, `t2` is completely captured and when it is dropped won't be affected
fn test2_only_precise_paths_need_migration() {
let t = (Foo(0), Foo(0));
let t1 = (Foo(0), Foo(0));
let t2 = (Foo(0), Foo(0));
let c = || { let _ = (&t, &t1); {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1)` causes `t`, `t1` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2;
} };
c();
}
// If a variable would've not been captured by value then it would've not been
// dropped with the closure and therefore doesn't need migration.
fn test3_only_by_value_need_migration() {
let t = (Foo(0), Foo(0));
let t1 = (Foo(0), Foo(0));
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
println!("{:?}", t1.1);
} };
c();
}
// The root variable might not implement drop themselves but some path starting
// at the root variable might implement Drop.
//
// If this path isn't captured we need to migrate for the root variable.
fn test4_type_contains_drop_need_migration() {
let t = ConstainsDropField(Foo(0), Foo(0));
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
} };
c();
}
// Test migration analysis in case of Drop + Non Drop aggregates.
// Note we need migration here only because the non-copy (because Drop type) is captured,
// otherwise we won't need to, since we can get away with just by ref capture in that case.
fn test5_drop_non_drop_aggregate_need_migration() {
let t = (Foo(0), Foo(0), 0i32);
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
} };
c();
}
// Test migration analysis in case of Significant and Insignificant Drop aggregates.
fn test6_significant_insignificant_drop_aggregate_need_migration() {
let t = (Foo(0), String::new());
let c = || { let _ = &t; {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.1;
} };
c();
}
// Since we are using a move closure here, both `t` and `t1` get moved
// even though they are being used by ref inside the closure.
fn test7_move_closures_non_copy_types_might_need_migration() {
let t = (Foo(0), Foo(0));
let t1 = (Foo(0), Foo(0), Foo(0));
let c = move || { let _ = (&t1, &t); {
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = (&t1, &t)` causes `t1`, `t` to be fully captured
println!("{:?} {:?}", t1.1, t.1);
} };
c();
}
fn main() {
test1_all_need_migration();
test2_only_precise_paths_need_migration();
test3_only_by_value_need_migration();
test4_type_contains_drop_need_migration();
test5_drop_non_drop_aggregate_need_migration();
test6_significant_insignificant_drop_aggregate_need_migration();
test7_move_closures_non_copy_types_might_need_migration();
}

View File

@ -1,3 +1,4 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
//~^ NOTE: the lint level is defined here
@ -22,8 +23,8 @@ fn test1_all_need_migration() {
let t2 = (Foo(0), Foo(0));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t, t1, t2));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1, &t2)` causes `t`, `t1`, `t2` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2.0;
@ -40,8 +41,8 @@ fn test2_only_precise_paths_need_migration() {
let t2 = (Foo(0), Foo(0));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t, t1));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP:` let _ = (&t, &t1)` causes `t`, `t1` to be fully captured
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2;
@ -56,8 +57,8 @@ fn test3_only_by_value_need_migration() {
let t = (Foo(0), Foo(0));
let t1 = (Foo(0), Foo(0));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
println!("{:?}", t1.1);
};
@ -73,8 +74,8 @@ fn test4_type_contains_drop_need_migration() {
let t = ConstainsDropField(Foo(0), Foo(0));
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
};
@ -88,8 +89,8 @@ fn test5_drop_non_drop_aggregate_need_migration() {
let t = (Foo(0), Foo(0), 0i32);
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.0;
};
@ -98,13 +99,11 @@ fn test5_drop_non_drop_aggregate_need_migration() {
// Test migration analysis in case of Significant and Insignificant Drop aggregates.
fn test6_significant_insignificant_drop_aggregate_need_migration() {
struct S(i32, i32);
let t = (Foo(0), String::new());
let c = || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = &t` causes `t` to be fully captured
let _t = t.1;
};
@ -118,8 +117,8 @@ fn test7_move_closures_non_copy_types_might_need_migration() {
let t1 = (Foo(0), Foo(0), Foo(0));
let c = move || {
//~^ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: drop(&(t1, t));
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: `let _ = (&t1, &t)` causes `t1`, `t` to be fully captured
println!("{:?} {:?}", t1.1, t.1);
};

View File

@ -1,5 +1,5 @@
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:24:13
--> $DIR/significant_drop.rs:25:13
|
LL | let c = || {
| _____________^
@ -12,14 +12,22 @@ LL | | };
| |_____^
|
note: the lint level is defined here
--> $DIR/significant_drop.rs:1:9
--> $DIR/significant_drop.rs:2:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: drop(&(t, t1, t2));
help: `let _ = (&t, &t1, &t2)` causes `t`, `t1`, `t2` to be fully captured
|
LL | let c = || { let _ = (&t, &t1, &t2); {
LL |
LL |
LL | let _t = t.0;
LL | let _t1 = t1.0;
LL | let _t2 = t2.0;
...
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:42:13
--> $DIR/significant_drop.rs:43:13
|
LL | let c = || {
| _____________^
@ -31,10 +39,18 @@ LL | | let _t2 = t2;
LL | | };
| |_____^
|
= note: drop(&(t, t1));
help: `let _ = (&t, &t1)` causes `t`, `t1` to be fully captured
|
LL | let c = || { let _ = (&t, &t1); {
LL |
LL |
LL | let _t = t.0;
LL | let _t1 = t1.0;
LL | let _t2 = t2;
...
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:58:13
--> $DIR/significant_drop.rs:59:13
|
LL | let c = || {
| _____________^
@ -45,10 +61,18 @@ LL | | println!("{:?}", t1.1);
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | println!("{:?}", t1.1);
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:75:13
--> $DIR/significant_drop.rs:76:13
|
LL | let c = || {
| _____________^
@ -58,10 +82,17 @@ LL | | let _t = t.0;
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:90:13
--> $DIR/significant_drop.rs:91:13
|
LL | let c = || {
| _____________^
@ -71,10 +102,17 @@ LL | | let _t = t.0;
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.0;
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:105:13
--> $DIR/significant_drop.rs:104:13
|
LL | let c = || {
| _____________^
@ -84,10 +122,17 @@ LL | | let _t = t.1;
LL | | };
| |_____^
|
= note: drop(&(t));
help: `let _ = &t` causes `t` to be fully captured
|
LL | let c = || { let _ = &t; {
LL |
LL |
LL | let _t = t.1;
LL | } };
|
error: drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/significant_drop.rs:120:13
--> $DIR/significant_drop.rs:119:13
|
LL | let c = move || {
| _____________^
@ -97,7 +142,14 @@ LL | | println!("{:?} {:?}", t1.1, t.1);
LL | | };
| |_____^
|
= note: drop(&(t1, t));
help: `let _ = (&t1, &t)` causes `t1`, `t` to be fully captured
|
LL | let c = move || { let _ = (&t1, &t); {
LL |
LL |
LL | println!("{:?} {:?}", t1.1, t.1);
LL | } };
|
error: aborting due to 7 previous errors