Skip to content

Commit 81b93fa

Browse files
committed
Test that autoref'ing beyond method receivers does not leak into two-phase borrows.
1 parent c8041dd commit 81b93fa

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 g2p
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+
//[g2p]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll -Z two-phase-beyond-autoref
15+
16+
#![feature(rustc_attrs)]
17+
18+
// This is a test checking that when we limit two-phase borrows to
19+
// method receivers, we do not let other kinds of auto-ref to leak
20+
// through.
21+
//
22+
// The g2p revision illustrates the "undesirable" behavior you would
23+
// otherwise observe without limiting the phasing to autoref on method
24+
// receivers (namely, that the test would pass).
25+
26+
fn bar(x: &mut u32) {
27+
foo(x, *x);
28+
//[lxl]~^ ERROR cannot use `*x` because it was mutably borrowed [E0503]
29+
//[nll]~^^ ERROR cannot use `*x` because it was mutably borrowed [E0503]
30+
}
31+
32+
fn foo(x: &mut u32, y: u32) {
33+
*x += y;
34+
}
35+
36+
#[rustc_error]
37+
fn main() { //[g2p]~ ERROR compilation successful
38+
bar(&mut 5);
39+
}

0 commit comments

Comments
 (0)