Skip to content

Commit 18195d4

Browse files
authored
Rollup merge of rust-lang#55801 - pnkfelix:update-box-insensitivity-test-for-nll, r=davidtwco
NLL: Update box insensitivity test This is just keeping one of our tests honest with respect to NLL, in two ways: 1. Adds uses of borrows that would otherwise be too short to observe the error that we would have expected to see... 2. ... I say "would have expected" because all of the errors in this file are part of the reversion of rust-lang/rfcs#130 that is attached to NLL (you can see more discussion of this here rust-lang#43234 (comment) )
2 parents ff8ee96 + 9b6a568 commit 18195d4

File tree

3 files changed

+103
-86
lines changed

3 files changed

+103
-86
lines changed

src/test/ui/borrowck/borrowck-box-insensitivity.stderr renamed to src/test/ui/borrowck/borrowck-box-insensitivity.ast.stderr

+25-25
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ error[E0382]: use of moved value: `a`
33
|
44
LL | let _x = a.x;
55
| -- value moved here
6-
LL | //~^ value moved here
7-
LL | let _y = a.y; //~ ERROR use of moved
6+
LL | //[ast]~^ value moved here
7+
LL | let _y = a.y; //[ast]~ ERROR use of moved
88
| ^^ value used here after move
99
|
1010
= note: move occurs because `a.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
@@ -14,8 +14,8 @@ error[E0382]: use of moved value: `a`
1414
|
1515
LL | let _x = a.x;
1616
| -- value moved here
17-
LL | //~^ value moved here
18-
LL | let _y = a.y; //~ ERROR use of moved
17+
LL | //[ast]~^ value moved here
18+
LL | let _y = a.y; //[ast]~ ERROR use of moved
1919
| ^^ value used here after move
2020
|
2121
= note: move occurs because `a.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
@@ -25,8 +25,8 @@ error[E0382]: use of moved value: `a`
2525
|
2626
LL | let _x = a.x;
2727
| -- value moved here
28-
LL | //~^ value moved here
29-
LL | let _y = &a.y; //~ ERROR use of moved
28+
LL | //[ast]~^ value moved here
29+
LL | let _y = &a.y; //[ast]~ ERROR use of moved
3030
| ^^^ value used here after move
3131
|
3232
= note: move occurs because `a.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
@@ -44,7 +44,7 @@ error[E0503]: cannot use `a.y` because it was mutably borrowed
4444
|
4545
LL | let _x = &mut a.x;
4646
| --- borrow of `a.x` occurs here
47-
LL | let _y = a.y; //~ ERROR cannot use
47+
LL | let _y = a.y; //[ast]~ ERROR cannot use
4848
| ^^ use of borrowed `a.x`
4949

5050
error[E0505]: cannot move out of `a.y` because it is borrowed
@@ -60,9 +60,9 @@ error[E0502]: cannot borrow `a` (via `a.y`) as immutable because `a` is also bor
6060
|
6161
LL | let _x = &mut a.x;
6262
| --- mutable borrow occurs here (via `a.x`)
63-
LL | let _y = &a.y; //~ ERROR cannot borrow
63+
LL | let _y = &a.y; //[ast]~ ERROR cannot borrow
6464
| ^^^ immutable borrow occurs here (via `a.y`)
65-
LL | //~^ immutable borrow occurs here (via `a.y`)
65+
...
6666
LL | }
6767
| - mutable borrow ends here
6868

@@ -71,9 +71,9 @@ error[E0502]: cannot borrow `a` (via `a.y`) as mutable because `a` is also borro
7171
|
7272
LL | let _x = &a.x;
7373
| --- immutable borrow occurs here (via `a.x`)
74-
LL | let _y = &mut a.y; //~ ERROR cannot borrow
74+
LL | let _y = &mut a.y; //[ast]~ ERROR cannot borrow
7575
| ^^^ mutable borrow occurs here (via `a.y`)
76-
LL | //~^ mutable borrow occurs here (via `a.y`)
76+
...
7777
LL | }
7878
| - immutable borrow ends here
7979

@@ -82,8 +82,8 @@ error[E0382]: use of collaterally moved value: `a.y`
8282
|
8383
LL | let _x = a.x.x;
8484
| -- value moved here
85-
LL | //~^ value moved here
86-
LL | let _y = a.y; //~ ERROR use of collaterally moved
85+
LL | //[ast]~^ value moved here
86+
LL | let _y = a.y; //[ast]~ ERROR use of collaterally moved
8787
| ^^ value used here after move
8888
|
8989
= note: move occurs because `a.x.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
@@ -93,8 +93,8 @@ error[E0382]: use of collaterally moved value: `a.y`
9393
|
9494
LL | let _x = a.x.x;
9595
| -- value moved here
96-
LL | //~^ value moved here
97-
LL | let _y = a.y; //~ ERROR use of collaterally moved
96+
LL | //[ast]~^ value moved here
97+
LL | let _y = a.y; //[ast]~ ERROR use of collaterally moved
9898
| ^^ value used here after move
9999
|
100100
= note: move occurs because `a.x.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
@@ -104,8 +104,8 @@ error[E0382]: use of collaterally moved value: `a.y`
104104
|
105105
LL | let _x = a.x.x;
106106
| -- value moved here
107-
LL | //~^ value moved here
108-
LL | let _y = &a.y; //~ ERROR use of collaterally moved
107+
LL | //[ast]~^ value moved here
108+
LL | let _y = &a.y; //[ast]~ ERROR use of collaterally moved
109109
| ^^^ value used here after move
110110
|
111111
= note: move occurs because `a.x.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
@@ -115,7 +115,7 @@ error[E0505]: cannot move out of `a.y` because it is borrowed
115115
|
116116
LL | let _x = &a.x.x;
117117
| ----- borrow of `a.x.x` occurs here
118-
LL | //~^ borrow of `a.x.x` occurs here
118+
LL | //[ast]~^ borrow of `a.x.x` occurs here
119119
LL | let _y = a.y;
120120
| ^^ move out of `a.y` occurs here
121121

