Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let mut d = D;
- visit_clobber(&mut d, |_| panic!());
- }
- pub fn visit_clobber<T, F>(t: &mut T, f: F) where F: FnOnce(T) -> T {
- unsafe { std::ptr::write(t, f(std::ptr::read(t))); }
- }
- struct D;
- impl Drop for D {
- fn drop(&mut self) {
- println!("drop");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement