Skip to content

Commit

Permalink
Auto merge of #26192 - alexcrichton:features-clean, r=aturon
Browse files Browse the repository at this point in the history
This commit shards the all-encompassing `core`, `std_misc`, `collections`, and `alloc` features into finer-grained components that are much more easily opted into and tracked. This reflects the effort to push forward current unstable APIs to either stabilization or removal. Keeping track of unstable features on a much more fine-grained basis will enable the library subteam to quickly analyze a feature and help prioritize internally about what APIs should be stabilized.

A few assorted APIs were deprecated along the way, but otherwise this change is just changing the feature name associated with each API. Soon we will have a dashboard for keeping track of all the unstable APIs in the standard library, and I'll also start making issues for each unstable API after performing a first-pass for stabilization.
  • Loading branch information
bors committed Jun 18, 2015
2 parents 20d23d8 + 4fcde6e commit 154b577
Show file tree
Hide file tree
Showing 197 changed files with 1,386 additions and 1,088 deletions.
11 changes: 6 additions & 5 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#![crate_type = "bin"]

#![feature(box_syntax)]
#![feature(collections)]
#![feature(rustc_private)]
#![feature(std_misc)]
#![feature(test)]
#![feature(dynamic_lib)]
#![feature(libc)]
#![feature(path_ext)]
#![feature(rustc_private)]
#![feature(slice_extras)]
#![feature(str_char)]
#![feature(libc)]
#![feature(test)]
#![feature(vec_push_all)]

#![deny(warnings)]

Expand Down
56 changes: 37 additions & 19 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,23 +191,35 @@ impl<T: ?Sized> Arc<T> {
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(arc_weak)]
/// use std::sync::Arc;
///
/// let five = Arc::new(5);
///
/// 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
self.inner().weak.fetch_add(1, Relaxed);
Weak { _ptr: self._ptr }
}
}

impl<T: ?Sized> Arc<T> {
/// Get the number of weak references to this value.
#[inline]
#[unstable(feature = "arc_counts")]
pub fn weak_count(this: &Arc<T>) -> usize {
this.inner().weak.load(SeqCst) - 1
}

/// Get the number of strong references to this value.
#[inline]
#[unstable(feature = "arc_counts")]
pub fn strong_count(this: &Arc<T>) -> usize {
this.inner().strong.load(SeqCst)
}

#[inline]
fn inner(&self) -> &ArcInner<T> {
// This unsafety is ok because while this arc is alive we're guaranteed
Expand Down Expand Up @@ -236,13 +248,15 @@ impl<T: ?Sized> Arc<T> {

/// Get the number of weak references to this value.
#[inline]
#[unstable(feature = "alloc")]
pub fn weak_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().weak.load(SeqCst) - 1 }
#[unstable(feature = "arc_counts")]
#[deprecated(since = "1.2.0", reason = "renamed to Arc::weak_count")]
pub fn weak_count<T: ?Sized>(this: &Arc<T>) -> usize { Arc::weak_count(this) }

/// Get the number of strong references to this value.
#[inline]
#[unstable(feature = "alloc")]
pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().strong.load(SeqCst) }
#[unstable(feature = "arc_counts")]
#[deprecated(since = "1.2.0", reason = "renamed to Arc::strong_count")]
pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { Arc::strong_count(this) }


/// Returns a mutable reference to the contained value if the `Arc<T>` is unique.
Expand All @@ -255,7 +269,7 @@ pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().strong.loa
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(arc_unique, alloc)]
/// extern crate alloc;
/// # fn main() {
/// use alloc::arc::{Arc, get_mut};
Expand All @@ -271,10 +285,12 @@ pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().strong.loa
/// # }
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "arc_unique")]
#[deprecated(since = "1.2.0",
reason = "this function is unsafe with weak pointers")]
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 {
if Arc::strong_count(this) == 1 && Arc::weak_count(this) == 0 {
// This unsafety is ok because we're guaranteed that the pointer
// returned is the *only* pointer that will ever be returned to T. Our
// reference count is guaranteed to be 1 at this point, and we required
Expand Down Expand Up @@ -342,7 +358,7 @@ impl<T: Clone> Arc<T> {
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(arc_unique)]
/// use std::sync::Arc;
///
/// # unsafe {
Expand All @@ -352,7 +368,9 @@ impl<T: Clone> Arc<T> {
/// # }
/// ```
#[inline]
#[unstable(feature = "alloc")]
#[unstable(feature = "arc_unique")]
#[deprecated(since = "1.2.0",
reason = "this function is unsafe with weak pointers")]
pub unsafe fn make_unique(&mut self) -> &mut T {
// FIXME(#24880) potential race with upgraded weak pointers here
//
Expand Down Expand Up @@ -438,7 +456,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.
Expand All @@ -451,7 +469,7 @@ impl<T: ?Sized> Weak<T> {
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(arc_weak)]
/// use std::sync::Arc;
///
/// let five = Arc::new(5);
Expand Down Expand Up @@ -479,7 +497,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>`.
Expand All @@ -489,7 +507,7 @@ impl<T: ?Sized> Clone for Weak<T> {
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(arc_weak)]
/// use std::sync::Arc;
///
/// let weak_five = Arc::new(5).downgrade();
Expand All @@ -513,7 +531,7 @@ impl<T: ?Sized> Drop for Weak<T> {
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(arc_weak)]
/// use std::sync::Arc;
///
/// {
Expand Down
63 changes: 45 additions & 18 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

//! A pointer type for heap allocation.
//!
//! `Box<T>`, casually referred to as a 'box', provides the simplest form of heap allocation in
//! Rust. Boxes provide ownership for this allocation, and drop their contents when they go out of
//! scope.
//! `Box<T>`, casually referred to as a 'box', provides the simplest form of
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
//! drop their contents when they go out of scope.
//!
//! # Examples
//!
Expand All @@ -39,15 +39,17 @@
//!
//! This will print `Cons(1, Cons(2, Nil))`.
//!
//! Recursive structures must be boxed, because if the definition of `Cons` looked like this:
//! Recursive structures must be boxed, because if the definition of `Cons`
//! looked like this:
//!
//! ```rust,ignore
//! Cons(T, List<T>),
//! ```
//!
//! It wouldn't work. This is because the size of a `List` depends on how many elements are in the
//! list, and so we don't know how much memory to allocate for a `Cons`. By introducing a `Box`,
//! which has a defined size, we know how big `Cons` needs to be.
//! It wouldn't work. This is because the size of a `List` depends on how many
//! elements are in the list, and so we don't know how much memory to allocate
//! for a `Cons`. By introducing a `Box`, which has a defined size, we know how
//! big `Cons` needs to be.

#![stable(feature = "rust1", since = "1.0.0")]

Expand All @@ -69,7 +71,7 @@ use core::raw::{TraitObject};
/// The following two examples are equivalent:
///
/// ```
/// # #![feature(alloc)]
/// # #![feature(box_heap)]
/// #![feature(box_syntax)]
/// use std::boxed::HEAP;
///
Expand All @@ -79,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: () = ();

Expand Down Expand Up @@ -119,12 +121,37 @@ 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]
// NB: may want to be called from_ptr, see comments on CStr::from_ptr
pub unsafe fn from_raw(raw: *mut T) -> Self {
mem::transmute(raw)
}

/// Consumes the `Box`, returning the wrapped raw pointer.
///
/// After call to this function, caller is responsible for the memory
/// previously managed by `Box`, in particular caller should properly
/// destroy `T` and release memory. The proper way to do it is to
/// convert pointer back to `Box` with `Box::from_raw` function, because
/// `Box` does not specify, how memory is allocated.
///
/// # Examples
/// ```
/// # #![feature(box_raw)]
/// use std::boxed;
///
/// let seventeen = Box::new(17u32);
/// let raw = boxed::into_raw(seventeen);
/// let boxed_again = unsafe { Box::from_raw(raw) };
/// ```
#[unstable(feature = "box_raw", reason = "may be renamed")]
#[inline]
// NB: may want to be called into_ptr, see comments on CStr::from_ptr
pub fn into_raw(b: Box<T>) -> *mut T {
unsafe { mem::transmute(b) }
}
}

