rust/src/liballoc
bors e02c475da5 Auto merge of #67339 - CAD97:rc-provenance, r=sfackler
Use pointer offset instead of deref for A/Rc::into_raw

Internals thread: https://internals.rust-lang.org/t/rc-and-internal-mutability/11463/2?u=cad97

The current implementation of (`A`)`Rc::into_raw` uses the `Deref::deref` implementation to get the pointer-to-data that is returned. This is problematic in the proposed Stacked Borrow rules, as this only gets shared provenance over the data location. (Note that the strong/weak counts are `UnsafeCell` (`Cell`/`Atomic`) so shared provenance can still mutate them, but the data itself is not.) When promoted back to a real reference counted pointer, the restored pointer can be used for mutation through `::get_mut` (if it is the only surviving reference). However, this mutates through a pointer ultimately derived from a `&T` borrow, violating the Stacked Borrow rules.

There are three known potential solutions to this issue:

- Stacked Borrows is wrong, liballoc is correct.
- Fully admit (`A`)`Rc` as an "internal mutability" type and store the data payload in an `UnsafeCell` like the strong/weak counts are. (Note: this is not needed generally since the `RcBox`/`ArcInner` is stored behind a shared `NonNull` which maintains shared write provenance as a raw pointer.)
- Adjust `into_raw` to do direct manipulation of the pointer (like `from_raw`) so that it maintains write provenance and doesn't derive the pointer from a reference.

This PR implements the third option, as recommended by @RalfJung.

Potential future work: provide `as_raw` and `clone_raw` associated functions to allow the [`&T` -> (`A`)`Rc<T>` pattern](https://internals.rust-lang.org/t/rc-and-internal-mutability/11463/2?u=cad97) to be used soundly without creating (`A`)`Rc` from references.
2020-01-16 00:47:45 +00:00
..
alloc liballoc: ignore tests in Miri instead of removing them entirely 2019-12-07 12:42:19 +01:00
benches Format the world 2019-12-22 17:42:47 -05:00
collections Update APIs according to RFC change suggestions. 2020-01-14 20:11:52 +08:00
prelude Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
raw_vec Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
rc Format the world 2019-12-22 17:42:47 -05:00
sync Format the world 2019-12-22 17:42:47 -05:00
tests Revert "Rollup merge of #67727 - Dylan-DPC:stabilise/remove_item, r=alexcrichton" 2020-01-11 03:04:39 +00:00
alloc.rs Format the world 2019-12-22 17:42:47 -05:00
borrow.rs Format the world 2019-12-22 17:42:47 -05:00
boxed.rs Simplify Clone for Box<[T]> 2019-12-23 07:35:39 -07:00
Cargo.toml bump rand to fix Miri failures 2019-08-04 14:50:26 +02:00
fmt.rs Remove redundant link texts 2019-12-26 05:04:46 -08:00
lib.rs Format the world 2019-12-22 17:42:47 -05:00
macros.rs Scope format! temporaries 2019-09-27 17:36:45 -04:00
raw_vec.rs Format the world 2019-12-22 17:42:47 -05:00
rc.rs Auto merge of #67339 - CAD97:rc-provenance, r=sfackler 2020-01-16 00:47:45 +00:00
slice.rs reuse capacity variable in slice::repeat 2019-12-24 12:44:05 +08:00
str.rs Format the world 2019-12-22 17:42:47 -05:00
string.rs Format the world 2019-12-22 17:42:47 -05:00
sync.rs Auto merge of #67339 - CAD97:rc-provenance, r=sfackler 2020-01-16 00:47:45 +00:00
tests.rs Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
vec.rs Revert "Rollup merge of #67727 - Dylan-DPC:stabilise/remove_item, r=alexcrichton" 2020-01-11 03:04:39 +00:00