]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/qualif-union.rs
Rollup merge of #106962 - compiler-errors:use-sugg-span, r=oli-obk
[rust.git] / tests / ui / consts / qualif-union.rs
1 // Checks that unions use type based qualification. Regression test for issue #90268.
2
3 use std::cell::Cell;
4 use std::mem::ManuallyDrop;
5
6 union U { i: u32, c: ManuallyDrop<Cell<u32>> }
7
8 const C1: ManuallyDrop<Cell<u32>> = {
9     unsafe { U { c: ManuallyDrop::new(Cell::new(0)) }.c }
10 };
11
12 const C2: ManuallyDrop<Cell<u32>> = {
13     unsafe { U { i : 0 }.c }
14 };
15
16 const C3: ManuallyDrop<Cell<u32>> = {
17     let mut u = U { i: 0 };
18     u.i = 1;
19     unsafe { u.c }
20 };
21
22 const C4: U = U { i: 0 };
23
24 const C5: [U; 1] = [U {i : 0}; 1];
25
26 fn main() {
27     // Interior mutability should prevent promotion.
28     let _: &'static _ = &C1; //~ ERROR temporary value dropped while borrowed
29     let _: &'static _ = &C2; //~ ERROR temporary value dropped while borrowed
30     let _: &'static _ = &C3; //~ ERROR temporary value dropped while borrowed
31     let _: &'static _ = &C4; //~ ERROR temporary value dropped while borrowed
32     let _: &'static _ = &C5; //~ ERROR temporary value dropped while borrowed
33 }