summaryrefslogtreecommitdiffstats
path: root/library/core/tests/array.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /library/core/tests/array.rs
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/tests/array.rs')
-rw-r--r--library/core/tests/array.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs
index f268fe3ae..5327e4f81 100644
--- a/library/core/tests/array.rs
+++ b/library/core/tests/array.rs
@@ -700,3 +700,28 @@ fn array_into_iter_rfold() {
let s = it.rfold(10, |a, b| 10 * a + b);
assert_eq!(s, 10432);
}
+
+#[cfg(not(panic = "abort"))]
+#[test]
+fn array_map_drops_unmapped_elements_on_panic() {
+ struct DropCounter<'a>(usize, &'a AtomicUsize);
+ impl Drop for DropCounter<'_> {
+ fn drop(&mut self) {
+ self.1.fetch_add(1, Ordering::SeqCst);
+ }
+ }
+
+ const MAX: usize = 11;
+ for panic_after in 0..MAX {
+ let counter = AtomicUsize::new(0);
+ let a = array::from_fn::<_, 11, _>(|i| DropCounter(i, &counter));
+ let success = std::panic::catch_unwind(|| {
+ let _ = a.map(|x| {
+ assert!(x.0 < panic_after);
+ assert_eq!(counter.load(Ordering::SeqCst), x.0);
+ });
+ });
+ assert!(success.is_err());
+ assert_eq!(counter.load(Ordering::SeqCst), MAX);
+ }
+}