Skip to content

Commit affddf6

Browse files
committed
Make ui/issues/issue-17263.rs robust w.r.t. NLL.
1 parent cd52b3c commit affddf6

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/test/ui/issues/issue-17263.stderr renamed to src/test/ui/issues/issue-17263.ast.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | let (c, d) = (&mut foo.a, &foo.b);
1616
| ----- ^^^^^ immutable borrow occurs here (via `foo.b`)
1717
| |
1818
| mutable borrow occurs here (via `foo.a`)
19-
LL | //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable
19+
...
2020
LL | }
2121
| - mutable borrow ends here
2222

src/test/ui/issues/issue-17263.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error: compilation successful
22
--> $DIR/issue-17263.rs:15:1
33
|
4-
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
4+
LL | / fn main() { //[nll]~ ERROR compilation successful
55
LL | | let mut x: Box<_> = box Foo { a: 1, b: 2 };
66
LL | | let (a, b) = (&mut x.a, &mut x.b);
7-
LL | | //~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time
7+
LL | | //[ast]~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time
88
... |
9-
LL | | //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable
9+
LL | | use_mut(a);
1010
LL | | }
1111
| |_^
1212

src/test/ui/issues/issue-17263.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
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.
104

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
1111
#![feature(box_syntax, rustc_attrs)]
1212

1313
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
1616
let mut x: Box<_> = box Foo { a: 1, b: 2 };
1717
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
1919

2020
let mut foo: Box<_> = box Foo { a: 1, b: 2 };
2121
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);
2332
}
33+
34+
fn use_mut<T>(_: &mut T) { }
35+
fn use_imm<T>(_: &T) { }

0 commit comments

Comments
 (0)