Skip to content

Commit 9d22610

Browse files
Address review comments
1 parent 7e528cc commit 9d22610

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

library/core/src/iter/adapters/map_windows.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ impl<T: Clone, const N: usize> Clone for Buffer<T, N> {
207207
});
208208

209209
// `clone()` could panic; `ManuallyDrop` guards against that.
210-
// (We could instead just construct `self.as_array_ref().clone()`
211-
// as a local on the stack before creating the buffer.
212-
// That would avoid the leak amplification,
213-
// but maybe also make it harder to optimize out the local/temporary?)
214210
buffer.as_uninit_array_mut().write(self.as_array_ref().clone());
215211

216212
// We initialized the buffer above, so we are good now

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,20 @@ mod drop_checks {
147147
/// Regression test for #156501
148148
#[test]
149149
fn panicking_clone() {
150+
static CLONE_COUNTER: AtomicUsize = AtomicUsize::new(0);
150151
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
151152

152153
struct PanickingClone(u8);
153154

154155
impl Clone for PanickingClone {
155156
fn clone(&self) -> Self {
156-
panic!(
157-
"⚞(· <:::> ·)⚟ aaaaaah its the turbofish monster!!! its gonna eat us all!!!1!"
158-
);
157+
if CLONE_COUNTER.fetch_add(1, Relaxed) == 3 {
158+
panic!(
159+
"⚞(· <:::> ·)⚟ aaaaaah its the turbofish monster!!! its gonna eat us all!!!1!"
160+
);
161+
}
162+
163+
Self(self.0)
159164
}
160165
}
161166

@@ -181,8 +186,7 @@ mod drop_checks {
181186

182187
assert!(result.is_err());
183188

184-
// current impl does leak amplification
185-
assert_eq!(DROP_COUNTER.load(Relaxed), 0);
189+
assert_eq!(DROP_COUNTER.load(Relaxed), 3);
186190
}
187191
}
188192

0 commit comments

Comments
 (0)