Commit Graph

396 Commits

Author SHA1 Message Date
CAD97
d8a9c61e1a Use impl for Weak::as_ptr that works for unsized T 2020-06-28 14:33:18 -04:00
CAD97
e4bdf47f4c Do not require ptr validity in rc::data_offset 2020-06-28 14:24:09 -04:00
CAD97
db539c6498 Use raw_ref_op in A|Rc::as_ptr 2020-06-28 14:21:03 -04:00
LeSeulArtichaut
39e29ce4d0 #[deny(unsafe_op_in_unsafe_fn)] in liballoc 2020-06-19 13:47:01 +02:00
Lzu Tao
fff822fead Migrate to numeric associated consts 2020-06-10 01:35:47 +00:00
Mark Rousskov
7139342249 Bump to 1.46 2020-06-03 15:27:51 -04:00
Yuki Okushi
d472f8e462
Rollup merge of #72288 - vorner:stabilize-weak-into-raw, r=dtolnay
Stabilization of weak-into-raw

Closes #60728.

There are also two removals of `#![feature(weak_into_raw)]` in the `src/tools/miri` submodule. How should I synchronize the changes with there?

* I can ignore it for now and once this gets merged, update the tool, send a pull request to that one and then reference the changes to rustc.
* I could try submitting the changes to miri first, but then the build would fail there, because the attribute would still be needed.

I think the first one is the correct one, extrapolating from the contributing guidelines (even though they speak about breaking the tools and this should not break it, as extra feature should not hurt).
2020-05-29 15:06:55 +09:00
bors
914adf04af Auto merge of #71447 - cuviper:unsized_cow, r=dtolnay
impl From<Cow> for Box, Rc, and Arc

These forward `Borrowed`/`Owned` values to existing `From` impls.

- `Box<T>` is a fundamental type, so it would be a breaking change to add a blanket impl. Therefore, `From<Cow>` is only implemented for `[T]`, `str`, `CStr`, `OsStr`, and `Path`.
- For `Rc<T>` and `Arc<T>`, `From<Cow>` is implemented for everything that implements `From` the borrowed and owned types separately.
2020-05-19 08:08:48 +00:00
bors
34cce58d81 Auto merge of #72204 - RalfJung:abort, r=Mark-Simulacrum
make abort intrinsic safe, and correct its documentation

Turns out `std::process::abort` is not the same as the intrinsic, the comment was just wrong. Quoting from the unix implementation:
```
// On Unix-like platforms, libc::abort will unregister signal handlers
// including the SIGABRT handler, preventing the abort from being blocked, and
// fclose streams, with the side effect of flushing them so libc buffered
// output will be printed.  Additionally the shell will generally print a more
// understandable error message like "Abort trap" rather than "Illegal
// instruction" that intrinsics::abort would cause, as intrinsics::abort is
// implemented as an illegal instruction.
```
2020-05-17 12:49:01 +00:00
Ralf Jung
5980d972d1 make abort intrinsic safe, and correct its documentation 2020-05-17 11:23:42 +02:00
Michal 'vorner' Vaner
ba0d0c27df
Stabilization of weak-into-raw
Stabilizes #60728.
2020-05-17 08:21:24 +02:00
Matthew Jasper
cb2703945c Use min_specialization in liballoc
- Remove a type parameter from `[A]RcFromIter`.
- Remove an implementation of `[A]RcFromIter` that didn't actually
  specialize anything.
- Remove unused implementation of `IsZero` for `Option<&mut T>`.
- Change specializations of `[A]RcEqIdent` to use a marker trait version
of `Eq`.
- Remove `BTreeClone`. I couldn't find a way to make this work with
  `min_specialization`.
- Add `rustc_unsafe_specialization_marker` to `Copy` and `TrustedLen`.
2020-04-26 16:27:13 +01:00
bors
0862458dad Auto merge of #71556 - Dylan-DPC:rollup-9ll4shr, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #69041 (proc_macro: Stabilize `Span::resolved_at` and `Span::located_at`)
 - #69813 (Implement BitOr and BitOrAssign for the NonZero integer types)
 - #70712 (stabilize BTreeMap::remove_entry)
 - #71168 (Deprecate `{Box,Rc,Arc}::into_raw_non_null`)
 - #71544 (Replace filter_map().next() calls with find_map())
 - #71545 (Fix comment in docstring example for Error::kind)
 - #71548 (Add missing Send and Sync impls for linked list Cursor and CursorMut.)

Failed merges:

r? @ghost
2020-04-25 17:49:00 +00:00
Dylan DPC
939c93208c
Rollup merge of #71168 - SimonSapin:into_raw_non_null, r=Amanieu
Deprecate `{Box,Rc,Arc}::into_raw_non_null`

