Skip to content

Commit

Permalink
Test that autoref'ing beyond method receivers does not leak into two-…
Browse files Browse the repository at this point in the history
…phase borrows.
  • Loading branch information
pnkfelix committed Feb 8, 2018
1 parent c8041dd commit 81b93fa
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/test/compile-fail/borrowck/two-phase-nonrecv-autoref.rs
@@ -0,0 +1,39 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: lxl nll g2p
//[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows
//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll
//[g2p]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll -Z two-phase-beyond-autoref

#![feature(rustc_attrs)]

// This is a test checking that when we limit two-phase borrows to
// method receivers, we do not let other kinds of auto-ref to leak
// through.
//
// The g2p revision illustrates the "undesirable" behavior you would
// otherwise observe without limiting the phasing to autoref on method
// receivers (namely, that the test would pass).

fn bar(x: &mut u32) {
foo(x, *x);
//[lxl]~^ ERROR cannot use `*x` because it was mutably borrowed [E0503]
//[nll]~^^ ERROR cannot use `*x` because it was mutably borrowed [E0503]
}

fn foo(x: &mut u32, y: u32) {
*x += y;
}

#[rustc_error]
fn main() { //[g2p]~ ERROR compilation successful
bar(&mut 5);
}

0 comments on commit 81b93fa

Please sign in to comment.