]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / run-pass / borrowck / borrowck-unsafe-static-mutable-borrows.rs
CommitLineData
54a0048b 1// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
abe05a73 11// revisions: ast mir
ff7c6d11 12//[mir]compile-flags: -Z borrowck=mir
5bcae85e 13
abe05a73
XL
14// Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)
15
16struct Foo { x: [usize; 2] }
17
18static mut SFOO: Foo = Foo { x: [23, 32] };
5bcae85e
SL
19
20impl Foo {
abe05a73 21 fn x(&mut self) -> &mut usize { &mut self.x[0] }
5bcae85e 22}
a7813a04
XL
23
24fn main() {
abe05a73
XL
25 unsafe {
26 let sfoo: *mut Foo = &mut SFOO;
27 let x = (*sfoo).x();
28 (*sfoo).x[1] += 1;
29 *x += 1;
30 }
54a0048b 31}