MIR borrowck: implement union-and-array-compatible semantics
Fixes #44831. Fixes #44834. Fixes #45537. Fixes #45696 (by implementing DerefPure semantics, which is what we want going forward).
This commit is contained in:
parent
abe85ab0b2
commit
6bc4b50511
5 changed files with 368 additions and 59 deletions
|
|
@ -8,6 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test will be fixed later
|
||||
// revisions: ast mir
|
||||
//[mir]compile-flags: -Z borrowck=mir
|
||||
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ fn main() {
|
|||
{
|
||||
let ra = &u.a;
|
||||
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`)
|
||||
// FIXME Error for MIR (needs support for union)
|
||||
//[mir]~^ ERROR cannot borrow `u.b` as mutable because it is also borrowed as immutable
|
||||
}
|
||||
{
|
||||
let ra = &u.a;
|
||||
u.b = 1; //[ast]~ ERROR cannot assign to `u.b` because it is borrowed
|
||||
// FIXME Error for MIR (needs support for union)
|
||||
//[mir]~^ ERROR cannot assign to `u.b` because it is borrowed
|
||||
}
|
||||
// Mut borrow, same field
|
||||
{
|
||||
|
|
@ -84,22 +84,23 @@ fn main() {
|
|||
{
|
||||
let rma = &mut u.a;
|
||||
let rb = &u.b; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as immutable because `u` is also borrowed as mutable (via `u.a`)
|
||||
// FIXME Error for MIR (needs support for union)
|
||||
//[mir]~^ ERROR cannot borrow `u.b` as immutable because it is also borrowed as mutable
|
||||
}
|
||||
{
|
||||
let ra = &mut u.a;
|
||||
let b = u.b; //[ast]~ ERROR cannot use `u.b` because it was mutably borrowed
|
||||
// FIXME Error for MIR (needs support for union)
|
||||
//[mir]~^ ERROR cannot use `u.b` because it was mutably borrowed
|
||||
|
||||
}
|
||||
{
|
||||
let rma = &mut u.a;
|
||||
let rmb2 = &mut u.b; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as mutable more than once at a time
|
||||
// FIXME Error for MIR (needs support for union)
|
||||
//[mir]~^ ERROR cannot borrow `u.b` as mutable more than once at a time
|
||||
}
|
||||
{
|
||||
let rma = &mut u.a;
|
||||
u.b = 1; //[ast]~ ERROR cannot assign to `u.b` because it is borrowed
|
||||
// FIXME Error for MIR (needs support for union)
|
||||
//[mir]~^ ERROR cannot assign to `u.b` because it is borrowed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
|
|
@ -22,7 +23,7 @@ fn main() {
|
|||
println!("t[0]: {}", t[0]);
|
||||
a[2] = 0; //[ast]~ ERROR cannot assign to `a[..]` because it is borrowed
|
||||
//[cmp]~^ ERROR cannot assign to `a[..]` because it is borrowed (Ast)
|
||||
// FIXME Error for MIR (error missed)
|
||||
//[cmp]~| ERROR cannot assign to `a[..]` because it is borrowed (Mir)
|
||||
println!("t[0]: {}", t[0]);
|
||||
t[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ fn causes_ice(mut l: &mut Sexpression) {
|
|||
//[mir]~| ERROR [E0499]
|
||||
l = &mut **expr; //[ast]~ ERROR [E0506]
|
||||
//[mir]~^ ERROR [E0506]
|
||||
//[mir]~| ERROR [E0506]
|
||||
//[mir]~| ERROR [E0499]
|
||||
//[mir]~| ERROR [E0506]
|
||||
//[mir]~| ERROR [E0499]
|
||||
}
|
||||
}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue