diff options
| author | Steven Fackler <sfackler@gmail.com> | 2016-12-11 18:51:22 -0800 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2016-12-12 21:44:09 -0800 |
| commit | 75fe727b785b43c5f31601adc19233d2efb186f0 (patch) | |
| tree | 601862196601c2f65aca6c8bd8f08ccf9e4a0b96 /src/libcoretest | |
| parent | 3db197aa9d343c7974b06a9b18ae5f78d5c64637 (diff) | |
| download | rust-75fe727b785b43c5f31601adc19233d2efb186f0.tar.gz rust-75fe727b785b43c5f31601adc19233d2efb186f0.zip | |
Implement RFC #1725
cc #37955
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcoretest/ptr.rs | 23 |
2 files changed, 24 insertions, 0 deletions
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<Vec<u32>> = 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])); +} |
