Files
rust/library/core/src
Matthias Krüger e332aa89a7 Rollup merge of #139145 - okaneco:safe_splits, r=Amanieu
slice: Remove some uses of unsafe in first/last chunk methods

Remove unsafe `split_at_unchecked` and `split_at_mut_unchecked` in some slice `split_first_chunk`/`split_last_chunk` methods.
Replace those calls with the safe `split_at` and `split_at_checked` where applicable.

Add codegen tests to check for no panics when calculating the last chunk index using `checked_sub` and `split_at`.

Better viewed with whitespace disabled in diff view

---

The unchecked calls are mostly manual implementations of the safe methods, but with the safety condition negated from `mid <= len` to `len < mid`.
```rust
if self.len() < N {
    None
} else {
    // SAFETY: We manually verified the bounds of the split.
    let (first, tail) = unsafe { self.split_at_unchecked(N) };
    // Or for the last_chunk methods
    let (init, last) = unsafe { self.split_at_unchecked(self.len() - N) };
```

Unsafe is still needed for the pointer array casts. Their safety comments are unmodified.
2025-04-03 07:39:05 +02:00
..
2025-03-26 14:32:35 -04:00
2025-02-15 13:34:01 +06:00
2025-03-23 17:47:10 +09:00
2025-03-26 14:32:35 -04:00
2025-03-16 17:47:56 +00:00
2025-03-21 20:51:06 +00:00
2025-03-06 13:21:59 -08:00
2025-03-06 13:21:59 -08:00
2025-02-27 19:06:06 -08:00
2025-03-25 21:02:55 +01:00
2025-02-18 09:32:44 -08:00
2025-01-20 18:35:32 +01:00
2025-02-18 08:50:21 -08:00
2025-03-26 14:32:35 -04:00
2025-03-26 14:32:35 -04:00
2024-11-27 15:14:54 +00:00
2025-02-18 09:32:44 -08:00
2025-03-19 17:37:35 +01:00
2025-02-18 09:32:44 -08:00
2025-03-23 15:27:31 -07:00