|
1 |
| -// Copyright 2014 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. |
| 1 | +// This checks diagnostic quality for cases where AST-borrowck treated |
| 2 | +// `Box<T>` as other types (see rust-lang/rfcs#130). NLL again treats |
| 3 | +// `Box<T>` specially. We capture the differences via revisions. |
10 | 4 |
|
| 5 | +// revisions: ast nll |
| 6 | +//[ast]compile-flags: -Z borrowck=ast |
| 7 | +//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows |
| 8 | + |
| 9 | +// don't worry about the --compare-mode=nll on this test. |
| 10 | +// ignore-compare-mode-nll |
11 | 11 | #![feature(box_syntax, rustc_attrs)]
|
12 | 12 |
|
13 | 13 | struct Foo { a: isize, b: isize }
|
14 |
| - |
15 |
| -fn main() { #![rustc_error] // rust-lang/rust#49855 |
| 14 | +#[rustc_error] // rust-lang/rust#49855 |
| 15 | +fn main() { //[nll]~ ERROR compilation successful |
16 | 16 | let mut x: Box<_> = box Foo { a: 1, b: 2 };
|
17 | 17 | let (a, b) = (&mut x.a, &mut x.b);
|
18 |
| - //~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time |
| 18 | + //[ast]~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time |
19 | 19 |
|
20 | 20 | let mut foo: Box<_> = box Foo { a: 1, b: 2 };
|
21 | 21 | let (c, d) = (&mut foo.a, &foo.b);
|
22 |
| - //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable |
| 22 | + //[ast]~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable |
| 23 | + |
| 24 | + // We explicitly use the references created above to illustrate |
| 25 | + // that NLL is accepting this code *not* because of artificially |
| 26 | + // short lifetimes, but rather because it understands that all the |
| 27 | + // references are of disjoint parts of memory. |
| 28 | + use_imm(d); |
| 29 | + use_mut(c); |
| 30 | + use_mut(b); |
| 31 | + use_mut(a); |
23 | 32 | }
|
| 33 | + |
| 34 | +fn use_mut<T>(_: &mut T) { } |
| 35 | +fn use_imm<T>(_: &T) { } |
0 commit comments