]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_no_migrations.rs
Rollup merge of #107248 - erikdesjardins:addrspace, r=oli-obk
[rust.git] / tests / ui / closures / 2229_closure_analysis / migrations / insignificant_drop_attr_no_migrations.rs
1 // run-pass
2
3 #![deny(rust_2021_incompatible_closure_captures)]
4 #![feature(rustc_attrs)]
5 #![allow(unused)]
6 #[rustc_insignificant_dtor]
7
8 struct InsignificantDropPoint {
9     x: i32,
10     y: i32,
11 }
12
13 impl Drop for InsignificantDropPoint {
14     fn drop(&mut self) {}
15 }
16
17 struct GenericStruct<T>(T, T);
18
19 // No drop reordering is required as the elements of `t` implement insignificant drop
20 fn insignificant_drop_does_not_need_migration() {
21     let t = (InsignificantDropPoint { x: 4, y: 9 }, InsignificantDropPoint { x: 4, y: 9 });
22
23     let c = || {
24         let _t = t.0;
25     };
26
27     c();
28 }
29
30 // Generic struct whose elements don't have significant drops don't need drop reordering
31 fn generic_struct_with_insignificant_drop_does_not_need_migration() {
32     let t =
33         GenericStruct(InsignificantDropPoint { x: 4, y: 9 }, InsignificantDropPoint { x: 4, y: 9 });
34
35     let c = || {
36         let _t = t.0;
37     };
38
39     c();
40 }
41
42 fn main() {
43     insignificant_drop_does_not_need_migration();
44     generic_struct_with_insignificant_drop_does_not_need_migration();
45 }