alloc: Split apart the global `alloc` feature

This commit is contained in:
Alex Crichton 2015-06-09 11:52:41 -07:00
parent c14d86fd3f
commit c44f5399e4
12 changed files with 54 additions and 36 deletions

View File

@ -134,7 +134,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be
/// used to break cycles between `Arc` pointers.
#[unsafe_no_drop_flag]
#[unstable(feature = "alloc",
#[unstable(feature = "arc_weak",
reason = "Weak pointers may not belong in this module.")]
pub struct Weak<T: ?Sized> {
// FIXME #12808: strange name to try to avoid interfering with
@ -198,7 +198,7 @@ impl<T: ?Sized> Arc<T> {
///
/// let weak_five = five.downgrade();
/// ```
#[unstable(feature = "alloc",
#[unstable(feature = "arc_weak",
reason = "Weak pointers may not belong in this module.")]
pub fn downgrade(&self) -> Weak<T> {
// See the clone() impl for why this is relaxed
@ -236,12 +236,12 @@ impl<T: ?Sized> Arc<T> {
/// Get the number of weak references to this value.
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "arc_extras")]
pub fn weak_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().weak.load(SeqCst) - 1 }
/// Get the number of strong references to this value.
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "arc_extras")]
pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().strong.load(SeqCst) }
@ -271,7 +271,7 @@ pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().strong.loa
/// # }
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "arc_extras")]
pub unsafe fn get_mut<T: ?Sized>(this: &mut Arc<T>) -> Option<&mut T> {
// FIXME(#24880) potential race with upgraded weak pointers here
if strong_count(this) == 1 && weak_count(this) == 0 {
@ -352,7 +352,7 @@ impl<T: Clone> Arc<T> {
/// # }
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "arc_extras")]
pub unsafe fn make_unique(&mut self) -> &mut T {
// FIXME(#24880) potential race with upgraded weak pointers here
//
@ -438,7 +438,7 @@ impl<T: ?Sized> Drop for Arc<T> {
}
}
#[unstable(feature = "alloc",
#[unstable(feature = "arc_weak",
reason = "Weak pointers may not belong in this module.")]
impl<T: ?Sized> Weak<T> {
/// Upgrades a weak reference to a strong reference.
@ -479,7 +479,7 @@ impl<T: ?Sized> Weak<T> {
}
}
#[unstable(feature = "alloc",
#[unstable(feature = "arc_weak",
reason = "Weak pointers may not belong in this module.")]
impl<T: ?Sized> Clone for Weak<T> {
/// Makes a clone of the `Weak<T>`.

View File

@ -81,7 +81,7 @@ use core::raw::{TraitObject};
/// }
/// ```
#[lang = "exchange_heap"]
#[unstable(feature = "alloc",
#[unstable(feature = "box_heap",
reason = "may be renamed; uncertain about custom allocator design")]
pub const HEAP: () = ();
@ -121,7 +121,7 @@ impl<T : ?Sized> Box<T> {
/// Function is unsafe, because improper use of this function may
/// lead to memory problems like double-free, for example if the
/// function is called twice on the same raw pointer.
#[unstable(feature = "alloc",
#[unstable(feature = "box_raw",
reason = "may be renamed or moved out of Box scope")]
#[inline]
pub unsafe fn from_raw(raw: *mut T) -> Self {
@ -146,7 +146,7 @@ impl<T : ?Sized> Box<T> {
/// let raw = boxed::into_raw(seventeen);
/// let boxed_again = unsafe { Box::from_raw(raw) };
/// ```
#[unstable(feature = "alloc",
#[unstable(feature = "box_raw",
reason = "may be renamed")]
#[inline]
pub fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T {

View File

@ -8,6 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![unstable(feature = "heap_api",
reason = "the precise API and guarantees it provides may be tweaked \
slightly, especially to possibly take into account the \
types being stored to make room for a future \
tracing garbage collector")]
use core::{isize, usize};
#[inline(always)]
@ -94,7 +100,6 @@ pub fn usable_size(size: usize, align: usize) -> usize {
///
/// These statistics may be inconsistent if other threads use the allocator
/// during the call.
#[unstable(feature = "alloc")]
pub fn stats_print() {
imp::stats_print();
}

View File

@ -59,9 +59,11 @@
// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
#![cfg_attr(stage0, feature(custom_attribute))]
#![crate_name = "alloc"]
#![unstable(feature = "alloc")]
#![staged_api]
#![crate_type = "rlib"]
#![staged_api]
#![unstable(feature = "alloc",
reason = "this library is unlikely to be stabilized in its current \
form or name")]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
@ -86,11 +88,11 @@
#![feature(unique)]
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(unsize)]
#![cfg_attr(test, feature(test, alloc, rustc_private))]
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
feature(libc))]
#[macro_use]
extern crate core;
@ -124,6 +126,7 @@ pub mod rc;
/// Common out-of-memory routine
#[cold]
#[inline(never)]
#[unstable(feature = "oom", reason = "not a scrutinized interface")]
pub fn oom() -> ! {
// FIXME(#14674): This really needs to do something other than just abort
// here, but any printing done must be *guaranteed* to not
@ -144,4 +147,5 @@ pub fn oom() -> ! {
// to get linked in to libstd successfully (the linker won't
// optimize it out).
#[doc(hidden)]
#[unstable(feature = "issue_14344_fixme")]
pub fn fixme_14344_be_sure_to_link_to_collections() {}

View File

@ -236,7 +236,7 @@ impl<T: ?Sized> Rc<T> {
///
/// let weak_five = five.downgrade();
/// ```
#[unstable(feature = "alloc",
#[unstable(feature = "rc_weak",
reason = "Weak pointers may not belong in this module")]
pub fn downgrade(&self) -> Weak<T> {
self.inc_weak();
@ -246,12 +246,12 @@ impl<T: ?Sized> Rc<T> {
/// Get the number of weak references to this value.
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "rc_extras")]
pub fn weak_count<T: ?Sized>(this: &Rc<T>) -> usize { this.weak() - 1 }
/// Get the number of strong references to this value.
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "rc_extras")]
pub fn strong_count<T: ?Sized>(this: &Rc<T>) -> usize { this.strong() }
/// Returns true if there are no other `Rc` or `Weak<T>` values that share the
@ -269,7 +269,7 @@ pub fn strong_count<T: ?Sized>(this: &Rc<T>) -> usize { this.strong() }
/// rc::is_unique(&five);
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "rc_extras")]
pub fn is_unique<T>(rc: &Rc<T>) -> bool {
weak_count(rc) == 0 && strong_count(rc) == 1
}
@ -292,7 +292,7 @@ pub fn is_unique<T>(rc: &Rc<T>) -> bool {
/// assert_eq!(rc::try_unwrap(x), Err(Rc::new(4)));
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "rc_extras")]
pub fn try_unwrap<T>(rc: Rc<T>) -> Result<T, Rc<T>> {
if is_unique(&rc) {
unsafe {
@ -327,7 +327,7 @@ pub fn try_unwrap<T>(rc: Rc<T>) -> Result<T, Rc<T>> {
/// assert!(rc::get_mut(&mut x).is_none());
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "rc_extras")]
pub fn get_mut<T>(rc: &mut Rc<T>) -> Option<&mut T> {
if is_unique(rc) {
let inner = unsafe { &mut **rc._ptr };
@ -354,7 +354,7 @@ impl<T: Clone> Rc<T> {
/// let mut_five = five.make_unique();
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "rc_extras")]
pub fn make_unique(&mut self) -> &mut T {
if !is_unique(self) {
*self = Rc::new((**self).clone())
@ -652,7 +652,7 @@ impl<T> fmt::Pointer for Rc<T> {
///
/// See the [module level documentation](./index.html) for more.
#[unsafe_no_drop_flag]
#[unstable(feature = "alloc",
#[unstable(feature = "rc_weak",
reason = "Weak pointers may not belong in this module.")]
pub struct Weak<T: ?Sized> {
// FIXME #12808: strange names to try to avoid interfering with
@ -663,7 +663,7 @@ pub struct Weak<T: ?Sized> {
impl<T: ?Sized> !marker::Send for Weak<T> {}
impl<T: ?Sized> !marker::Sync for Weak<T> {}
#[unstable(feature = "alloc",
#[unstable(feature = "rc_weak",
reason = "Weak pointers may not belong in this module.")]
impl<T: ?Sized> Weak<T> {
@ -741,7 +741,7 @@ impl<T: ?Sized> Drop for Weak<T> {
}
}
#[unstable(feature = "alloc",
#[unstable(feature = "rc_weak",
reason = "Weak pointers may not belong in this module.")]
impl<T: ?Sized> Clone for Weak<T> {

View File

@ -33,10 +33,11 @@
#![feature(alloc)]
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(heap_api)]
#![feature(oom)]
#![feature(ptr_as_ref)]
#![feature(raw)]
#![feature(staged_api)]
#![feature(unboxed_closures)]
#![cfg_attr(test, feature(test))]
extern crate alloc;

View File

@ -29,6 +29,7 @@
#![feature(alloc)]
#![feature(box_patterns)]
#![feature(box_raw)]
#![feature(box_syntax)]
#![feature(copy_lifetime)]
#![feature(core)]
@ -36,6 +37,7 @@
#![feature(core_prelude)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
#![feature(heap_api)]
#![feature(iter_cmp)]
#![feature(iter_idx)]
#![feature(iter_order)]
@ -43,6 +45,7 @@
#![feature(iter_sum)]
#![feature(lang_items)]
#![feature(num_bits_bytes)]
#![feature(oom)]
#![feature(pattern)]
#![feature(ptr_as_ref)]
#![feature(raw)]

View File

@ -169,10 +169,11 @@
html_playground_url = "http://play.rust-lang.org/")]
#![deny(missing_docs)]
#![feature(alloc)]
#![feature(staged_api)]
#![feature(box_raw)]
#![feature(box_syntax)]
#![feature(const_fn)]
#![feature(iter_cmp)]
#![feature(staged_api)]
#![feature(std_misc)]
use std::boxed;

