Make ui/issues/issue-17263.rs
robust w.r.t. NLL.
This commit is contained in:
parent
cd52b3c2dc
commit
affddf68c6
@ -16,7 +16,7 @@ LL | let (c, d) = (&mut foo.a, &foo.b);
|
||||
| ----- ^^^^^ immutable borrow occurs here (via `foo.b`)
|
||||
| |
|
||||
| mutable borrow occurs here (via `foo.a`)
|
||||
LL | //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable
|
||||
...
|
||||
LL | }
|
||||
| - mutable borrow ends here
|
||||
|
@ -1,12 +1,12 @@
|
||||
error: compilation successful
|
||||
--> $DIR/issue-17263.rs:15:1
|
||||
|
|
||||
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
|
||||
LL | / fn main() { //[nll]~ ERROR compilation successful
|
||||
LL | | let mut x: Box<_> = box Foo { a: 1, b: 2 };
|
||||
LL | | let (a, b) = (&mut x.a, &mut x.b);
|
||||
LL | | //~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time
|
||||
LL | | //[ast]~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time
|
||||
... |
|
||||
LL | | //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable
|
||||
LL | | use_mut(a);
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
|
@ -1,23 +1,35 @@
|
||||
// Copyright 2014 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.
|
||||
// This checks diagnostic quality for cases where AST-borrowck treated
|
||||
// `Box<T>` as other types (see rust-lang/rfcs#130). NLL again treats
|
||||
// `Box<T>` specially. We capture the differences via revisions.
|
||||
|
||||
// revisions: ast nll
|
||||
//[ast]compile-flags: -Z borrowck=ast
|
||||
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
|
||||
|
||||
// don't worry about the --compare-mode=nll on this test.
|
||||
// ignore-compare-mode-nll
|
||||
#![feature(box_syntax, rustc_attrs)]
|
||||
|
||||
struct Foo { a: isize, b: isize }
|
||||
|
||||
fn main() { #![rustc_error] // rust-lang/rust#49855
|
||||
#[rustc_error] // rust-lang/rust#49855
|
||||
fn main() { //[nll]~ ERROR compilation successful
|
||||
let mut x: Box<_> = box Foo { a: 1, b: 2 };
|
||||
let (a, b) = (&mut x.a, &mut x.b);
|
||||
//~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time
|
||||
//[ast]~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time
|
||||
|
||||
let mut foo: Box<_> = box Foo { a: 1, b: 2 };
|
||||
let (c, d) = (&mut foo.a, &foo.b);
|
||||
//~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable
|
||||
//[ast]~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable
|
||||
|
||||
// We explicitly use the references created above to illustrate
|
||||
// that NLL is accepting this code *not* because of artificially
|
||||
// short lifetimes, but rather because it understands that all the
|
||||
// references are of disjoint parts of memory.
|
||||
use_imm(d);
|
||||
use_mut(c);
|
||||
use_mut(b);
|
||||
use_mut(a);
|
||||
}
|
||||
|
||||
fn use_mut<T>(_: &mut T) { }
|
||||
fn use_imm<T>(_: &T) { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user