summaryrefslogtreecommitdiffstats
path: root/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs b/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs
new file mode 100644
index 000000000..2f8cddc06
--- /dev/null
+++ b/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs
@@ -0,0 +1,101 @@
+// edition:2021
+
+// Tests that in cases where we individually capture all the fields of a type,
+// we still drop them in the order they would have been dropped in the 2018 edition.
+
+// NOTE: It is *critical* that the order of the min capture NOTES in the stderr output
+// does *not* change!
+
+#![feature(rustc_attrs)]
+
+#[derive(Debug)]
+struct HasDrop;
+impl Drop for HasDrop {
+ fn drop(&mut self) {
+ println!("dropped");
+ }
+}
+
+fn test_one() {
+ let a = (HasDrop, HasDrop);
+ let b = (HasDrop, HasDrop);
+
+ let c = #[rustc_capture_analysis]
+ //~^ ERROR: attributes on expressions are experimental
+ //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
+ || {
+ //~^ ERROR: Min Capture analysis includes:
+ //~| ERROR
+ println!("{:?}", a.0);
+ //~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
+ //~| NOTE
+ println!("{:?}", a.1);
+ //~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
+ //~| NOTE
+
+ println!("{:?}", b.0);
+ //~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
+ //~| NOTE
+ println!("{:?}", b.1);
+ //~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
+ //~| NOTE
+ };
+}
+
+fn test_two() {
+ let a = (HasDrop, HasDrop);
+ let b = (HasDrop, HasDrop);
+
+ let c = #[rustc_capture_analysis]
+ //~^ ERROR: attributes on expressions are experimental
+ //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
+ || {
+ //~^ ERROR: Min Capture analysis includes:
+ //~| ERROR
+ println!("{:?}", a.1);
+ //~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
+ //~| NOTE
+ println!("{:?}", a.0);
+ //~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
+ //~| NOTE
+
+ println!("{:?}", b.1);
+ //~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
+ //~| NOTE
+ println!("{:?}", b.0);
+ //~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
+ //~| NOTE
+ };
+}
+
+fn test_three() {
+ let a = (HasDrop, HasDrop);
+ let b = (HasDrop, HasDrop);
+
+ let c = #[rustc_capture_analysis]
+ //~^ ERROR: attributes on expressions are experimental
+ //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
+ || {
+ //~^ ERROR: Min Capture analysis includes:
+ //~| ERROR
+ println!("{:?}", b.1);
+ //~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
+ //~| NOTE
+ println!("{:?}", a.1);
+ //~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
+ //~| NOTE
+ println!("{:?}", a.0);
+ //~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
+ //~| NOTE
+
+ println!("{:?}", b.0);
+ //~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
+ //~| NOTE
+ };
+}
+
+fn main() {
+ test_one();
+ test_two();
+ test_three();
+}