Skip to content

Commit

Permalink
core: Split apart the global core feature
Browse files Browse the repository at this point in the history
This commit shards the broad `core` feature of the libcore library into finer
grained features. This split groups together similar APIs and enables tracking
each API separately, giving a better sense of where each feature is within the
stabilization process.

A few minor APIs were deprecated along the way:

* Iterator::reverse_in_place
* marker::NoCopy
  • Loading branch information
alexcrichton committed Jun 17, 2015
1 parent e7a5a1c commit c14d86f
Show file tree
Hide file tree
Showing 54 changed files with 379 additions and 288 deletions.
18 changes: 10 additions & 8 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 Down Expand Up @@ -355,7 +357,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
22 changes: 14 additions & 8 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,32 @@
#![cfg_attr(stage0, feature(custom_attribute))]
#![crate_name = "alloc"]
#![unstable(feature = "alloc")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![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/")]
#![doc(test(no_crate_inject))]

#![feature(no_std)]
html_root_url = "http://doc.rust-lang.org/nightly/",
test(no_crate_inject))]
#![no_std]

#![feature(allocator)]
#![feature(box_syntax)]
#![feature(coerce_unsized)]
#![feature(core)]
#![feature(core_intrinsics)]
#![feature(core_prelude)]
#![feature(custom_attribute)]
#![feature(fundamental)]
#![feature(lang_items)]
#![feature(box_syntax)]
#![feature(no_std)]
#![feature(nonzero)]
#![feature(optin_builtin_traits)]
#![feature(raw)]
#![feature(staged_api)]
#![feature(unboxed_closures)]
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(core)]
#![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))]
Expand Down
4 changes: 3 additions & 1 deletion src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

#![feature(alloc)]
#![feature(box_syntax)]
#![feature(core)]
#![feature(core_intrinsics)]
#![feature(ptr_as_ref)]
#![feature(raw)]
#![feature(staged_api)]
#![feature(unboxed_closures)]
#![cfg_attr(test, feature(test))]
Expand Down
30 changes: 23 additions & 7 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,42 @@
#![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/",
html_playground_url = "http://play.rust-lang.org/")]
#![doc(test(no_crate_inject))]
html_playground_url = "http://play.rust-lang.org/",
test(no_crate_inject))]

#![allow(trivial_casts)]
#![cfg_attr(test, allow(deprecated))] // rand

#![feature(alloc)]
#![feature(box_syntax)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(copy_lifetime)]
#![feature(core)]
#![feature(core_intrinsics)]
#![feature(core_prelude)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
#![feature(iter_cmp)]
#![feature(iter_idx)]
#![feature(iter_order)]
#![feature(iter_product)]
#![feature(iter_sum)]
#![feature(lang_items)]
#![feature(num_bits_bytes)]
#![feature(pattern)]
#![feature(ptr_as_ref)]
#![feature(raw)]
#![feature(slice_patterns)]
#![feature(staged_api)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(str_internals)]
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(unique)]
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(slice_patterns)]
#![feature(utf8_error)]
#![cfg_attr(test, feature(rand, test))]
#![cfg_attr(test, allow(deprecated))] // rand
#![cfg_attr(not(test), feature(str_words))]

#![feature(no_std)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ use marker::{Reflect, Sized};
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Any: Reflect + 'static {
/// Gets the `TypeId` of `self`.
#[unstable(feature = "core",
#[unstable(feature = "get_type_id",
reason = "this method will likely be replaced by an associated static")]
fn get_type_id(&self) -> TypeId;
}
Expand Down
11 changes: 3 additions & 8 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
//! up to a certain length. Eventually we should able to generalize
//! to all lengths.

#![unstable(feature = "core")] // not yet reviewed

#![doc(primitive = "array")]
#![unstable(feature = "fixed_size_array",
reason = "traits and impls are better expressed through generic \
integer constants")]

