|
| 1 | +// edition:2021 |
| 2 | + |
| 3 | +// Tests that in cases where we individually capture all the fields of a type, |
| 4 | +// we still drop them in the order they would have been dropped in the 2018 edition. |
| 5 | + |
| 6 | +#![feature(rustc_attrs)] |
| 7 | + |
| 8 | +#[derive(Debug)] |
| 9 | +struct HasDrop; |
| 10 | +impl Drop for HasDrop { |
| 11 | + fn drop(&mut self) { |
| 12 | + println!("dropped"); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +fn test_one() { |
| 17 | + let a = (HasDrop, HasDrop); |
| 18 | + let b = (HasDrop, HasDrop); |
| 19 | + |
| 20 | + let c = #[rustc_capture_analysis] |
| 21 | + //~^ ERROR: attributes on expressions are experimental |
| 22 | + //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> |
| 23 | + || { |
| 24 | + //~^ ERROR: First Pass analysis includes: |
| 25 | + //~| ERROR: Min Capture analysis includes: |
| 26 | + println!("{:?}", a.0); |
| 27 | + //~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow |
| 28 | + //~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow |
| 29 | + println!("{:?}", a.1); |
| 30 | + //~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow |
| 31 | + //~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow |
| 32 | + |
| 33 | + println!("{:?}", b.0); |
| 34 | + //~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow |
| 35 | + //~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow |
| 36 | + println!("{:?}", b.1); |
| 37 | + //~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow |
| 38 | + //~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow |
| 39 | + }; |
| 40 | +} |
| 41 | + |
| 42 | +fn test_two() { |
| 43 | + let a = (HasDrop, HasDrop); |
| 44 | + let b = (HasDrop, HasDrop); |
| 45 | + |
| 46 | + let c = #[rustc_capture_analysis] |
| 47 | + //~^ ERROR: attributes on expressions are experimental |
| 48 | + //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> |
| 49 | + || { |
| 50 | + //~^ ERROR: First Pass analysis includes: |
| 51 | + //~| ERROR: Min Capture analysis includes: |
| 52 | + println!("{:?}", a.1); |
| 53 | + //~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow |
| 54 | + //~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow |
| 55 | + println!("{:?}", a.0); |
| 56 | + //~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow |
| 57 | + //~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow |
| 58 | + |
| 59 | + println!("{:?}", b.1); |
| 60 | + //~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow |
| 61 | + //~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow |
| 62 | + println!("{:?}", b.0); |
| 63 | + //~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow |
| 64 | + //~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow |
| 65 | + }; |
| 66 | +} |
| 67 | + |
| 68 | +fn test_three() { |
| 69 | + let a = (HasDrop, HasDrop); |
| 70 | + let b = (HasDrop, HasDrop); |
| 71 | + |
| 72 | + let c = #[rustc_capture_analysis] |
| 73 | + //~^ ERROR: attributes on expressions are experimental |
| 74 | + //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> |
| 75 | + || { |
| 76 | + //~^ ERROR: First Pass analysis includes: |
| 77 | + //~| ERROR: Min Capture analysis includes: |
| 78 | + println!("{:?}", b.1); |
| 79 | + //~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow |
| 80 | + //~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow |
| 81 | + println!("{:?}", a.1); |
| 82 | + //~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow |
| 83 | + //~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow |
| 84 | + println!("{:?}", a.0); |
| 85 | + //~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow |
| 86 | + //~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow |
| 87 | + |
| 88 | + println!("{:?}", b.0); |
| 89 | + //~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow |
| 90 | + //~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow |
| 91 | + }; |
| 92 | +} |
| 93 | + |
| 94 | +fn main() { |
| 95 | + test_one(); |
| 96 | + test_two(); |
| 97 | + test_three(); |
| 98 | +} |
0 commit comments