@@ -124,7 +124,7 @@ error[E0503]: cannot use `a.y` because it was mutably borrowed
124124
|
125125
LL | let _x = &mut a.x.x;
126126
| ----- borrow of `a.x.x` occurs here
127-
LL | let _y = a.y; //~ ERROR cannot use
127+
LL | let _y = a.y; //[ast]~ ERROR cannot use
128128
| ^^ use of borrowed `a.x.x`
129129

130130
error[E0505]: cannot move out of `a.y` because it is borrowed
@@ -140,10 +140,10 @@ error[E0502]: cannot borrow `a.y` as immutable because `a.x.x` is also borrowed
140140
|
141141
LL | let _x = &mut a.x.x;
142142
| ----- mutable borrow occurs here
143-
LL | //~^ mutable borrow occurs here
144-
LL | let _y = &a.y; //~ ERROR cannot borrow
143+
LL | //[ast]~^ mutable borrow occurs here
144+
LL | let _y = &a.y; //[ast]~ ERROR cannot borrow
145145
| ^^^ immutable borrow occurs here
146-
LL | //~^ immutable borrow occurs here
146+
...
147147
LL | }
148148
| - mutable borrow ends here
149149

@@ -152,10 +152,10 @@ error[E0502]: cannot borrow `a.y` as mutable because `a.x.x` is also borrowed as
152152
|
153153
LL | let _x = &a.x.x;
154154
| ----- immutable borrow occurs here
155-
LL | //~^ immutable borrow occurs here
156-
LL | let _y = &mut a.y; //~ ERROR cannot borrow
155+
LL | //[ast]~^ immutable borrow occurs here
156+
LL | let _y = &mut a.y; //[ast]~ ERROR cannot borrow
157157
| ^^^ mutable borrow occurs here
158-
LL | //~^ mutable borrow occurs here
158+
...
159159
LL | }
160160
| - immutable borrow ends here
161161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: compilation successful
2+
--> $DIR/borrowck-box-insensitivity.rs:160:1
3+
|
4+
LL | / fn main() { //[mir]~ ERROR compilation successful
5+
LL | | copy_after_move();
6+
LL | | move_after_move();
7+
LL | | borrow_after_move();
8+
... |
9+
LL | | mut_borrow_after_borrow_nested();
10+
LL | | }
11+
| |_^
12+
13+
error: aborting due to previous error
14+
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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.
1+
// This test is an artifact of the old policy that `Box<T>` should not
2+
// be treated specially by the AST-borrowck.
43
//
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.
4+
// NLL goes back to treating `Box<T>` specially (namely, knowing that
5+
// it uniquely owns the data it holds). See rust-lang/rfcs#130.
106

