]> git.proxmox.com Git - rustc.git/blame - src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.rs
New upstream version 1.56.0~beta.4+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / migrations / insignificant_drop_attr_migrations.rs
CommitLineData
17df50a5
XL
1// run-rustfix
2
136023e0 3#![deny(rust_2021_incompatible_closure_captures)]
17df50a5 4//~^ NOTE: the lint level is defined here
17df50a5
XL
5#![feature(rustc_attrs)]
6#![allow(unused)]
7
94222f64
XL
8use std::sync::Mutex;
9
10 #[rustc_insignificant_dtor]
17df50a5
XL
11struct InsignificantDropPoint {
12 x: i32,
94222f64 13 y: Mutex<i32>,
17df50a5
XL
14}
15
16impl Drop for InsignificantDropPoint {
17df50a5
XL
17 fn drop(&mut self) {}
18}
19
20struct SigDrop;
21
22impl Drop for SigDrop {
23 fn drop(&mut self) {}
24}
25
94222f64 26#[rustc_insignificant_dtor]
17df50a5
XL
27struct GenericStruct<T>(T, T);
28
17df50a5 29impl<T> Drop for GenericStruct<T> {
17df50a5
XL
30 fn drop(&mut self) {}
31}
32
94222f64
XL
33struct Wrapper<T>(GenericStruct<T>, i32);
34
17df50a5
XL
35// `SigDrop` implements drop and therefore needs to be migrated.
36fn significant_drop_needs_migration() {
37 let t = (SigDrop {}, SigDrop {});
38
39 let c = || {
136023e0
XL
40 //~^ ERROR: drop order
41 //~| NOTE: for more information, see
42 //~| HELP: add a dummy let to cause `t` to be fully captured
17df50a5 43 let _t = t.0;
94222f64 44 //~^ NOTE: in Rust 2018, this closure captures all of `t`, but in Rust 2021, it will only capture `t.0`
17df50a5
XL
45 };
46
47 c();
48}
94222f64 49//~^ NOTE: in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.0` will be dropped here as part of the closure
17df50a5
XL
50
51// Even if a type implements an insignificant drop, if it's
52// elements have a significant drop then the overall type is
53// consdered to have an significant drop. Since the elements
54// of `GenericStruct` implement drop, migration is required.
55fn generic_struct_with_significant_drop_needs_migration() {
56 let t = Wrapper(GenericStruct(SigDrop {}, SigDrop {}), 5);
57
58 // move is used to force i32 to be copied instead of being a ref
59 let c = move || {
136023e0
XL
60 //~^ ERROR: drop order
61 //~| NOTE: for more information, see
62 //~| HELP: add a dummy let to cause `t` to be fully captured
17df50a5 63 let _t = t.1;
94222f64 64 //~^ NOTE: in Rust 2018, this closure captures all of `t`, but in Rust 2021, it will only capture `t.1`
17df50a5
XL
65 };
66
67 c();
68}
94222f64 69//~^ NOTE: in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.1` will be dropped here as part of the closure
17df50a5
XL
70
71fn main() {
72 significant_drop_needs_migration();
73 generic_struct_with_significant_drop_needs_migration();
74}