Skip to content

Commit aa896b6

Browse files
committed
two-phase-reservation-sharing-interference.rs variant that is perhaps more surprising.
1 parent 155367a commit aa896b6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2017 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+
// revisions: lxl nll
12+
//[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows
13+
//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll
14+
15+
// This is similar to two-phase-reservation-sharing-interference.rs
16+
// in that it shows a reservation that overlaps with a shared borrow.
17+
//
18+
// However, it is also more immediately concerning because one would
19+
// intutively think that if run-pass/borrowck/two-phase-baseline.rs
20+
// works, then this *should* work too.
21+
//
22+
// As before, the current implementation is (probably) more
23+
// conservative than is necessary.
24+
//
25+
// So this test is just making a note of the current behavior, with
26+
// the caveat that in the future, the rules may be loosened, at which
27+
// point this test might be thrown out.
28+
29+
fn main() {
30+
let mut v = vec![0, 1, 2];
31+
let shared = &v;
32+
33+
v.push(shared.len());
34+
//[lxl]~^ ERROR cannot borrow `v` as mutable because it is also borrowed as immutable [E0502]
35+
//[nll]~^^ ERROR cannot borrow `v` as mutable because it is also borrowed as immutable [E0502]
36+
37+
assert_eq!(v, [0, 1, 2, 3]);
38+
}

0 commit comments

Comments
 (0)