3 #![deny(rust_2021_incompatible_closure_captures)]
4 //~^ NOTE: the lint level is defined here
5 #![feature(rustc_attrs)]
10 #[rustc_insignificant_dtor]
11 struct InsignificantDropPoint {
16 impl Drop for InsignificantDropPoint {
22 impl Drop for SigDrop {
26 #[rustc_insignificant_dtor]
27 struct GenericStruct<T>(T, T);
29 impl<T> Drop for GenericStruct<T> {
33 struct Wrapper<T>(GenericStruct<T>, i32);
35 // `SigDrop` implements drop and therefore needs to be migrated.
36 fn significant_drop_needs_migration() {
37 let t = (SigDrop {}, SigDrop {});
41 //~^ ERROR: drop order
42 //~| NOTE: for more information, see
43 //~| HELP: add a dummy let to cause `t` to be fully captured
45 //~^ NOTE: in Rust 2018, this closure captures all of `t`, but in Rust 2021, it will only capture `t.0`
50 //~^ NOTE: in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.0` will be dropped here as part of the closure
52 // Even if a type implements an insignificant drop, if it's
53 // elements have a significant drop then the overall type is
54 // consdered to have an significant drop. Since the elements
55 // of `GenericStruct` implement drop, migration is required.
56 fn generic_struct_with_significant_drop_needs_migration() {
57 let t = Wrapper(GenericStruct(SigDrop {}, SigDrop {}), 5);
59 // move is used to force i32 to be copied instead of being a ref
62 //~^ ERROR: drop order
63 //~| NOTE: for more information, see
64 //~| HELP: add a dummy let to cause `t` to be fully captured
66 //~^ NOTE: in Rust 2018, this closure captures all of `t`, but in Rust 2021, it will only capture `t.1`
71 //~^ NOTE: in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.1` will be dropped here as part of the closure
74 significant_drop_needs_migration();
75 generic_struct_with_significant_drop_needs_migration();