From 75fe727b785b43c5f31601adc19233d2efb186f0 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 11 Dec 2016 18:51:22 -0800 Subject: Implement RFC #1725 cc #37955 --- src/libcoretest/lib.rs | 1 + src/libcoretest/ptr.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'src/libcoretest') diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index b8c01e570f5..5b6686309a4 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -36,6 +36,7 @@ #![feature(iter_min_by)] #![feature(ordering_chaining)] #![feature(result_unwrap_or_default)] +#![feature(ptr_unaligned)] extern crate core; extern crate test; diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs index f7fe61896f8..7f6f472bfbb 100644 --- a/src/libcoretest/ptr.rs +++ b/src/libcoretest/ptr.rs @@ -9,6 +9,7 @@ // except according to those terms. use core::ptr::*; +use core::cell::RefCell; #[test] fn test() { @@ -189,3 +190,25 @@ pub fn test_variadic_fnptr() { let mut s = SipHasher::new(); assert_eq!(p.hash(&mut s), q.hash(&mut s)); } + +#[test] +fn write_unaligned_drop() { + thread_local! { + static DROPS: RefCell> = RefCell::new(Vec::new()); + } + + struct Dropper(u32); + + impl Drop for Dropper { + fn drop(&mut self) { + DROPS.with(|d| d.borrow_mut().push(self.0)); + } + } + + { + let c = Dropper(0); + let mut t = Dropper(1); + unsafe { write_unaligned(&mut t, c); } + } + DROPS.with(|d| assert_eq!(*d.borrow(), [0])); +} -- cgit 1.4.1-3-g733a5