- [proc_macro](language-features/proc-macro.md)
- [quote](language-features/quote.md)
- [relaxed_adts](language-features/relaxed-adts.md)
+ - [repr_align](language-features/repr-align.md)
- [repr_simd](language-features/repr-simd.md)
- [rustc_attrs](language-features/rustc-attrs.md)
- [rustc_diagnostic_macros](language-features/rustc-diagnostic-macros.md)
- [alloc_system](library-features/alloc-system.md)
- [alloc](library-features/alloc.md)
- [as_c_str](library-features/as-c-str.md)
- - [as_unsafe_cell](library-features/as-unsafe-cell.md)
- [ascii_ctype](library-features/ascii-ctype.md)
- - [binary_heap_extras](library-features/binary-heap-extras.md)
- [binary_heap_peek_mut_pop](library-features/binary-heap-peek-mut-pop.md)
- - [borrow_state](library-features/borrow-state.md)
- [box_heap](library-features/box-heap.md)
- [c_void_variant](library-features/c-void-variant.md)
- [char_escape_debug](library-features/char-escape-debug.md)
- [derive_clone_copy](library-features/derive-clone-copy.md)
- [derive_eq](library-features/derive-eq.md)
- [discriminant_value](library-features/discriminant-value.md)
- - [enumset](library-features/enumset.md)
- [error_type_id](library-features/error-type-id.md)
- [exact_size_is_empty](library-features/exact-size-is-empty.md)
- [fd](library-features/fd.md)
- [fd_read](library-features/fd-read.md)
- [fixed_size_array](library-features/fixed-size-array.md)
- [float_bits_conv](library-features/float-bits-conv.md)
- - [float_extras](library-features/float-extras.md)
- [flt2dec](library-features/flt2dec.md)
- [fmt_flags_align](library-features/fmt-flags-align.md)
- [fmt_internals](library-features/fmt-internals.md)
- [io_error_internals](library-features/io-error-internals.md)
- [io](library-features/io.md)
- [ip](library-features/ip.md)
- - [is_unique](library-features/is-unique.md)
- [iter_rfind](library-features/iter-rfind.md)
- [libstd_io_internals](library-features/libstd-io-internals.md)
- [libstd_sys_internals](library-features/libstd-sys-internals.md)
- [linked_list_extras](library-features/linked-list-extras.md)
- [lookup_host](library-features/lookup-host.md)
- [manually_drop](library-features/manually-drop.md)
- - [map_entry_recover_keys](library-features/map-entry-recover-keys.md)
- [mpsc_select](library-features/mpsc-select.md)
- [n16](library-features/n16.md)
- [never_type_impls](library-features/never-type-impls.md)
- [rand](library-features/rand.md)
- [range_contains](library-features/range-contains.md)
- [raw](library-features/raw.md)
- - [rc_would_unwrap](library-features/rc-would-unwrap.md)
- [retain_hash_collection](library-features/retain-hash-collection.md)
- [reverse_cmp_key](library-features/reverse-cmp-key.md)
- [rt](library-features/rt.md)
- [windows_handle](library-features/windows-handle.md)
- [windows_net](library-features/windows-net.md)
- [windows_stdio](library-features/windows-stdio.md)
- - [zero_one](library-features/zero-one.md)
- >>>>>> Add top level sections to the Unstable Book.
use core::ptr::{self, Shared};
use core::convert::From;
-use heap::deallocate;
+use heap::{allocate, deallocate, box_free};
use raw_vec::RawVec;
struct RcBox<T: ?Sized> {
value: T,
}
-
/// A single-threaded reference-counting pointer.
///
/// See the [module-level documentation](./index.html) for more details.
}
}
- /// Checks whether [`Rc::try_unwrap`][try_unwrap] would return
- /// [`Ok`].
- ///
- /// [try_unwrap]: struct.Rc.html#method.try_unwrap
- /// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
- #[unstable(feature = "rc_would_unwrap",
- reason = "just added for niche usecase",
- issue = "28356")]
- #[rustc_deprecated(since = "1.15.0", reason = "too niche; use `strong_count` instead")]
- pub fn would_unwrap(this: &Self) -> bool {
- Rc::strong_count(&this) == 1
- }
-
/// Consumes the `Rc`, returning the wrapped pointer.
///
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
}
}
+impl<T> Rc<[T]> {
+ /// Constructs a new `Rc<[T]>` from a `Box<[T]>`.
+ #[doc(hidden)]
+ #[unstable(feature = "rustc_private",
+ reason = "for internal use in rustc",
+ issue = "0")]
+ pub fn __from_array(value: Box<[T]>) -> Rc<[T]> {
+ unsafe {
+ let ptr: *mut RcBox<[T]> =
+ mem::transmute([mem::align_of::<RcBox<[T; 1]>>(), value.len()]);
+ // FIXME(custom-DST): creating this invalid &[T] is dubiously defined,
+ // we should have a better way of getting the size/align
+ // of a DST from its unsized part.
+ let ptr = allocate(size_of_val(&*ptr), align_of_val(&*ptr));
+ let ptr: *mut RcBox<[T]> = mem::transmute([ptr as usize, value.len()]);
+
+ // Initialize the new RcBox.
+ ptr::write(&mut (*ptr).strong, Cell::new(1));
+ ptr::write(&mut (*ptr).weak, Cell::new(1));
+ ptr::copy_nonoverlapping(
+ value.as_ptr(),
+ &mut (*ptr).value as *mut [T] as *mut T,
+ value.len());
+
+ // Free the original allocation without freeing its (moved) contents.
+ box_free(Box::into_raw(value));
+
+ Rc { ptr: Shared::new(ptr as *const _) }
+ }
+ }
+}
+
impl<T: ?Sized> Rc<T> {
/// Creates a new [`Weak`][weak] pointer to this value.
///
///
/// [weak]: struct.Weak.html
#[inline]
- #[unstable(feature = "is_unique", reason = "uniqueness has unclear meaning",
- issue = "28356")]
- #[rustc_deprecated(since = "1.15.0",
- reason = "too niche; use `strong_count` and `weak_count` instead")]
- pub fn is_unique(this: &Self) -> bool {
+ fn is_unique(this: &Self) -> bool {
Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1
}
self.sift_up(0, old_len);
}
- /// Pushes an item onto the binary heap, then pops the greatest item off the queue in
- /// an optimized fashion.
- ///
- /// # Examples
- ///
- /// Basic usage:
- ///
- /// ```
- /// #![feature(binary_heap_extras)]
- /// #![allow(deprecated)]
- ///
- /// use std::collections::BinaryHeap;
- /// let mut heap = BinaryHeap::new();
- /// heap.push(1);
- /// heap.push(5);
- ///
- /// assert_eq!(heap.push_pop(3), 5);
- /// assert_eq!(heap.push_pop(9), 9);
- /// assert_eq!(heap.len(), 2);
- /// assert_eq!(heap.peek(), Some(&3));
- /// ```
- #[unstable(feature = "binary_heap_extras",
- reason = "needs to be audited",
- issue = "28147")]
- #[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")]
- pub fn push_pop(&mut self, mut item: T) -> T {
- match self.data.get_mut(0) {
- None => return item,
- Some(top) => {
- if *top > item {
- swap(&mut item, top);
- } else {
- return item;
- }
- }
- }
-
- self.sift_down(0);
- item
- }
-
- /// Pops the greatest item off the binary heap, then pushes an item onto the queue in
- /// an optimized fashion. The push is done regardless of whether the binary heap
- /// was empty.
- ///
- /// # Examples
- ///
- /// Basic usage:
- ///
- /// ```
- /// #![feature(binary_heap_extras)]
- /// #![allow(deprecated)]
- ///
- /// use std::collections::BinaryHeap;
- /// let mut heap = BinaryHeap::new();
- ///
- /// assert_eq!(heap.replace(1), None);
- /// assert_eq!(heap.replace(3), Some(1));
- /// assert_eq!(heap.len(), 1);
- /// assert_eq!(heap.peek(), Some(&3));
- /// ```
- #[unstable(feature = "binary_heap_extras",
- reason = "needs to be audited",
- issue = "28147")]
- #[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")]
- pub fn replace(&mut self, mut item: T) -> Option<T> {
- if !self.is_empty() {
- swap(&mut item, &mut self.data[0]);
- self.sift_down(0);
- Some(item)
- } else {
- self.push(item);
- None
- }
- }
-
/// Consumes the `BinaryHeap` and returns the underlying vector
/// in arbitrary order.
///
/// An owning iterator over the elements of a `BinaryHeap`.
///
-/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`]
+/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`][`BinaryHeap`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.BinaryHeap.html#method.into_iter
/// An owning iterator over the entries of a `BTreeMap`.
///
-/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`]
+/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`][`BTreeMap`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.BTreeMap.html#method.into_iter
self.handle.reborrow().into_kv().0
}
- /// Deprecated, renamed to `remove_entry`
- #[unstable(feature = "map_entry_recover_keys", issue = "34285")]
- #[rustc_deprecated(since = "1.12.0", reason = "renamed to `remove_entry`")]
- pub fn remove_pair(self) -> (K, V) {
- self.remove_entry()
- }
-
/// Take ownership of the key and value from the map.
///
/// # Examples
/// An owning iterator over the entries of a `HashMap`.
///
-/// This `struct` is created by the [`into_iter`] method on [`HashMap`]
+/// This `struct` is created by the [`into_iter`] method on [`HashMap`][`HashMap`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.HashMap.html#method.into_iter
self.elem.read().0
}
- /// Deprecated, renamed to `remove_entry`
- #[unstable(feature = "map_entry_recover_keys", issue = "34285")]
- #[rustc_deprecated(since = "1.12.0", reason = "renamed to `remove_entry`")]
- pub fn remove_pair(self) -> (K, V) {
- self.remove_entry()
- }
-
/// Take the ownership of the key and value from the map.
///
/// # Examples