rust/tests/ui/union/union-fields-1.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
792 B
Rust
Raw Normal View History

// revisions: mirunsafeck thirunsafeck
// [thirunsafeck]compile-flags: -Z thir-unsafeck
2017-07-21 23:17:53 +00:00
#![deny(dead_code)]
2017-08-06 15:19:15 +00:00
union U1 {
a: u8, // should not be reported
b: u8, // should not be reported
c: u8, //~ ERROR field `c` is never read
2017-07-21 23:17:53 +00:00
}
2017-08-06 15:19:15 +00:00
union U2 {
a: u8, //~ ERROR field `a` is never read
2017-08-06 15:19:15 +00:00
b: u8, // should not be reported
c: u8, // should not be reported
2017-07-21 23:17:53 +00:00
}
union NoDropLike { a: u8 } //~ ERROR field `a` is never read
2017-07-21 23:17:53 +00:00
2017-08-06 18:46:32 +00:00
union U {
a: u8, // should not be reported
b: u8, // should not be reported
c: u8, //~ ERROR field `c` is never read
2017-08-06 18:46:32 +00:00
}
type A = U;
2017-07-21 23:17:53 +00:00
fn main() {
2017-08-06 15:19:15 +00:00
let u = U1 { a: 0 };
let _a = unsafe { u.b };
2017-07-21 23:17:53 +00:00
2017-08-06 15:19:15 +00:00
let u = U2 { c: 0 };
let _b = unsafe { u.b };
let _u = NoDropLike { a: 10 };
2017-08-06 18:46:32 +00:00
let u = A { a: 0 };
let _b = unsafe { u.b };
2017-08-06 15:19:15 +00:00
}