]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.rs
Auto merge of #107663 - matthiaskrgr:107423-point-at-EOF-code, r=compiler-errors
[rust.git] / tests / ui / borrowck / borrowck-unsafe-static-mutable-borrows.rs
1 // run-pass
2
3 // Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)
4
5 struct Foo { x: [usize; 2] }
6
7 static mut SFOO: Foo = Foo { x: [23, 32] };
8
9 impl Foo {
10     fn x(&mut self) -> &mut usize { &mut self.x[0] }
11 }
12
13 fn main() {
14     unsafe {
15         let sfoo: *mut Foo = &mut SFOO;
16         let x = (*sfoo).x();
17         (*sfoo).x[1] += 1;
18         *x += 1;
19     }
20 }