Skip to content

Commit 909b94b

Browse files
committed
Auto merge of #46041 - zilbuz:issue-44837, r=arielb1
MIR borrowck: finalize `check_access_permissions()` Fix #44837 (hopefully for good) r? @arielb1
2 parents 78fcf33 + 1cd9d74 commit 909b94b

8 files changed

+232
-79
lines changed

src/librustc_mir/borrow_check.rs

+193-63
Large diffs are not rendered by default.

src/test/compile-fail/E0594.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ static NUM: i32 = 18;
1515

1616
fn main() {
1717
NUM = 20; //[ast]~ ERROR E0594
18-
//[mir]~^ ERROR cannot assign to immutable static item
18+
//[mir]~^ ERROR cannot assign to immutable item `NUM`
1919
}

src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ static foo: isize = 5;
1616
fn main() {
1717
// assigning to various global constants
1818
foo = 6; //[ast]~ ERROR cannot assign to immutable static item
19-
//[mir]~^ ERROR cannot assign to immutable static item `foo`
19+
//[mir]~^ ERROR cannot assign to immutable item `foo`
2020
}

src/test/compile-fail/borrowck/borrowck-issue-14498.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// Also includes tests of the errors reported when the Box in question
1515
// is immutable (#14270).
1616

17+
// revisions: ast mir
18+
//[mir]compile-flags: -Z borrowck=mir
19+
1720
#![feature(box_syntax)]
1821

1922
struct A { a: isize }
@@ -23,7 +26,8 @@ fn indirect_write_to_imm_box() {
2326
let mut x: isize = 1;
2427
let y: Box<_> = box &mut x;
2528
let p = &y;
26-
***p = 2; //~ ERROR cannot assign to data in a `&` reference
29+
***p = 2; //[ast]~ ERROR cannot assign to data in a `&` reference
30+
//[mir]~^ ERROR cannot assign to immutable item `***p`
2731
drop(p);
2832
}
2933

@@ -32,7 +36,8 @@ fn borrow_in_var_from_var() {
3236
let mut y: Box<_> = box &mut x;
3337
let p = &y;
3438
let q = &***p;
35-
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
39+
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
40+
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
3641
drop(p);
3742
drop(q);
3843
}
@@ -42,7 +47,8 @@ fn borrow_in_var_from_var_via_imm_box() {
4247
let y: Box<_> = box &mut x;
4348
let p = &y;
4449
let q = &***p;
45-
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
50+
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
51+
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
4652
drop(p);
4753
drop(q);
4854
}
@@ -52,7 +58,8 @@ fn borrow_in_var_from_field() {
5258
let mut y: Box<_> = box &mut x.a;
5359
let p = &y;
5460
let q = &***p;
55-
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
61+
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
62+
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
5663
drop(p);
5764
drop(q);
5865
}
@@ -62,7 +69,8 @@ fn borrow_in_var_from_field_via_imm_box() {
6269
let y: Box<_> = box &mut x.a;
6370
let p = &y;
6471
let q = &***p;
65-
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
72+
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
73+
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
6674
drop(p);
6775
drop(q);
6876
}
@@ -72,7 +80,8 @@ fn borrow_in_field_from_var() {
7280
let mut y = B { a: box &mut x };
7381
let p = &y.a;
7482
let q = &***p;
75-
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
83+
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
84+
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
7685
drop(p);
7786
drop(q);
7887
}
@@ -82,7 +91,8 @@ fn borrow_in_field_from_var_via_imm_box() {
8291
let y = B { a: box &mut x };
8392
let p = &y.a;
8493
let q = &***p;
85-
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
94+
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
95+
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
8696
drop(p);
8797
drop(q);
8898
}
@@ -92,7 +102,8 @@ fn borrow_in_field_from_field() {
92102
let mut y = B { a: box &mut x.a };
93103
let p = &y.a;
94104
let q = &***p;
95-
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
105+
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
106+
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
96107
drop(p);
97108
drop(q);
98109
}
@@ -102,7 +113,8 @@ fn borrow_in_field_from_field_via_imm_box() {
102113
let y = B { a: box &mut x.a };
103114
let p = &y.a;
104115
let q = &***p;
105-
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
116+
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
117+
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
106118
drop(p);
107119
drop(q);
108120
}

src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ fn main() {
7070
};
7171
s[2] = 20;
7272
//[ast]~^ ERROR cannot assign to immutable indexed content
73-
// FIXME Error for MIR
73+
//[mir]~^^ ERROR cannot assign to immutable item
7474
}

src/test/compile-fail/cannot-mutate-captured-non-mut-var.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
12+
// revisions: ast mir
13+
//[mir]compile-flags: -Z borrowck=mir
14+
1115
#![feature(unboxed_closures)]
1216

1317
use std::io::Read;
@@ -17,9 +21,11 @@ fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
1721
fn main() {
1822
let x = 1;
1923
to_fn_once(move|| { x = 2; });
20-
//~^ ERROR: cannot assign to immutable captured outer variable
24+
//[ast]~^ ERROR: cannot assign to immutable captured outer variable
25+
//[mir]~^^ ERROR: cannot assign to immutable item `x`
2126

2227
let s = std::io::stdin();
2328
to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
24-
//~^ ERROR: cannot borrow immutable captured outer variable
29+
//[ast]~^ ERROR: cannot borrow immutable captured outer variable
30+
//[mir]~^^ ERROR: cannot borrow immutable item `s` as mutable
2531
}

src/test/compile-fail/issue-5500-1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn main() {
2020
let _iter = TrieMapIterator{node: &a};
2121
_iter.node = & //[ast]~ ERROR cannot assign to immutable field `_iter.node`
2222
//[mir]~^ ERROR cannot assign to immutable field `_iter.node` (Ast)
23-
// FIXME Error for MIR
23+
// MIR doesn't generate an error because the code isn't reachable. This is OK
24+
// because the test is here to check that the compiler doesn't ICE (cf. #5500).
2425
panic!()
2526
}

src/test/compile-fail/unboxed-closures-mutated-upvar-from-fn-closure.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z borrowck=mir
13+
1114
// Test that a by-ref `FnMut` closure gets an error when it tries to
1215
// mutate a value.
1316

@@ -19,6 +22,7 @@ fn main() {
1922
let mut counter = 0;
2023
call(|| {
2124
counter += 1;
22-
//~^ ERROR cannot assign to data in a captured outer variable in an `Fn` closure
25+
//[ast]~^ ERROR cannot assign to data in a captured outer variable in an `Fn` closure
26+
//[mir]~^^ ERROR cannot assign to immutable item `counter`
2327
});
2428
}

0 commit comments

Comments
 (0)