View File

@ -19,9 +19,9 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(alloc)]
#![feature(associated_consts)]
#![feature(collections)]
#![feature(rc_weak)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(staged_api)]

View File

@ -25,7 +25,6 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(alloc)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(collections)]
@ -40,6 +39,7 @@
#![feature(path_relative_from)]
#![feature(path_relative_from)]
#![feature(quote)]
#![feature(rc_weak)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(staged_api)]

View File

@ -107,6 +107,7 @@
#![feature(allow_internal_unstable)]
#![feature(associated_consts)]
#![feature(borrow_state)]
#![feature(box_raw)]
#![feature(box_syntax)]
#![feature(char_internals)]
#![feature(collections)]
@ -117,6 +118,7 @@
#![feature(core_prelude)]
#![feature(core_simd)]
#![feature(fnbox)]
#![feature(heap_api)]
#![feature(int_error_internals)]
#![feature(into_cow)]
#![feature(iter_order)]
@ -126,6 +128,7 @@
#![feature(macro_reexport)]
#![feature(no_std)]
#![feature(num_bits_bytes)]
#![feature(oom)]
#![feature(optin_builtin_traits)]
#![feature(rand)]
#![feature(raw)]

View File

@ -37,14 +37,15 @@
#![feature(asm)]
#![feature(box_syntax)]
#![feature(collections)]
#![feature(core)]
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(libc)]
#![feature(set_stdio)]
#![feature(duration)]
#![feature(duration_span)]
#![feature(fnbox)]
#![feature(iter_cmp)]
#![feature(libc)]
#![feature(rustc_private)]
#![feature(set_stdio)]
#![feature(staged_api)]
#![feature(std_misc)]
extern crate getopts;
extern crate serialize;