Skip to content

Commit c54147d

Browse files
committed
Auto merge of #136185 - matthiaskrgr:rollup-zqzy6wb, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #133151 (Trim extra whitespace in fn ptr suggestion span) - #133829 (Implement `AtomicT::update` & `AtomicT::try_update`) - #135367 (Enable `unreachable_pub` lint in `alloc`) - #135748 (Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸) - #135805 (Add missing allocator safety in alloc crate) - #135886 (Document purpose of closure in from_fn.rs more clearly) - #135961 (Fix 2/4 tests skipped by opt-dist) - #136012 (Document powf and powi values that are always 1.0) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 27738c8 + a2c2482 commit c54147d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/pass/disjoint-array-accesses.rs

+35
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)