Commit Graph

291 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
e6e27924e1 liballoc: cargo check passes on 2018 2019-02-02 08:36:45 +01:00
bors
f29b4fbd74 Auto merge of #56696 - jonas-schievink:weak-counts, r=alexcrichton
Implement Weak::{strong_count, weak_count}

The counters are also useful on `Weak`, not just on strong references (`Rc` or `Arc`).

In situations where there are still strong references around, you can also get these counts by temporarily upgrading and adjusting the values accordingly. Using the methods introduced here is simpler to do, less error-prone (since you can't forget to adjust the counts), can also be used when no strong references are around anymore, and might be more efficient due to not having to temporarily create an `Rc`.

This is mainly useful in assertions or tests of complex data structures. Data structures might have internal invariants that make them the sole owner of a `Weak` pointer, and an assertion on the weak count could be used to ensure that this indeed happens as expected. Due to the presence of `Weak::upgrade`, the `strong_count` becomes less useful, but it still seems worthwhile to mirror the API of `Rc`.

TODO:
* [X] Tracking issue - https://github.com/rust-lang/rust/issues/57977

Closes https://github.com/rust-lang/rust/issues/50158
2019-01-31 19:20:14 +00:00
Mazdak Farrokhzad
e8173a654d
Rollup merge of #57934 - dwijnand:from-Arc/Rc-to-NonNull, r=alexcrichton
Introduce into_raw_non_null on Rc and Arc

None
2019-01-31 02:10:44 +01:00
Jonas Schievink
0d314f08af Add tracking issue to unstable attribute 2019-01-29 22:34:35 +01:00
Jonas Schievink
b664341d91 Make weak_count return an Option<usize> 2019-01-29 21:58:17 +01:00
Jonas Schievink
2fe3b3b486 Implement Weak::{strong_count, weak_count} 2019-01-29 21:07:35 +01:00
Dale Wijnand
1e577269da
Introduce into_raw_non_null on Rc and Arc 2019-01-28 22:24:26 +00:00
Ralf Jung
c11e514e9d liballoc: remove unneeded allow(deprecated) 2019-01-28 10:39:49 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Mazdak Farrokhzad
93af1e7369
Rollup merge of #56939 - cramertj:pin-stabilization, r=alexcrichton
Pin stabilization

This implements the changes suggested in https://github.com/rust-lang/rust/issues/55766#issue-378417538 and stabilizes the `pin` feature. @alexcrichton also listed several "blockers" in that issue, but then in [this comment](https://github.com/rust-lang/rust/issues/55766#issuecomment-445074980) mentioned that they're more "TODO items":
>  In that vein I think it's fine for a stabilization PR to be posted at any time now with FCP lapsed for a week or so now. The final points about self/pin/pinned can be briefly discussed there (if even necessary, they could be left as the proposal above).

Let's settle these last bits here and get this thing stabilized! :)

r? @alexcrichton
cc @withoutboats
2018-12-23 23:09:04 +01:00
kennytm
14ebca5c19
Rollup merge of #56941 - euclio:deny-libstd-resolution-failures, r=QuietMisdreavus
deny intra-doc link resolution failures in libstd

Fixes #56693.

Until we land a fix for the underlying issue (#56922), we can at least fix the failures in libstd so they don't propagate to downstream crates.
2018-12-23 02:11:59 +08:00
Taylor Cramer
684fe9a6b2 Rename Box/Arc/Rc::pinned to ::pin 2018-12-21 20:42:50 -08:00
Taylor Cramer
610bcaf6f3 Stabilize Pin 2018-12-21 20:42:50 -08:00
Michael Hewson
153f5a7892 Stabilize Rc, Arc and Pin as method receivers
This lets you write methods using `self: Rc<Self>`, `self: Arc<Self>`, `self: Pin<&mut Self>`, `self: Pin<Box<Self>`, and other combinations involving `Pin` and another stdlib receiver type, without needing the `arbitrary_self_types`. Other user-created receiver types can be used, but they still require the feature flag to use.

This is implemented by introducing a new trait, `Receiver`, which the method receiver's type must implement if the `arbitrary_self_types` feature is not enabled. To keep composed receiver types such as `&Arc<Self>` unstable, the receiver type is also required to implement `Deref<Target=Self>` when the feature flag is not enabled.

This lets you use `self: Rc<Self>` and `self: Arc<Self>` in stable Rust, which was not allowed previously. It was agreed that they would be stabilized in #55786. `self: Pin<&Self>` and other pinned receiver types do not require the `arbitrary_self_types` feature, but they cannot be used on stable because `Pin` still requires the `pin` feature.
2018-12-20 01:14:01 -05:00
Andy Russell
82e55c1bdc
deny intra-doc link resolution failures in libstd 2018-12-17 21:10:24 -05:00
Thomas Heck
40d60a4608 Use private trait for Rc/Arc Eq specialization 2018-12-08 13:30:54 +01:00
Jo Liss
2a916a617f Short-circuit Rc/Arc equality checking on equal pointers where T: Eq
Closes #42655
2018-12-08 13:30:54 +01:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Pietro Albini
1594a4245b
Rollup merge of #55987 - Thomasdezeeuw:weak-ptr_eq, r=sfackler
Add Weak.ptr_eq

I hope the doc tests alone are good enough.

We also might want to discuss the dangling pointer case (from `Weak::new()`).

Updates #55981.
2018-12-05 23:54:24 +01:00
Thomas de Zeeuw
38e21f92f1 Fix link in Weak::new 2018-12-03 10:49:33 +01:00
Thomas de Zeeuw
380dd7d47b Add rc::Weak.ptr_eq 2018-12-03 10:49:27 +01:00
Corey Farwell
ebb1a48b41
Merge branch 'master' into frewsxcv-dyn 2018-11-23 14:09:08 -05:00
Steve Klabnik
d7b3f5c6ae update various stdlib docs 2018-11-21 06:50:17 -05:00
Corey Farwell
033cbfec4d Incorporate dyn into more comments and docs. 2018-11-20 09:35:03 -05:00
Murarth
317f494c72 Fix Rc/Arc allocation layout
* Rounds allocation layout up to a multiple of alignment
* Adds a convenience method `Layout::pad_to_align` to perform rounding
2018-11-08 11:50:02 -07:00
bors
65e485d8f1 Auto merge of #54922 - murarth:rc-ub-fix, r=alexcrichton
Fix undefined behavior in Rc/Arc allocation

Manually calculate allocation layout for `Rc`/`Arc` to avoid undefined behavior

Closes #54908
2018-11-05 22:20:25 +00:00
Murarth
d60290fc63 Fix undefined behavior in Rc/Arc allocation
Manually calculate allocation layout for `Rc`/`Arc` to avoid undefined behavior
2018-11-05 10:33:30 -07:00
Michael Hewson
f12c250e40 Replace CoerceSized trait with DispatchFromDyn
Rename `CoerceSized` to `DispatchFromDyn`, and reverse the direction so that, for example, you write

```
impl<T: Unsize<U>, U> DispatchFromDyn<*const U> for *const T {}
```

instead of

```
impl<T: Unsize<U>, U> DispatchFromDyn<*const T> for *const U {}
```

this way the trait is really just a subset of `CoerceUnsized`.

The checks in object_safety.rs are updated for the new trait, and some documentation and method names in there are updated for the new trait name — e.g. `receiver_is_coercible` is now called `receiver_is_dispatchable`. Since the trait now works in the opposite direction, some code had to updated here for that too.

I did not update the error messages for invalid `CoerceSized` (now `DispatchFromDyn`) implementations, except to find/replace `CoerceSized` with `DispatchFromDyn`. Will ask for suggestions in the PR thread.
2018-11-01 18:16:59 -04:00
Michael Hewson
192900e7c2 Add CoerceSized impls throughout libstd
This will make receiver types like `Rc<Self>` and `Pin<&mut Self>`
object-safe.
2018-11-01 18:16:22 -04:00
Alex Crichton
d0060d72e5 Bump nightly to 1.32.0
* Also update the bootstrap compiler
* Update cargo to 1.32.0
* Clean out stage0 annotations
2018-10-31 11:53:50 -07:00
Zack M. Davis
ab91a6b4df #[must_use] for associated functions is supposed to actually work
In the comments of (closed, defunct) pull request #54884, Mazdak
"Centril" Farrokhzad noted that must-use annotations didn't work on an
associated function (what other communities might call a "static
method"). Subsequent logging revealed that in this case we have a
`Def::Method`, whereas the lint pass was only matching on
`Def::Fn`. (One could argue that those def-names are thereby
misleading—must-use for self-ful methods have always worked—but
documenting or reworking that can be left to another day.)
2018-10-12 22:01:43 -07:00
David Wood
da4a12038b
Introduce language items for Arc and Rc.
This commit introduces language items for `Arc` and `Rc` so that types
can later be checked to be `Arc` or `Rc` in the NLL borrow checker. The
`lang` attribute is currently limited to `stage1` as it requires a
compiler built with knowledge of the expected language items.
2018-10-01 13:50:21 +02:00
bors
1e21c9a297 Auto merge of #53877 - withoutboats:compositional-pin, r=aturon
Update to a new pinning API.

~~Blocked on #53843 because of method resolution problems with new pin type.~~

@r? @cramertj

cc @RalfJung @pythonesque anyone interested in #49150
2018-09-19 06:56:19 +00:00
bors
06da917b01 Auto merge of #51885 - GuillaumeGomez:trait-impl-show-docs, r=Mark-Simulacrum,QuietMisdreavus
Trait impl show docs

Fixes #51834.

<img width="1440" alt="screen shot 2018-06-29 at 00 14 33" src="https://user-images.githubusercontent.com/3050060/42063323-6e6e8cc8-7b31-11e8-88ef-4dd2229df76c.png">

(You can see both commit changes in the screenshot 😄)

r? @QuietMisdreavus
2018-09-08 04:14:54 +00:00
Guillaume Gomez
c1ad1b0338 Fix invalid urls 2018-09-06 23:32:30 +02:00
Without Boats
974bdc80fe
Update to a new pinning API. 2018-09-01 06:57:58 +02:00
Without Boats
9ff29d6188
Fix Rc impl. 2018-09-01 05:04:46 +02:00
Without Boats
c3bdd76047
Implement Unpin for Box, Rc, and Arc 2018-09-01 01:54:59 +02:00
bors
9f9f2c0095 Auto merge of #53530 - kennytm:rollup, r=kennytm
Rollup of 17 pull requests

Successful merges:

 - #53030 (Updated RELEASES.md for 1.29.0)
 - #53104 (expand the documentation on the `Unpin` trait)
 - #53213 (Stabilize IP associated constants)
 - #53296 (When closure with no arguments was expected, suggest wrapping)
 - #53329 (Replace usages of ptr::offset with ptr::{add,sub}.)
 - #53363 (add individual docs to `core::num::NonZero*`)
 - #53370 (Stabilize macro_vis_matcher)
 - #53393 (Mark libserialize functions as inline)
 - #53405 (restore the page title after escaping out of a search)
 - #53452 (Change target triple used to check for lldb in build-manifest)
 - #53462 (Document Box::into_raw returns non-null ptr)
 - #53465 (Remove LinkMeta struct)
 - #53492 (update lld submodule to include RISCV patch)
 - #53496 (Fix typos found by codespell.)
 - #53521 (syntax: Optimize some literal parsing)
 - #53540 (Moved issue-53157.rs into src/test/ui/consts/const-eval/)
 - #53551 (Avoid some Place clones.)

Failed merges:

r? @ghost
2018-08-21 16:04:11 +00:00
Corey Farwell
993fb93464 Replace usages of ptr::offset with ptr::{add,sub}. 2018-08-20 07:28:34 -04:00
Dmytro Shynkevych
4e17fbde0b Fixed typo 2018-08-05 02:41:14 -04:00
Dmytro Shynkevych
1553ea2316 Changed Rc::inc_{weak,strong} to better hint optimization to LLVM 2018-08-04 15:41:12 -04:00
Ralf Jung
a303741334 typos 2018-07-23 12:53:37 +02:00
Ralf Jung
33b8f6253f Don't use NonNull::dangling as sentinel value
Instead, rely on alignment and use usize::MAX as sentinel.
2018-07-23 11:31:55 +02:00
ljedrz
217f8fbd45 Revert borked changes in last commit. 2018-07-11 10:19:54 +02:00
ljedrz
cd44b3ddad Add missing dyn in liballoc 2018-07-10 22:32:19 +02:00
ljedrz
296e72f11c Deny bare trait objects in in src/liballoc 2018-07-10 20:45:16 +02:00
Mark Rousskov
e3823388a8
Rollup merge of #52103 - tmccombs:rc_downcast, r=Mark-Simulacrum
Stabilize rc_downcast

Fixes #44608
2018-07-06 21:29:17 -06:00
Simon Sapin
67202b8b68 Fix is_dangling import when Arc is #[cfg]’ed out 2018-07-07 01:44:57 +02:00
Simon Sapin
41730b7e2e Rc: remove unused allocation from Weak::new()
Same as https://github.com/rust-lang/rust/pull/50357
2018-07-07 01:41:30 +02:00