]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/qualif-union.rs
Do not suggest `let_else` if no bindings would be introduced
[rust.git] / src / test / ui / consts / qualif-union.rs
1 // Checks that unions use type based qualification. Regression test for issue #90268.
2 #![feature(untagged_unions)]
3 use std::cell::Cell;
4
5 union U { i: u32, c: Cell<u32> }
6
7 const C1: Cell<u32> = {
8     unsafe { U { c: Cell::new(0) }.c }
9 };
10
11 const C2: Cell<u32> = {
12     unsafe { U { i : 0 }.c }
13 };
14
15 const C3: Cell<u32> = {
16     let mut u = U { i: 0 };
17     u.i = 1;
18     unsafe { u.c }
19 };
20
21 const C4: U = U { i: 0 };
22
23 const C5: [U; 1] = [U {i : 0}; 1];
24
25 fn main() {
26     // Interior mutability should prevent promotion.
27     let _: &'static _ = &C1; //~ ERROR temporary value dropped while borrowed
28     let _: &'static _ = &C2; //~ ERROR temporary value dropped while borrowed
29     let _: &'static _ = &C3; //~ ERROR temporary value dropped while borrowed
30     let _: &'static _ = &C4; //~ ERROR temporary value dropped while borrowed
31     let _: &'static _ = &C5; //~ ERROR temporary value dropped while borrowed
32 }