]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-45697.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / issues / issue-45697.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
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
11 // Test that assignments to an `&mut` pointer which is found in a
12 // borrowed (but otherwise non-aliasable) location is illegal.
13
14 // compile-flags: -Z emit-end-regions -Z borrowck=compare -C overflow-checks=off
15
16 struct S<'a> {
17     pointer: &'a mut isize
18 }
19
20 fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> {
21     S { pointer: &mut *p.pointer }
22 }
23
24 fn main() {
25     let mut x = 1;
26
27     {
28         let mut y = S { pointer: &mut x };
29         let z = copy_borrowed_ptr(&mut y);
30         *y.pointer += 1;
31         //~^ ERROR cannot assign to `*y.pointer` because it is borrowed (Ast) [E0506]
32         //~| ERROR cannot use `*y.pointer` because it was mutably borrowed (Mir) [E0503]
33         //~| ERROR cannot assign to `*y.pointer` because it is borrowed (Mir) [E0506]
34         *z.pointer += 1;
35     }
36 }