Commit f6faef4
committed
Auto merge of rust-lang#114795 - RalfJung:cell-swap, r=dtolnay
make Cell::swap panic if the Cells partially overlap
The following function ought to be sound:
```rust
fn as_cell_of_array<T, const N: usize>(c: &[Cell<T>; N]) -> &Cell<[T; N]> {
unsafe { transmute(c) }
}
```
However, due to `Cell::swap`, it currently is not -- safe code can [cause a use-after-free](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c9415799722d985ff7d2c2c997b724ca). This PR fixes that.
Fixes rust-lang#807782 files changed
+16
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
| |||
415 | 416 | | |
416 | 417 | | |
417 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
418 | 425 | | |
419 | 426 | | |
420 | 427 | | |
| |||
430 | 437 | | |
431 | 438 | | |
432 | 439 | | |
| 440 | + | |
433 | 441 | | |
434 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
435 | 447 | | |
436 | 448 | | |
437 | 449 | | |
438 | | - | |
| 450 | + | |
| 451 | + | |
439 | 452 | | |
440 | | - | |
| 453 | + | |
441 | 454 | | |
442 | 455 | | |
443 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2567 | 2567 | | |
2568 | 2568 | | |
2569 | 2569 | | |
2570 | | - | |
| 2570 | + | |
2571 | 2571 | | |
2572 | 2572 | | |
2573 | 2573 | | |
| |||
0 commit comments