fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// run-rustfix 2 3#![deny(rust_2021_incompatible_closure_captures)] 4//~^ NOTE: the lint level is defined here 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 = || { 21 let _ = &t; 22 //~^ ERROR: drop order 23 //~| NOTE: for more information, see 24 //~| HELP: add a dummy let to cause `t` to be fully captured 25 let _t = t.0; 26 //~^ NOTE: in Rust 2018, this closure captures all of `t`, but in Rust 2021, it will only capture `t.0` 27 let _t = &t.1; 28 }; 29 30 c(); 31} 32//~^ NOTE: in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.0` will be dropped here as part of the closure 33 34struct S; 35impl Drop for S { 36 fn drop(&mut self) {} 37} 38 39struct T(S, S); 40struct U(T, T); 41 42// Test precise analysis for the lint works with paths longer than one. 43fn test_precise_analysis_long_path_missing() { 44 let u = U(T(S, S), T(S, S)); 45 46 let c = || { 47 let _ = &u; 48 //~^ ERROR: drop order 49 //~| NOTE: for more information, see 50 //~| HELP: add a dummy let to cause `u` to be fully captured 51 let _x = u.0.0; 52 //~^ NOTE: in Rust 2018, this closure captures all of `u`, but in Rust 2021, it will only capture `u.0.0` 53 let _x = u.0.1; 54 //~^ NOTE: in Rust 2018, this closure captures all of `u`, but in Rust 2021, it will only capture `u.0.1` 55 let _x = u.1.0; 56 //~^ NOTE: in Rust 2018, this closure captures all of `u`, but in Rust 2021, it will only capture `u.1.0` 57 }; 58 59 c(); 60} 61//~^ NOTE: in Rust 2018, `u` is dropped here, but in Rust 2021, only `u.0.0` will be dropped here as part of the closure 62//~| NOTE: in Rust 2018, `u` is dropped here, but in Rust 2021, only `u.0.1` will be dropped here as part of the closure 63//~| NOTE: in Rust 2018, `u` is dropped here, but in Rust 2021, only `u.1.0` will be dropped here as part of the closure 64 65 66fn main() { 67 test_precise_analysis_drop_paths_not_captured_by_move(); 68 test_precise_analysis_long_path_missing(); 69}