diff options
| author | Jed Davis <jld@panix.com> | 2013-03-11 01:04:08 -0700 |
|---|---|---|
| committer | Jed Davis <jld@panix.com> | 2013-03-13 10:25:49 -0700 |
| commit | a301db7eef71d8f74ba9bd61b9dc4559b3ffc1aa (patch) | |
| tree | a6fe0916ac41f48ed61b556a6f4a32d644b21767 /src/test/run-pass/enum-alignment.rs | |
| parent | 0ad3a110be9070b87ecd7e1c71d20a02660d8959 (diff) | |
| download | rust-a301db7eef71d8f74ba9bd61b9dc4559b3ffc1aa.tar.gz rust-a301db7eef71d8f74ba9bd61b9dc4559b3ffc1aa.zip | |
Represent enums with regular structs; no more alignment-breaking casts.
Diffstat (limited to 'src/test/run-pass/enum-alignment.rs')
| -rw-r--r-- | src/test/run-pass/enum-alignment.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/run-pass/enum-alignment.rs b/src/test/run-pass/enum-alignment.rs new file mode 100644 index 00000000000..5da64367023 --- /dev/null +++ b/src/test/run-pass/enum-alignment.rs @@ -0,0 +1,26 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn addr_of<T>(ptr: &T) -> uint { + let ptr = ptr::addr_of(ptr); + unsafe { ptr as uint } +} + +fn is_aligned<T>(ptr: &T) -> bool { + (addr_of(ptr) % sys::min_align_of::<T>()) == 0 +} + +pub fn main() { + let x = Some(0u64); + match x { + None => fail!(), + Some(ref y) => fail_unless!(is_aligned(y)) + } +} |
