]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-69114-static-mut-ty.rs
Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote
[rust.git] / src / test / ui / nll / issue-69114-static-mut-ty.rs
1 // Check that borrowck ensures that `static mut` items have the expected type.
2
3 static FOO: u8 = 42;
4 static mut BAR: &'static u8 = &FOO;
5 static mut BAR_ELIDED: &u8 = &FOO;
6
7 fn main() {
8     unsafe {
9         println!("{} {}", BAR, BAR_ELIDED);
10         set_bar();
11         set_bar_elided();
12         println!("{} {}", BAR, BAR_ELIDED);
13     }
14 }
15
16 fn set_bar() {
17     let n = 42;
18     unsafe {
19         BAR = &n;
20         //~^ ERROR does not live long enough
21     }
22 }
23
24 fn set_bar_elided() {
25     let n = 42;
26     unsafe {
27         BAR_ELIDED = &n;
28         //~^ ERROR does not live long enough
29     }
30 }