3 #![deny(rust_2021_incompatible_closure_captures)]
4 //~^ NOTE: the lint level is defined here
5 #![feature(rustc_attrs)]
8 struct InsignificantDropPoint {
13 impl Drop for InsignificantDropPoint {
14 #[rustc_insignificant_dtor]
20 impl Drop for SigDrop {
24 struct GenericStruct<T>(T, T);
26 struct Wrapper<T>(GenericStruct<T>, i32);
28 impl<T> Drop for GenericStruct<T> {
29 #[rustc_insignificant_dtor]
33 // `SigDrop` implements drop and therefore needs to be migrated.
34 fn significant_drop_needs_migration() {
35 let t = (SigDrop {}, SigDrop {});
37 let c = || { let _ = &t;
38 //~^ ERROR: drop order
39 //~| NOTE: for more information, see
40 //~| HELP: add a dummy let to cause `t` to be fully captured
42 //~^ NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0`
47 //~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.0` would be dropped here alongside the closure
49 // Even if a type implements an insignificant drop, if it's
50 // elements have a significant drop then the overall type is
51 // consdered to have an significant drop. Since the elements
52 // of `GenericStruct` implement drop, migration is required.
53 fn generic_struct_with_significant_drop_needs_migration() {
54 let t = Wrapper(GenericStruct(SigDrop {}, SigDrop {}), 5);
56 // move is used to force i32 to be copied instead of being a ref
57 let c = move || { let _ = &t;
58 //~^ ERROR: drop order
59 //~| NOTE: for more information, see
60 //~| HELP: add a dummy let to cause `t` to be fully captured
62 //~^ NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.1`
67 //~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.1` would be dropped here alongside the closure
70 significant_drop_needs_migration();
71 generic_struct_with_significant_drop_needs_migration();