Per ongoing FCP at https://github.com/rust-lang/rust/issues/47336#issuecomment-586589016
See also https://github.com/rust-lang/rust/issues/47336#issuecomment-614054164
2020-04-25 18:30:29 +02:00
Mark Rousskov
93eed402ad Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
Tyler Ruckinger
547219c7e4 Fix doc link errors 2020-04-23 10:40:28 -04:00
Josh Stone
6d40751b37 impl From<Cow> for Rc and Arc
These forward `Borrowed`/`Owned` values to existing `From` impls.

    impl<'a, B> From<Cow<'a, B>> for Rc<B>
    where
        B: ToOwned + ?Sized,
        Rc<B>: From<&'a B> + From<B::Owned>,

    impl<'a, B> From<Cow<'a, B>> for Arc<B>
    where
        B: ToOwned + ?Sized,
        Arc<B>: From<&'a B> + From<B::Owned>,
2020-04-22 13:33:42 -07:00
Michal 'vorner' Vaner
f4ded11b49
weak-into-raw: Add {Arc,Rc}::as_ptr
For consistency with Weak
2020-04-19 09:38:16 +02:00
Simon Sapin
b359fe1eea Deprecate Rc::into_raw_non_null and Arc::into_raw_non_null 2020-04-15 16:18:33 +02:00
Simon Sapin
cdb6bef4fb Deprecate Box::into_raw_non_null
Per https://github.com/rust-lang/rust/issues/47336#issuecomment-586589016
2020-04-15 16:18:33 +02:00
Michal 'vorner' Vaner
80ccddc0ed
weak-into-raw: as_raw -> as_ptr + dangling garbage
* Rename Weak::as_raw to Weak::as_ptr for consistency with some other
  types.
* The as_ptr for a dangling Weak pointer might return whatever garbage
  (and takes that advantage to avoid a conditional).
* Don't guarantee to be able to do `Weak::from_raw(weak.as_ptr())` (even
  though it'll still work fine).
2020-04-13 17:17:34 +02:00
Eduard-Mihai Burtescu
9d13520a6b Replace "rc"/"arc" lang items with Rc/Arc diagnostic items. 2020-04-08 10:47:41 +03:00
Linus Färnstrand
fff4f08398 Stop importing integer modules in liballoc 2020-04-05 11:22:01 +02:00
Tim Diekmann
bf6a46db31 Make fields in MemoryBlock public 2020-03-28 20:22:07 +01:00
Tim Diekmann
03b055b0b4 Remove alignment from MemoryBlock 2020-03-26 17:14:12 +01:00
Tim Diekmann
2526accdd3 Fix issues from review and unsoundness of RawVec::into_box 2020-03-26 17:11:47 +01:00
Tim Diekmann
56cbf2f22a Overhaul of the AllocRef trait to match allocator-wg's latest consens 2020-03-26 17:10:54 +01:00
Dylan DPC
0bc5fc99d3
Rollup merge of #68099 - lukaslueg:into_raw_unsafe, r=LukasKalbertodt
Amend Rc/Arc::from_raw() docs regarding unsafety