/// Consumes the `Box`, returning the wrapped raw pointer.
Expand All @@ -137,18 +164,18 @@ impl<T : ?Sized> Box<T> {
///
/// # Examples
/// ```
/// # #![feature(alloc)]
/// # #![feature(box_raw)]
/// use std::boxed;
///
/// let seventeen = Box::new(17u32);
/// let raw = boxed::into_raw(seventeen);
/// let boxed_again = unsafe { Box::from_raw(raw) };
/// ```
#[unstable(feature = "alloc",
reason = "may be renamed")]
#[unstable(feature = "box_raw", reason = "may be renamed")]
#[deprecated(since = "1.2.0", reason = "renamed to Box::into_raw")]
#[inline]
pub fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T {
unsafe { mem::transmute(b) }
Box::into_raw(b)
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -181,7 +208,7 @@ impl<T: Clone> Clone for Box<T> {
/// # Examples
///
/// ```
/// # #![feature(alloc, core)]
/// # #![feature(box_raw)]
/// let x = Box::new(5);
/// let mut y = Box::new(10);
///
Expand Down Expand Up @@ -242,7 +269,7 @@ impl Box<Any> {
if self.is::<T>() {
unsafe {
// Get the raw representation of the trait object
let raw = into_raw(self);
let raw = Box::into_raw(self);
let to: TraitObject =
mem::transmute::<*mut Any, TraitObject>(raw);

Expand Down Expand Up @@ -334,7 +361,7 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
/// -> i32>`.
///
/// ```
/// #![feature(core)]
/// #![feature(fnbox)]
///
/// use std::boxed::FnBox;
/// use std::collections::HashMap;
Expand All @@ -355,7 +382,7 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
/// }
/// ```
#[rustc_paren_sugar]
#[unstable(feature = "core", reason = "Newly introduced")]
#[unstable(feature = "fnbox", reason = "Newly introduced")]
pub trait FnBox<A> {
type Output;

Expand Down
7 changes: 6 additions & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit 154b577

Please sign in to comment.