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
1313struct A {
@@ -33,131 +33,131 @@ struct D {
3333fn 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
4242fn 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
5151fn 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
6060fn 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-
6868fn 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-
7474fn 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-
8282fn 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-
8989fn 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-
9696fn 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
104104fn 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
112112fn 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
120120fn 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-
129129fn 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-
135135fn 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-
143143fn 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-
151151fn 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