[This](https://stackoverflow.com/questions/59671647/is-it-safe-to-clone-a-type-erased-arc-via-raw-pointer) question on SO boils down to "is it safe to `::from_raw()` a `Rc<T>`/`Arc<T>` using a dummy `T` even if `T` is never dereferenced via the new `Rc`/`Arc`?". It almost never is.

This PR amends the docs of `from_raw()` regarding this point.
2020-03-22 15:48:28 +01:00
Yuki Okushi
4699b29a04
Rollup merge of #69609 - TimDiekmann:excess, r=Amanieu
Remove `usable_size` APIs

This removes the usable size APIs:
- remove `usable_size` (obv)
- change return type of allocating methods to include the allocated size
- remove `_excess` API

r? @Amanieu
closes rust-lang/wg-allocators#17
2020-03-03 17:50:06 +09:00
Tim Diekmann
d8e3557dba Remove usable_size APIs 2020-03-03 00:08:24 +01:00
Yuki Okushi
4e0bea326e Stabilize boxed_slice_try_from 2020-02-28 13:28:09 +09:00
Lukas Lueg
586c7e3907 Make rc::RcBox and sync::ArcInner repr(C)
Future-proof these types in case rustc reorders
the inner fields. As per discussion in PR #68099.
2020-02-07 22:59:24 +01:00
Lukas Lueg
b4c96a9199 Refine [Arc/Rc]::from_raw() docs 2020-01-28 22:28:13 +01:00
Tim Diekmann
7ca25db816
Rename Alloc to AllocRef 2020-01-27 21:39:51 +01:00
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
Lukas Lueg
becebf3106 Ammend Rc/Arc::from_raw() docs regarding unsafety
Constructing an Rc/Arc is unsafe even if the wrapped `T`
is never dereferenced.
2020-01-10 19:39:01 +01:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mazdak Farrokhzad
ca528fcc04
Rollup merge of #67504 - Mark-Simulacrum:note-data-offset, r=Centril
Warn against relying on ?Sized being last

Fixes #62522
2019-12-22 02:40:07 +01:00
Mark Rousskov
a34c2677af Warn against relying on ?Sized being last 2019-12-21 20:35:41 -05:00
Ross MacArthur
f7256d28d1
Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
CAD97
eb77f7ec6e Add internal safety docs to (A)Rc::into_raw 2019-12-17 15:52:13 -05:00
Mazdak Farrokhzad
c34ea91a9d
Rollup merge of #65778 - bdonlan:stable_weak_count, r=dtolnay
Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}`

* Original PR: #56696
* Tracking issue: #57977

Closes: #57977

Supporting comments:

> Although these were added for testing, it is occasionally useful to have a way to probe optimistically for whether a weak pointer has become dangling, without actually taking the overhead of manipulating atomics. Are there any plans to stabilize this?

_Originally posted by @bdonlan in https://github.com/rust-lang/rust/issues/57977#issuecomment-516970921_

> Having this stabilized would help. Currently, the only way to check if a weak pointer has become dangling is to call `upgrade`, which is by far expensive.

_Originally posted by @glebpom in https://github.com/rust-lang/rust/issues/57977#issuecomment-526934709_

Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now.

Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in `src/stdsimd`).
2019-12-16 05:23:26 +01:00
cad97
c842f02dee
Use pointer offset instead of deref for A/Rc::into_raw 2019-12-15 19:57:18 -05:00
David Tolnay
9778e03665
Bump Weak::strong_count/weak_count stabilizations from 1.40 to 1.41 2019-12-14 19:26:25 -08:00
Mazdak Farrokhzad
bcf992dc6c
Rollup merge of #66710 - vorner:weak-into-raw-null-docs, r=dtolnay
weak-into-raw: Clarify some details in Safety

Clarify it is OK to pass a pointer that never owned a weak count (one
from Weak::new) back into it as it was created from it. Relates to
discussion in #60728.

@CAD97 Do you want to have a look at the new docs?
2019-12-05 19:03:08 +01:00
Michal 'vorner' Vaner
473151070b
weak-into-raw: Clarify some details in Safety
Clarify it is OK to pass a pointer that never owned a weak count (one
from Weak::new) back into it as it was created from it. Relates to
discussion in #60728.
2019-12-05 15:22:11 +01:00
bors
4787e97475 Auto merge of #66256 - CAD97:patch-2, r=RalfJung
Layout::pad_to_align is infallible

As per [this comment](https://github.com/rust-lang/rust/issues/55724#issuecomment-441421651) (cc @glandium).

> Per https://github.com/rust-lang/rust/blob/eb981a1/src/libcore/alloc.rs#L63-L65, `layout.size()` is always <= `usize::MAX - (layout.align() - 1)`.
>
> Which means:
>
> * The maximum value `layout.size()` can have is already aligned for `layout.align()` (`layout.align()` being a power of two, `usize::MAX - (layout.align() - 1)` is a multiple of `layout.align()`)
> * Incidentally, any value smaller than that maximum value will align at most to that maximum value.
>
> IOW, `pad_to_align` can not return `Err(LayoutErr)`, except for the layout not respecting its invariants, but we shouldn't care about that.

This PR makes `pad_to_align` return `Layout` directly, representing the fact that it cannot fail.
2019-12-03 01:50:33 +00:00
Tyler Mandry
941d915942
Rollup merge of #66128 - emilio:new-zeroed, r=SimonSapin
alloc: Add new_zeroed() versions like new_uninit().

MaybeUninit has both uninit() and zeroed(), it seems reasonable to have the same
surface on Box/Rc/Arc.

Needs tests.

cc #63291
2019-11-26 17:56:05 -06:00
Bryan Donlan
0d0b283c2c Make Weak::weak_count() return zero when no strong refs remain 2019-11-21 19:48:39 +00:00
Bryan Donlan
91ee3d1c31 Stabilize std::{rc,sync}::Weak::{weak_count, strong_count}
Closes: #57977
2019-11-21 18:33:03 +00:00