Skip to content

Commit 1f9f3f4

Browse files
authored
Rollup merge of #135748 - compiler-errors:len-2, r=RalfJung,oli-obk
Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸 Change `Rvalue::RawRef` to take a `RawRefKind` instead of just a `Mutability`. Then introduce `RawRefKind::FakeForPtrMetadata` and use that for lowering index bounds checking to a `PtrMetadata`. This new `RawRefKind::FakeForPtrMetadata` acts like a shallow fake borrow in borrowck, which mimics the semantics of the old `Rvalue::Len` operation we're replacing. We can then use this `RawRefKind` instead of using a span desugaring hack in CTFE. cc ``@scottmcm`` ``@RalfJung``
2 parents 6f4478c + d7157ea commit 1f9f3f4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/pass/disjoint-array-accesses.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This is a regression test for issue #135671 where a MIR refactor about arrays and their lengths
2+
// unexpectedly caused borrowck errors for disjoint borrows of array elements, for which we had no
3+
// tests. This is a collection of a few code samples from that issue.
4+
5+
//@revisions: stack tree
6+
//@[tree]compile-flags: -Zmiri-tree-borrows
7+
8+
struct Test {
9+
a: i32,
10+
b: i32,
11+
}
12+
13+
fn one() {
14+
let inputs: &mut [_] = &mut [Test { a: 0, b: 0 }];
15+
let a = &mut inputs[0].a;
16+
let b = &mut inputs[0].b;
17+
18+
*a = 0;
19+
*b = 1;
20+
}
21+
22+
fn two() {
23+
let slice = &mut [(0, 0)][..];
24+
std::mem::swap(&mut slice[0].0, &mut slice[0].1);
25+
}
26+
27+
fn three(a: &mut [(i32, i32)], i: usize, j: usize) -> (&mut i32, &mut i32) {
28+
(&mut a[i].0, &mut a[j].1)
29+
}
30+
31+
fn main() {
32+
one();
33+
two();
34+
three(&mut [(1, 2), (3, 4)], 0, 1);
35+
}

0 commit comments

Comments
 (0)