]> git.proxmox.com Git - rustc.git/blame - src/test/ui/closures/2229_closure_analysis/migrations/precise.fixed
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / migrations / precise.fixed
CommitLineData
cdc7bbd5
XL
1// run-rustfix
2
136023e0
XL
3#![deny(rust_2021_incompatible_closure_captures)]
4//~^ NOTE: the lint level is defined here
cdc7bbd5
XL
5
6#[derive(Debug)]
7struct Foo(i32);
8impl Drop for Foo {
9 fn drop(&mut self) {
10 println!("{:?} dropped", self.0);
11 }
12}
13
14struct ConstainsDropField(Foo, Foo);
15
16// Test that lint is triggered if a path that implements Drop is not captured by move
17fn test_precise_analysis_drop_paths_not_captured_by_move() {
18 let t = ConstainsDropField(Foo(10), Foo(20));
19
20 let c = || { let _ = &t;
136023e0
XL
21 //~^ ERROR: drop order
22 //~| NOTE: for more information, see
23 //~| HELP: add a dummy let to cause `t` to be fully captured
cdc7bbd5 24 let _t = t.0;
136023e0 25 //~^ NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0`
cdc7bbd5
XL
26 let _t = &t.1;
27 };
28
29 c();
30}
136023e0 31//~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.0` would be dropped here alongside the closure
cdc7bbd5
XL
32
33struct S;
34impl Drop for S {
136023e0 35 fn drop(&mut self) {}
cdc7bbd5
XL
36}
37
38struct T(S, S);
39struct U(T, T);
40
41// Test precise analysis for the lint works with paths longer than one.
42fn test_precise_analysis_long_path_missing() {
43 let u = U(T(S, S), T(S, S));
44
45 let c = || { let _ = &u;
136023e0
XL
46 //~^ ERROR: drop order
47 //~| NOTE: for more information, see
48 //~| HELP: add a dummy let to cause `u` to be fully captured
cdc7bbd5 49 let _x = u.0.0;
136023e0 50 //~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.0`
cdc7bbd5 51 let _x = u.0.1;
136023e0 52 //~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.1`
cdc7bbd5 53 let _x = u.1.0;
136023e0 54 //~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.1.0`
cdc7bbd5
XL
55 };
56
57 c();
58}
136023e0
XL
59//~^ NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.0` would be dropped here alongside the closure
60//~| NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1` would be dropped here alongside the closure
61//~| NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.1.0` would be dropped here alongside the closure
62
cdc7bbd5
XL
63
64fn main() {
65 test_precise_analysis_drop_paths_not_captured_by_move();
66 test_precise_analysis_long_path_missing();
67}