7+
// revisions: ast mir
8+
//[ast] compile-flags: -Z borrowck=ast
9+
//[mir] compile-flags: -Z borrowck=mir
10+
// ignore-compare-mode-nll
1111
#![feature(box_syntax, rustc_attrs)]
1212

1313
struct A {
@@ -33,131 +33,131 @@ struct D {
3333
fn copy_after_move() {
3434
let a: Box<_> = box A { x: box 0, y: 1 };
3535
let _x = a.x;
36-
//~^ value moved here
37-
let _y = a.y; //~ ERROR use of moved
38-
//~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
39-
//~| value used here after move
36+
//[ast]~^ value moved here
37+
let _y = a.y; //[ast]~ ERROR use of moved
38+
//[ast]~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
39+
//[ast]~| value used here after move
4040
}
4141

4242
fn move_after_move() {
4343
let a: Box<_> = box B { x: box 0, y: box 1 };
4444
let _x = a.x;
45-
//~^ value moved here
46-
let _y = a.y; //~ ERROR use of moved
47-
//~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
48-
//~| value used here after move
45+
//[ast]~^ value moved here
46+
let _y = a.y; //[ast]~ ERROR use of moved
47+
//[ast]~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
48+
//[ast]~| value used here after move
4949
}
5050

5151
fn borrow_after_move() {
5252
let a: Box<_> = box A { x: box 0, y: 1 };
5353
let _x = a.x;
54-
//~^ value moved here
55-
let _y = &a.y; //~ ERROR use of moved
56-
//~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
57-
//~| value used here after move
54+
//[ast]~^ value moved here
55+
let _y = &a.y; //[ast]~ ERROR use of moved
56+
//[ast]~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
57+
//[ast]~| value used here after move
5858
}
5959

6060
fn move_after_borrow() {
6161
let a: Box<_> = box B { x: box 0, y: box 1 };
6262
let _x = &a.x;
6363
let _y = a.y;
64-
//~^ ERROR cannot move
65-
//~| move out of
64+
//[ast]~^ ERROR cannot move
65+
//[ast]~| move out of
66+
use_imm(_x);
6667
}
67-
6868
fn copy_after_mut_borrow() {
6969
let mut a: Box<_> = box A { x: box 0, y: 1 };
7070
let _x = &mut a.x;
71-
let _y = a.y; //~ ERROR cannot use
71+
let _y = a.y; //[ast]~ ERROR cannot use
72+
use_mut(_x);
7273
}
73-
7474
fn move_after_mut_borrow() {
7575
let mut a: Box<_> = box B { x: box 0, y: box 1 };
7676
let _x = &mut a.x;
7777
let _y = a.y;
78-
//~^ ERROR cannot move
79-
//~| move out of
78+
//[ast]~^ ERROR cannot move
79+
//[ast]~| move out of
80+
use_mut(_x);
8081
}
81-
8282
fn borrow_after_mut_borrow() {
8383
let mut a: Box<_> = box A { x: box 0, y: 1 };
8484
let _x = &mut a.x;
85-
let _y = &a.y; //~ ERROR cannot borrow
86-
//~^ immutable borrow occurs here (via `a.y`)
85+
let _y = &a.y; //[ast]~ ERROR cannot borrow
86+
//[ast]~^ immutable borrow occurs here (via `a.y`)
87+
use_mut(_x);
8788
}
88-
8989
fn mut_borrow_after_borrow() {
9090
let mut a: Box<_> = box A { x: box 0, y: 1 };
9191
let _x = &a.x;
92-
let _y = &mut a.y; //~ ERROR cannot borrow
93-
//~^ mutable borrow occurs here (via `a.y`)
92+
let _y = &mut a.y; //[ast]~ ERROR cannot borrow
93+
//[ast]~^ mutable borrow occurs here (via `a.y`)
94+
use_imm(_x);
9495
}
95-
9696
fn copy_after_move_nested() {
9797
let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
9898
let _x = a.x.x;
99-
//~^ value moved here
100-
let _y = a.y; //~ ERROR use of collaterally moved
101-
//~| value used here after move
99+
//[ast]~^ value moved here
100+
let _y = a.y; //[ast]~ ERROR use of collaterally moved
101+
//[ast]~| value used here after move
102102
}
103103

104104
fn move_after_move_nested() {
105105
let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
106106
let _x = a.x.x;
107-
//~^ value moved here
108-
let _y = a.y; //~ ERROR use of collaterally moved
109-
//~| value used here after move
107+
//[ast]~^ value moved here
108+
let _y = a.y; //[ast]~ ERROR use of collaterally moved
109+
//[ast]~| value used here after move
110110
}
111111

112112
fn borrow_after_move_nested() {
113113
let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
114114
let _x = a.x.x;
115-
//~^ value moved here
116-
let _y = &a.y; //~ ERROR use of collaterally moved
117-
//~| value used here after move
115+
//[ast]~^ value moved here
116+
let _y = &a.y; //[ast]~ ERROR use of collaterally moved
117+
//[ast]~| value used here after move
118118
}
119119

120120
fn move_after_borrow_nested() {
121121
let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
122122
let _x = &a.x.x;
123-
//~^ borrow of `a.x.x` occurs here
123+
//[ast]~^ borrow of `a.x.x` occurs here
124124
let _y = a.y;
125-
//~^ ERROR cannot move
126-
//~| move out of
125+
//[ast]~^ ERROR cannot move
126+
//[ast]~| move out of
127+
use_imm(_x);
127128
}
128-
129129
fn copy_after_mut_borrow_nested() {
130130
let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
131131
let _x = &mut a.x.x;
132-
let _y = a.y; //~ ERROR cannot use
132+
let _y = a.y; //[ast]~ ERROR cannot use
133+
use_mut(_x);
133134
}
134-
135135
fn move_after_mut_borrow_nested() {
136136
let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
137137
let _x = &mut a.x.x;
138138
let _y = a.y;
139-
//~^ ERROR cannot move
140-
//~| move out of
139+
//[ast]~^ ERROR cannot move
140+
//[ast]~| move out of
141+
use_mut(_x);
141142
}
142-
143143
fn borrow_after_mut_borrow_nested() {
144144
let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
145145
let _x = &mut a.x.x;
146-
//~^ mutable borrow occurs here
147-
let _y = &a.y; //~ ERROR cannot borrow
148-
//~^ immutable borrow occurs here
146+
//[ast]~^ mutable borrow occurs here
147+
let _y = &a.y; //[ast]~ ERROR cannot borrow
148+
//[ast]~^ immutable borrow occurs here
149+
use_mut(_x);
149150
}
150-
151151
fn mut_borrow_after_borrow_nested() {
152152
let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
153153
let _x = &a.x.x;
154-
//~^ immutable borrow occurs here
155-
let _y = &mut a.y; //~ ERROR cannot borrow
156-
//~^ mutable borrow occurs here
154+
//[ast]~^ immutable borrow occurs here
155+
let _y = &mut a.y; //[ast]~ ERROR cannot borrow
156+
//[ast]~^ mutable borrow occurs here
157+
use_imm(_x);
157158
}
158-
159159
#[rustc_error]
160-
fn main() {
160+
fn main() { //[mir]~ ERROR compilation successful
161161
copy_after_move();
162162
move_after_move();
163163
borrow_after_move();
@@ -180,3 +180,6 @@ fn main() {
180180
borrow_after_mut_borrow_nested();
181181
mut_borrow_after_borrow_nested();
182182
}
183+
184+
fn use_mut<T>(_: &mut T) { }
185+
fn use_imm<T>(_: &T) { }

0 commit comments

Comments
 (0)