about summary refs log tree commit diff
path: root/src/libcore/cell.rs
AgeCommit message (Collapse)AuthorLines
2020-05-03Mention `RefCell::take` can panic in docsThinkChaos-0/+4
2020-04-26Add `RefCell::take`ThinkChaos-0/+21
In the same vein as `Cell::take` and `Option::take`.
2020-03-17Rollup merge of #70029 - jonas-schievink:bootstrap, r=CentrilMazdak Farrokhzad-1/+1
Bump the bootstrap compiler
2020-03-15Bump the bootstrap compilerJonas Schievink-1/+1
2020-03-15Rollup merge of #69528 - HeroicKatora:finalize-ref-cell, r=dtolnayMazdak Farrokhzad-5/+36
Add undo_leak to reset RefCell borrow state This method is complementary for the feature cell_leak added in an earlier PR. It allows *safely* reverting the effects of leaking a borrow guard by statically proving that such a guard could not longer exist. This was not added to the existing `get_mut` out of concern of impacting the complexity of the otherwise pure pointer cast and because the name `get_mut` poorly communicates the intent of resetting remaining borrows. This is a follow-up to #68712 and uses the same tracking issue, #69099, as these methods deal with the same mechanism and the idea came up [in a review comment](https://github.com/rust-lang/rust/pull/68712#discussion_r384670041). @dtolnay who reviewed the prior PR. cc @RalfJung
2020-03-04Add unborrow to reset RefCell borrow stateAndreas Molzer-5/+36
This method is complementary for the feature refcell_leak added in an earlier PR. It allows reverting the effects of leaking a borrow guard by statically proving that such a guard could not longer exist. This was not added to the existing `get_mut` out of concern of impacting the complexity of the otherwise pure pointer cast and because the name `get_mut` poorly communicates the intent of resetting remaining borrows.
2020-02-26Rollup merge of #68712 - HeroicKatora:finalize-ref-cell, r=dtolnayDylan DPC-0/+63
Add methods to 'leak' RefCell borrows as references with the lifetime of the original reference Usually, references to the interior are only created by the `Deref` and `DerefMut` impl of the guards `Ref` and `RefMut`. Note that `RefCell` already has to cope with leaks of such guards which, when it occurs, effectively makes it impossible to ever acquire a mutable guard or any guard for `Ref` and `RefMut` respectively. It is already safe to use this to create a reference to the inner of the ref cell that lives as long as the reference to the `RefCell` itself, e.g. ```rust fn leak(r: &RefCell<usize>) -> Option<&usize> { let guard = r.try_borrow().ok()?; let leaked = Box::leak(Box::new(guard)); Some(&*leaked) } ``` The newly added methods allow the same reference conversion without an indirection over a leaked allocation. It's placed on the `Ref`/`RefMut` to compose with both borrow and try_borrow directly.
2020-02-24Address method commentsAndreas Molzer-3/+2
2020-02-12Add tracking number, adjust documentation wordingAndreas Molzer-4/+5
2020-02-10Add `repr(no_niche)` to `UnsafeCell`. Fix #68303.Felix S. Klock II-0/+1
2020-01-31Add methods to leak RefCell borrows to referencesAndreas Molzer-0/+63
Usually, references to the interior are only created by the `Deref` and `DerefMut` impl of the guards `Ref` and `RefMut`. Note that `RefCell` already has to cope with leaks of such guards which, when it occurs, effectively makes it impossible to ever acquire a mutable guard or any guard for `Ref` and `RefMut` respectively. It is already safe to use this to create a reference to the inner of the ref cell that lives as long as the reference to the `RefCell` itself, e.g. ```rust fn leak(r: &RefCell<usize>) -> Option<&usize> { let guard = r.try_borrow().ok()?; let leaked = Box::leak(Box::new(guard)); Some(&*leaked) } ``` The newly added methods allow the same reference conversion without an indirection over a leaked allocation and composing with both borrow and try_borrow without additional method combinations.
2020-01-16Elaborate on SAFETY commentsPhoebe Bell-9/+16
2020-01-16Fix typo "gurantees -> guarantees"Phoebe Bell-1/+1
2020-01-16Document unsafe blocks in core::{cell, str, sync}Phoebe Bell-2/+10
2019-12-22Format the worldMark Rousskov-52/+29
2019-12-18Propagate cfg bootstrapMark Rousskov-11/+5
2019-12-13Require stable/unstable annotations for the constness of all stable ↵Oliver Scherer-0/+11
functions with a `const` modifier
2019-11-13make things uglyRalf Jung-3/+3
2019-11-13expand docsRalf Jung-2/+7
2019-11-13clarify why we can do the ptr castRalf Jung-3/+5
2019-11-13Trailing full stopRalf Jung-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-11-09add raw ptr variant of UnsafeCell::getRalf Jung-0/+30
2019-11-07Rollup merge of #63793 - oli-obk:🧹, r=dtolnayMazdak Farrokhzad-0/+2
Have tidy ensure that we document all `unsafe` blocks in libcore cc @rust-lang/libs I documented a few and added ignore flags on the other files. We can incrementally document the files, but won't regress any files this way.
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-0/+2
2019-11-06Fixed libcore/cell.rs exampleOleg Nosov-1/+4
2019-11-05Reverted PhantomData in LinkedList, fixed PhantomData markers in Rc and ArcOleg Nosov-1/+3
2019-10-03Reorder methods of CellShotaro Yamada-46/+46
To make `new` method appear first in documentation.
2019-07-27Auto merge of #62748 - luca-barbieri:optimize-refcell-borrow, r=RalfJungbors-5/+15
Optimize RefCell read borrowing Instead of doing two comparisons we can do only one with a bit of cleverness. LLVM currently can't do this optimization itself on x86-64.
2019-07-21fix commentLuca Barbieri-1/+1
2019-07-21Expand comment on BorrowRef::newLuca Barbieri-2/+12
2019-07-17Optimize RefCell read borrowingLuca Barbieri-3/+3
Instead of doing two comparisons we can do only one with a bit of cleverness. LLVM currently can't do this optimization itself on x86-64.
2019-07-16state also in the intro that UnsafeCell has no effect on &mutRalf Jung-2/+3
2019-07-13add spaces in front of trait requirementsDodo-6/+6
2019-06-07Stabilize Cell::from_mut and as_slice_of_cellsSimon Sapin-4/+2
FCP: https://github.com/rust-lang/rust/issues/43038#issuecomment-499900463
2019-06-05Aggregation of drive-by cosmetic changes.Alexander Regueiro-1/+1
2019-05-30Rollup merge of #60850 - SimonSapin:unguarded, r=alexcrichtonMazdak Farrokhzad-2/+1
Stabilize RefCell::try_borrow_unguarded Servo has been using this since https://github.com/servo/servo/pull/23196 to add a runtime check to some unsafe code, as discussed in PR https://github.com/rust-lang/rust/pull/59211. Stabilizing would help do more of the same in libraries that also have users on Stable.
2019-05-23typoBrent Kerby-1/+1
2019-05-21Simplify RefCell minimum_spanning_tree exampleBrent Kerby-24/+22
2019-05-15Stabilize RefCell::try_borrow_unguardedSimon Sapin-2/+1
Servo has been using this since https://github.com/servo/servo/pull/23196 to add a runtime check to some unsafe code, as discussed in PR https://github.com/rust-lang/rust/pull/59211. Stabilizing would help do more of the same in libraries that also have users on Stable.
2019-04-19libcore: deny more...Mazdak Farrokhzad-10/+10
2019-04-18libcore => 2018Taiki Endo-6/+6
2019-04-11Auto merge of #59211 - nox:refcell-borrow-state, r=KodrAusbors-0/+38
Introduce RefCell::try_borrow_unguarded *Come sit next to the fireplace with me, this is going to be a long story.* So, you may already be aware that Servo has weird design constraints that forces us developers working on it to do weird things. The thing that interests us today is that we do layout on a separate thread with its own thread pool to do some things in parallel, whereas the data it uses comes from the script thread, which implements the entire DOM and related pieces, with `!Sync` data types such as `RefCell<T>`. The invariant we maintain is that script does not do anything ever with the DOM data as long as layout is doing its job. That's all nice and all, but one thing we don't ensure is that we don't actually know if script was currently mutably borrowing some `RefCell<T>` prior to starting layout, which may lead to aliasing mutable memory and obviously undefined behaviour. This PR reinstates `RefCell::borrow_state` so that [this method](https://github.com/servo/servo/blob/master/components/script/dom/bindings/cell.rs#L23-L30) can make use of it and return `None` if the cell was mutably borrowed. Cc @SimonSapin
2019-03-31Rollup merge of #59581 - jmcomets:stabilize-refcell_replace_swap, r=CentrilMazdak Farrokhzad-4/+1
Stabilize refcell_replace_swap feature Please be kind, this is my first time contributing. :smile: I noticed #43570 only needs stabilizing (and I need it for a side project I'm working on), so I followed the [guide](https://rust-lang.github.io/rustc-guide/stabilization_guide.html#stabilization-pr) to move things forward. I'm happy to amend things if needed, let me know!
2019-03-31refcell_replace_swap: remove feature gate & obsolete documentation itemJean-Marie Comets-2/+0
2019-03-31Stabilize refcell_replace_swap feature, closes #43570Jean-Marie Comets-2/+1
2019-03-30Fix doc testsFabian Drinck-1/+0
2019-03-19Introduce RefCell::try_borrow_unguardedAnthony Ramine-49/+38
This replaces RefCell::borrow_state to something that encodes the use case of Servo better.
2019-03-18Stabilize refcell_map_split featureJoshua Liebow-Feeser-4/+2
- Closes #51476
2019-03-16Tweak documentation of RefCell::borrow_stateAnthony Ramine-6/+10
2019-03-15Revert "Deprecate std::cell::RefCell::borrow_state"Anthony Ramine-4/+0
This reverts commit dc2d5058e999abb18ab2686b4e3e385ec6e36666.