99// except according to those terms.
1010
1111// ignore-tidy-linelength
12+ // revisions: ast mir
13+ //[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
1214
1315#[ derive( Clone , Copy ) ]
1416union U {
@@ -30,11 +32,15 @@ fn main() {
3032 }
3133 {
3234 let ra = & u. a ;
33- let rma = & mut u. a ; //~ ERROR cannot borrow `u.a` as mutable because it is also borrowed as immutable
35+ let rma = & mut u. a ; //[ast]~ ERROR cannot borrow `u.a` as mutable because it is also borrowed as immutable
36+ //[mir]~^ ERROR cannot borrow `u.a` as mutable because it is also borrowed as immutable (Ast)
37+ //[mir]~| ERROR cannot borrow `u.0` as mutable because it is also borrowed as immutable (Mir)
3438 }
3539 {
3640 let ra = & u. a ;
37- u. a = 1 ; //~ ERROR cannot assign to `u.a` because it is borrowed
41+ u. a = 1 ; //[ast]~ ERROR cannot assign to `u.a` because it is borrowed
42+ //[mir]~^ ERROR cannot assign to `u.a` because it is borrowed (Ast)
43+ //[mir]~| ERROR cannot assign to `u.0` because it is borrowed (Mir)
3844 }
3945 // Imm borrow, other field
4046 {
@@ -47,45 +53,65 @@ fn main() {
4753 }
4854 {
4955 let ra = & u. a ;
50- let rmb = & mut u. b ; //~ ERROR cannot borrow `u` (via `u.b`) as mutable because `u` is also borrowed as immutable (via `u.a`)
56+ let rmb = & mut u. b ; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as mutable because `u` is also borrowed as immutable (via `u.a`)
57+ //[mir]~^ ERROR cannot borrow `u` (via `u.b`) as mutable because `u` is also borrowed as immutable (via `u.a`) (Ast)
58+ // FIXME Error for MIR (needs support for union)
5159 }
5260 {
5361 let ra = & u. a ;
54- u. b = 1 ; //~ ERROR cannot assign to `u.b` because it is borrowed
62+ u. b = 1 ; //[ast]~ ERROR cannot assign to `u.b` because it is borrowed
63+ //[mir]~^ ERROR cannot assign to `u.b` because it is borrowed (Ast)
64+ // FIXME Error for MIR (needs support for union)
5565 }
5666 // Mut borrow, same field
5767 {
5868 let rma = & mut u. a ;
59- let ra = & u. a ; //~ ERROR cannot borrow `u.a` as immutable because it is also borrowed as mutable
69+ let ra = & u. a ; //[ast]~ ERROR cannot borrow `u.a` as immutable because it is also borrowed as mutable
70+ //[mir]~^ ERROR cannot borrow `u.a` as immutable because it is also borrowed as mutable (Ast)
71+ //[mir]~| ERROR cannot borrow `u.0` as immutable because it is also borrowed as mutable (Mir)
6072 }
6173 {
6274 let ra = & mut u. a ;
63- let a = u. a ; //~ ERROR cannot use `u.a` because it was mutably borrowed
75+ let a = u. a ; //[ast]~ ERROR cannot use `u.a` because it was mutably borrowed
76+ //[mir]~^ ERROR cannot use `u.a` because it was mutably borrowed (Ast)
77+ //[mir]~| ERROR cannot use `u.0` because it was mutably borrowed (Mir)
6478 }
6579 {
6680 let rma = & mut u. a ;
67- let rma2 = & mut u. a ; //~ ERROR cannot borrow `u.a` as mutable more than once at a time
81+ let rma2 = & mut u. a ; //[ast]~ ERROR cannot borrow `u.a` as mutable more than once at a time
82+ //[mir]~^ ERROR cannot borrow `u.a` as mutable more than once at a time (Ast)
83+ //[mir]~| ERROR cannot borrow `u.0` as mutable more than once at a time (Mir)
6884 }
6985 {
7086 let rma = & mut u. a ;
71- u. a = 1 ; //~ ERROR cannot assign to `u.a` because it is borrowed
87+ u. a = 1 ; //[ast]~ ERROR cannot assign to `u.a` because it is borrowed
88+ //[mir]~^ ERROR cannot assign to `u.a` because it is borrowed (Ast)
89+ //[mir]~| ERROR cannot assign to `u.0` because it is borrowed (Mir)
7290 }
7391 // Mut borrow, other field
7492 {
7593 let rma = & mut u. a ;
76- let rb = & u. b ; //~ ERROR cannot borrow `u` (via `u.b`) as immutable because `u` is also borrowed as mutable (via `u.a`)
94+ let rb = & u. b ; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as immutable because `u` is also borrowed as mutable (via `u.a`)
95+ //[mir]~^ ERROR cannot borrow `u` (via `u.b`) as immutable because `u` is also borrowed as mutable (via `u.a`) (Ast)
96+ // FIXME Error for MIR (needs support for union)
7797 }
7898 {
7999 let ra = & mut u. a ;
80- let b = u. b ; //~ ERROR cannot use `u.b` because it was mutably borrowed
100+ let b = u. b ; //[ast]~ ERROR cannot use `u.b` because it was mutably borrowed
101+ //[mir]~^ ERROR cannot use `u.b` because it was mutably borrowed (Ast)
102+ // FIXME Error for MIR (needs support for union)
81103 }
82104 {
83105 let rma = & mut u. a ;
84- let rmb2 = & mut u. b ; //~ ERROR cannot borrow `u` (via `u.b`) as mutable more than once at a time
106+ let rmb2 = & mut u. b ; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as mutable more than once at a time
107+ //[mir]~^ ERROR cannot borrow `u` (via `u.b`) as mutable more than once at a time (Ast)
108+ // FIXME Error for MIR (needs support for union)
85109 }
86110 {
87111 let rma = & mut u. a ;
88- u. b = 1 ; //~ ERROR cannot assign to `u.b` because it is borrowed
112+ u. b = 1 ; //[ast]~ ERROR cannot assign to `u.b` because it is borrowed
113+ //[mir]~^ ERROR cannot assign to `u.b` because it is borrowed (Ast)
114+ // FIXME Error for MIR (needs support for union)
89115 }
90116 }
91117}
0 commit comments