Skip to content

Commit

Permalink
Rollup merge of rust-lang#83827 - the8472:fix-inplace-panic-on-drop, …
Browse files Browse the repository at this point in the history
…r=RalfJung

cleanup leak after test to make miri happy

Contains changes that were requested in rust-lang#83629 but didn't make it into the rollup.

r? ```@RalfJung```
  • Loading branch information
GuillaumeGomez authored Apr 4, 2021
2 parents 8e37df4 + 572873f commit e00fb1c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,21 @@ fn test_from_iter_specialization_panic_during_drop_leaks() {
}
}

let mut to_free: *mut Droppable = core::ptr::null_mut();
let mut cap = 0;

let _ = std::panic::catch_unwind(AssertUnwindSafe(|| {
let v = vec![Droppable::DroppedTwice(Box::new(123)), Droppable::PanicOnDrop];
let mut v = vec![Droppable::DroppedTwice(Box::new(123)), Droppable::PanicOnDrop];
to_free = v.as_mut_ptr();
cap = v.capacity();
let _ = v.into_iter().take(0).collect::<Vec<_>>();
}));

assert_eq!(unsafe { DROP_COUNTER }, 1);
// clean up the leak to keep miri happy
unsafe {
drop(Vec::from_raw_parts(to_free, 0, cap));
}
}

#[test]
Expand Down

0 comments on commit e00fb1c

Please sign in to comment.