Skip to content

Commit c5fd944

Browse files
JoJoDevelopingLuthaf
authored andcommitted
Make test ptr::slice_mut compliant with Tree Borrows
Tree Borrows is a new aliasing model for Rust, which features more precise tracking of pointer aliasing. The aim is to be more lenient than Stacked Borrows, while also having less dirty hacks than SB had. It turns out that the test ptr::slice_mut here relied on one such gross hack. The problematic code is here: https://github.com/lumol-org/soa-derive/blob/ad918be58f47ee6d38e9c83411180e756a3220c0/tests/ptr.rs#L77-L93 There, a slice is created, and then a reference to it is obtained using `slice::as_mut_ptr()`, which (internally) creates a new mutable reference. This means that the resulting pointer can not be mixed with accesses to the original slice. However, the test does so: It first uses the pointer, then the original slice, and then again the pointer. The proper solution is to re-derive the pointer when it's needed again, which is what this PR does.
1 parent ad918be commit c5fd944

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tests/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn slice_mut() {
8686
assert_eq!(slice.mass[0], 42.0);
8787

8888
unsafe {
89-
let slice = ParticleSliceMut::from_raw_parts_mut(ptr, 2);
89+
let slice = ParticleSliceMut::from_raw_parts_mut(slice.as_mut_ptr(), 2);
9090

9191
for mass in slice.mass {
9292
*mass = -1.0;

0 commit comments

Comments
 (0)