summary refs log tree commit diff
path: root/src/test/ui/issues/issue-17263.rs
blob: 754f3b90aacf1f47de9ce15674126dc94370edf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 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 }
#[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);
    //[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);
    //[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) { }