about summary refs log tree commit diff
path: root/src/libcore/cell.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-1724/+0
2020-06-30Deny unsafe ops in unsafe fns, part 6LeSeulArtichaut-1/+0
And final part!!!
2020-06-30Deny unsafe ops in unsafe fns, part 1LeSeulArtichaut-1/+7
2020-06-13Rollup merge of #73302 - JakobDegen:should-panic-documentation, ↵Dylan DPC-18/+8
r=Mark-Simulacrum Adjusted some doctests in libcore to use `should_panic`. Fixes #73196 . I grepped libstd and libcore for all the instances of this pattern that I could find, but its possible that I missed some of course. If anyone knows of any more, please let me know and I will add them to the PR.
2020-06-13Adjusted some doctests in libcore to use `should_panic`.Jake Degen-18/+8
Previously, some doctests were spawning new threads and joining them to indicate that a particular call should panic; this hurt readability, so the tests have been adjusted to simply call the method and use the `should_panic` marker.
2020-06-10Migrate to numeric associated constsLzu Tao-5/+5
2020-05-27Rollup merge of #72606 - GuillaumeGomez:cell-example-update, r=Dylan-DPCDylan DPC-3/+3
Small cell example update r? @Dylan-DPC
2020-05-26Small cell example updateGuillaume Gomez-3/+3
2020-05-17make abort intrinsic safe, and correct its documentationRalf Jung-3/+2
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