use clone::Clone;
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
Expand All @@ -30,7 +31,6 @@ use slice::{Iter, IterMut, SliceExt};
///
/// This trait can be used to implement other traits on fixed-size arrays
/// without causing much metadata bloat.
#[unstable(feature = "core")]
pub trait FixedSizeArray<T> {
/// Converts the array to immutable slice
fn as_slice(&self) -> &[T];
Expand All @@ -42,7 +42,6 @@ pub trait FixedSizeArray<T> {
macro_rules! array_impls {
($($N:expr)+) => {
$(
#[unstable(feature = "core")]
impl<T> FixedSizeArray<T> for [T; $N] {
#[inline]
fn as_slice(&self) -> &[T] {
Expand All @@ -54,17 +53,13 @@ macro_rules! array_impls {
}
}

#[unstable(feature = "array_as_ref",
reason = "should ideally be implemented for all fixed-sized arrays")]
impl<T> AsRef<[T]> for [T; $N] {
#[inline]
fn as_ref(&self) -> &[T] {
&self[..]
}
}

#[unstable(feature = "array_as_ref",
reason = "should ideally be implemented for all fixed-sized arrays")]
impl<T> AsMut<[T]> for [T; $N] {
#[inline]
fn as_mut(&mut self) -> &mut [T] {
Expand Down
50 changes: 28 additions & 22 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<T:Copy> Cell<T> {
/// let uc = unsafe { c.as_unsafe_cell() };
/// ```
#[inline]
#[unstable(feature = "core")]
#[unstable(feature = "as_unsafe_cell")]
pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell<T> {
&self.value
}
Expand Down Expand Up @@ -277,7 +277,7 @@ pub struct RefCell<T: ?Sized> {

/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[unstable(feature = "std_misc")]
#[unstable(feature = "borrow_state")]
pub enum BorrowState {
/// The cell is currently being read, there is at least one active `borrow`.
Reading,
Expand Down Expand Up @@ -339,7 +339,7 @@ impl<T: ?Sized> RefCell<T> {
///
/// The returned value can be dispatched on to determine if a call to
/// `borrow` or `borrow_mut` would succeed.
#[unstable(feature = "std_misc")]
#[unstable(feature = "borrow_state")]
#[inline]
pub fn borrow_state(&self) -> BorrowState {
match self.borrow.get() {
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<T: ?Sized> RefCell<T> {
///
/// This function is `unsafe` because `UnsafeCell`'s field is public.
#[inline]
#[unstable(feature = "core")]
#[unstable(feature = "as_unsafe_cell")]
pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell<T> {
&self.value
}
Expand Down Expand Up @@ -564,9 +564,10 @@ impl<'b, T: ?Sized> Ref<'b, T> {
///
/// The `RefCell` is already immutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as `Ref::clone(...)`.
/// A `Clone` implementation or a method would interfere with the widespread
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
/// This is an associated function that needs to be used as
/// `Ref::clone(...)`. A `Clone` implementation or a method would interfere
/// with the widespread use of `r.borrow().clone()` to clone the contents of
/// a `RefCell`.
#[unstable(feature = "cell_extras",
reason = "likely to be moved to a method, pending language changes")]
#[inline]
Expand All @@ -582,8 +583,8 @@ impl<'b, T: ?Sized> Ref<'b, T> {
/// The `RefCell` is already immutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as `Ref::map(...)`.
/// A method would interfere with methods of the same name on the contents of a `RefCell`
/// used through `Deref`.
/// A method would interfere with methods of the same name on the contents
/// of a `RefCell` used through `Deref`.
///
/// # Example
///
Expand All @@ -607,13 +608,14 @@ impl<'b, T: ?Sized> Ref<'b, T> {
}
}

/// Make a new `Ref` for a optional component of the borrowed data, e.g. an enum variant.
/// Make a new `Ref` for a optional component of the borrowed data, e.g. an
/// enum variant.
///
/// The `RefCell` is already immutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as `Ref::filter_map(...)`.
/// A method would interfere with methods of the same name on the contents of a `RefCell`
/// used through `Deref`.
/// This is an associated function that needs to be used as
/// `Ref::filter_map(...)`. A method would interfere with methods of the
/// same name on the contents of a `RefCell` used through `Deref`.
///
/// # Example
///
Expand All @@ -639,13 +641,14 @@ impl<'b, T: ?Sized> Ref<'b, T> {
}

impl<'b, T: ?Sized> RefMut<'b, T> {
/// Make a new `RefMut` for a component of the borrowed data, e.g. an enum variant.
/// Make a new `RefMut` for a component of the borrowed data, e.g. an enum
/// variant.
///
/// The `RefCell` is already mutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as `RefMut::map(...)`.
/// A method would interfere with methods of the same name on the contents of a `RefCell`
/// used through `Deref`.
/// This is an associated function that needs to be used as
/// `RefMut::map(...)`. A method would interfere with methods of the same
/// name on the contents of a `RefCell` used through `Deref`.
///
/// # Example
///
Expand Down Expand Up @@ -673,13 +676,14 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
}
}

/// Make a new `RefMut` for a optional component of the borrowed data, e.g. an enum variant.
/// Make a new `RefMut` for a optional component of the borrowed data, e.g.
/// an enum variant.
///
/// The `RefCell` is already mutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as `RefMut::filter_map(...)`.
/// A method would interfere with methods of the same name on the contents of a `RefCell`
/// used through `Deref`.
/// This is an associated function that needs to be used as
/// `RefMut::filter_map(...)`. A method would interfere with methods of the
/// same name on the contents of a `RefCell` used through `Deref`.
///
/// # Example
///
Expand All @@ -690,7 +694,9 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
/// let c = RefCell::new(Ok(5));
/// {
/// let b1: RefMut<Result<u32, ()>> = c.borrow_mut();
/// let mut b2: RefMut<u32> = RefMut::filter_map(b1, |o| o.as_mut().ok()).unwrap();
/// let mut b2: RefMut<u32> = RefMut::filter_map(b1, |o| {
/// o.as_mut().ok()
/// }).unwrap();
/// assert_eq!(*b2, 5);
/// *b2 = 42;
/// }
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![allow(non_snake_case)]
#![doc(primitive = "char")]
#![stable(feature = "rust1", since = "1.0.0")]

use iter::Iterator;
use mem::transmute;
Expand Down Expand Up @@ -131,6 +132,8 @@ pub fn from_digit(num: u32, radix: u32) -> Option<char> {
// unicode/char.rs, not here
#[allow(missing_docs)] // docs in libunicode/u_char.rs
#[doc(hidden)]
#[unstable(feature = "core_char_ext",
reason = "the stable interface is `impl char` in later crate")]
pub trait CharExt {
fn is_digit(self, radix: u32) -> bool;
fn to_digit(self, radix: u32) -> Option<u32>;
Expand Down Expand Up @@ -220,6 +223,8 @@ impl CharExt for char {
/// If the buffer is not large enough, nothing will be written into it
/// and a `None` will be returned.
#[inline]
#[unstable(feature = "char_internals",
reason = "this function should not be exposed publicly")]
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if code < MAX_ONE_B && !dst.is_empty() {
Expand Down Expand Up @@ -251,6 +256,8 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
/// If the buffer is not large enough, nothing will be written into it
/// and a `None` will be returned.
#[inline]
#[unstable(feature = "char_internals",
reason = "this function should not be exposed publicly")]
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if (ch & 0xFFFF) == ch && !dst.is_empty() {
Expand Down
9 changes: 4 additions & 5 deletions src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,28 @@ clone_impl! { char }

macro_rules! extern_fn_clone {
($($A:ident),*) => (
#[unstable(feature = "core",
reason = "this may not be sufficient for fns with region parameters")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($A,)* ReturnType> Clone for extern "Rust" fn($($A),*) -> ReturnType {
/// Returns a copy of a function pointer.
#[inline]
fn clone(&self) -> extern "Rust" fn($($A),*) -> ReturnType { *self }
}

#[unstable(feature = "core", reason = "brand new")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($A,)* ReturnType> Clone for extern "C" fn($($A),*) -> ReturnType {
/// Returns a copy of a function pointer.
#[inline]
fn clone(&self) -> extern "C" fn($($A),*) -> ReturnType { *self }
}

#[unstable(feature = "core", reason = "brand new")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($A,)* ReturnType> Clone for unsafe extern "Rust" fn($($A),*) -> ReturnType {
/// Returns a copy of a function pointer.
#[inline]
fn clone(&self) -> unsafe extern "Rust" fn($($A),*) -> ReturnType { *self }
}

#[unstable(feature = "core", reason = "brand new")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($A,)* ReturnType> Clone for unsafe extern "C" fn($($A),*) -> ReturnType {
/// Returns a copy of a function pointer.
#[inline]
Expand Down
Loading

0 comments on commit c14d86f

Please sign in to comment.