Skip to content

Commit eafd63c

Browse files
Move test to stdlib test suite
1 parent 4a524ec commit eafd63c

3 files changed

Lines changed: 42 additions & 46 deletions

File tree

library/coretests/tests/iter/adapters/map_windows.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::atomic::Ordering::SeqCst;
55
mod drop_checks {
66
//! These tests mainly make sure the elements are correctly dropped.
77
8-
use std::sync::atomic::Ordering::SeqCst;
8+
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
99
use std::sync::atomic::{AtomicBool, AtomicUsize};
1010

1111
#[derive(Debug)]
@@ -143,6 +143,47 @@ mod drop_checks {
143143
check::<5>(5, 1);
144144
check::<5>(5, 4);
145145
}
146+
147+
/// Regression test for #156501
148+
#[test]
149+
fn panicking_clone() {
150+
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
151+
152+
struct PanickingClone(u8);
153+
154+
impl Clone for PanickingClone {
155+
fn clone(&self) -> Self {
156+
panic!(
157+
"⚞(· <:::> ·)⚟ aaaaaah its the turbofish monster!!! its gonna eat us all!!!1!"
158+
);
159+
}
160+
}
161+
162+
impl Drop for PanickingClone {
163+
fn drop(&mut self) {
164+
assert_eq!(self.0, 42);
165+
166+
DROP_COUNTER.fetch_add(1, Relaxed);
167+
}
168+
}
169+
170+
let array = [const { PanickingClone(42) }; 17];
171+
let mut iter = array.into_iter().map_windows::<_, (), 17>(|_| ());
172+
173+
// initialize the buffer
174+
iter.next();
175+
176+
let result = std::panic::catch_unwind(|| {
177+
// now do the clones and panic.
178+
// this should't try to drop uninitialized memory
179+
let _ = iter.clone();
180+
});
181+
182+
assert!(result.is_err());
183+
184+
// current impl does leak amplification
185+
assert_eq!(DROP_COUNTER.load(Relaxed), 0);
186+
}
146187
}
147188

148189
#[test]

src/tools/miri/tests/pass/issues/issue-156501-mapwindows-panicking-clone.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/tools/miri/tests/pass/issues/issue-156501-mapwindows-panicking-clone.stderr

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)