mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
20 lines
349 B
Rust
20 lines
349 B
Rust
// run-pass
|
|
// revisions: mirunsafeck thirunsafeck
|
|
// [thirunsafeck]compile-flags: -Z thir-unsafeck
|
|
|
|
use std::fmt;
|
|
|
|
union U {
|
|
a: u8
|
|
}
|
|
|
|
impl fmt::Display for U {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
unsafe { write!(f, "Oh hai {}", self.a) }
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
assert_eq!(U { a: 2 }.to_string(), "Oh hai 2");
|
|
}
|