summaryrefslogtreecommitdiffstats
path: root/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs')
-rw-r--r--src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs b/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
deleted file mode 100644
index 0450fe8ab..000000000
--- a/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
+++ /dev/null
@@ -1,69 +0,0 @@
-// run-pass
-// needs-unwind
-// Check that partially moved from function parameters are dropped after the
-// named bindings that move from them.
-
-
-use std::{panic, cell::RefCell};
-
-struct LogDrop<'a>(i32, Context<'a>);
-
-#[derive(Copy, Clone)]
-struct Context<'a> {
- panic_on: i32,
- drops: &'a RefCell<Vec<i32>>,
-}
-
-impl<'a> Context<'a> {
- fn record_drop(self, index: i32) {
- self.drops.borrow_mut().push(index);
- if index == self.panic_on {
- panic!();
- }
- }
-}
-
-impl<'a> Drop for LogDrop<'a> {
- fn drop(&mut self) {
- self.1.record_drop(self.0);
- }
-}
-
-fn bindings_in_params((_x, _): (LogDrop, LogDrop), (_, _y): (LogDrop, LogDrop)) {}
-fn bindings_with_let(a: (LogDrop, LogDrop), b: (LogDrop, LogDrop)) {
- // Drop order in foo is the same as the following bindings.
- // _temp2 is declared after _x to avoid a difference between `_: T` and
- // `x: T` in function parameters.
- let _temp1 = a;
- let (_x, _) = _temp1;
-
- let _temp2 = b;
- let (_, _y) = _temp2;
-}
-
-fn test_drop_order(panic_on: i32, fun: fn((LogDrop, LogDrop), (LogDrop, LogDrop))) {
- let context = Context {
- panic_on,
- drops: &RefCell::new(Vec::new()),
- };
- let one = LogDrop(1, context);
- let two = LogDrop(2, context);
- let three = LogDrop(3, context);
- let four = LogDrop(4, context);
-
- let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
- fun((three, four), (two, one));
- }));
- if panic_on == 0 {
- assert!(res.is_ok(), "should not have panicked");
- } else {
- assert!(res.is_err(), "should have panicked");
- }
- assert_eq!(*context.drops.borrow(), [1, 2, 3, 4], "incorrect drop order");
-}
-
-fn main() {
- (0..=4).for_each(|i| test_drop_order(i, bindings_in_params));
- (0..=4).for_each(|i| test_drop_order(i, bindings_with_let));
- (0..=4).for_each(|i| test_drop_order(i, |(_x, _), (_, _y)| {}));
-}