FFORGE//RS
← Roadmap

rust / LEVEL 4

The unsafe block that did not need to exist

EST.40 MIN
01

THEORY / RETRIEVAL

What to restore

  • State the aliasing invariant behind two mutable references
  • Use split_at_mut while preserving requested return order

Unsafe moves proof obligations to the programmer

Creating two `&mut T` values requires them to be valid, aligned, in bounds and non-overlapping for their full lifetimes. The compiler cannot verify raw-pointer code, so every unsafe block needs a local invariant that reviewers can actually audit.

Prefer APIs that encode the proof

`split_at_mut` returns two non-overlapping slices. Once indices are ordered, taking one element from each half expresses disjointness through safe types and removes the raw-pointer proof entirely.

CHECKPOINT

Which approach gives two mutable elements the smallest and clearest safety proof?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / CODE REVIEW

Make the code safe

Replace the rejected double-borrow attempt with a safe implementation. Return references in the caller's requested order; equal or out-of-bounds indices return None. Do not use unsafe.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.