1
Fork 0

Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)

`Float` still needs to be public for libcore unit tests.
This commit is contained in:
Simon Sapin 2018-04-12 08:36:31 +02:00
parent 18ab16b510
commit 70fdd1b5c0
8 changed files with 40 additions and 29 deletions

View file

@ -75,7 +75,7 @@
#![deny(missing_debug_implementations)] #![deny(missing_debug_implementations)]
#![cfg_attr(test, allow(deprecated))] // rand #![cfg_attr(test, allow(deprecated))] // rand
#![cfg_attr(not(test), feature(core_float))] #![cfg_attr(all(not(test), stage0), feature(float_internals))]
#![cfg_attr(not(test), feature(exact_size_is_empty))] #![cfg_attr(not(test), feature(exact_size_is_empty))]
#![cfg_attr(not(test), feature(generator_trait))] #![cfg_attr(not(test), feature(generator_trait))]
#![cfg_attr(test, feature(rand, test))] #![cfg_attr(test, feature(rand, test))]

View file

@ -87,3 +87,16 @@ macro_rules! forward_ref_op_assign {
} }
} }
#[cfg(stage0)]
macro_rules! public_in_stage0 {
( { $(#[$attr:meta])* } $($Item: tt)*) => {
$(#[$attr])* pub $($Item)*
}
}
#[cfg(not(stage0))]
macro_rules! public_in_stage0 {
( { $(#[$attr:meta])* } $($Item: tt)*) => {
$(#[$attr])* pub(crate) $($Item)*
}
}

View file

@ -4098,65 +4098,58 @@ pub enum FpCategory {
Normal, Normal,
} }
/// A built-in floating point number. // Technically private and only exposed for coretests:
#[doc(hidden)] #[doc(hidden)]
#[unstable(feature = "core_float", #[unstable(feature = "float_internals",
reason = "stable interface is via `impl f{32,64}` in later crates", reason = "internal routines only exposed for testing",
issue = "32110")] issue = "0")]
pub trait Float: Sized { pub trait Float: Sized {
/// Type used by `to_bits` and `from_bits`. /// Type used by `to_bits` and `from_bits`.
#[stable(feature = "core_float_bits", since = "1.25.0")]
type Bits; type Bits;
/// Returns `true` if this value is NaN and false otherwise. /// Returns `true` if this value is NaN and false otherwise.
#[stable(feature = "core", since = "1.6.0")]
fn is_nan(self) -> bool; fn is_nan(self) -> bool;
/// Returns `true` if this value is positive infinity or negative infinity and /// Returns `true` if this value is positive infinity or negative infinity and
/// false otherwise. /// false otherwise.
#[stable(feature = "core", since = "1.6.0")]
fn is_infinite(self) -> bool; fn is_infinite(self) -> bool;
/// Returns `true` if this number is neither infinite nor NaN. /// Returns `true` if this number is neither infinite nor NaN.
#[stable(feature = "core", since = "1.6.0")]
fn is_finite(self) -> bool; fn is_finite(self) -> bool;
/// Returns `true` if this number is neither zero, infinite, denormal, or NaN. /// Returns `true` if this number is neither zero, infinite, denormal, or NaN.
#[stable(feature = "core", since = "1.6.0")]
fn is_normal(self) -> bool; fn is_normal(self) -> bool;
/// Returns the category that this number falls into. /// Returns the category that this number falls into.
#[stable(feature = "core", since = "1.6.0")]
fn classify(self) -> FpCategory; fn classify(self) -> FpCategory;
/// Returns `true` if `self` is positive, including `+0.0` and /// Returns `true` if `self` is positive, including `+0.0` and
/// `Float::infinity()`. /// `Float::infinity()`.
#[stable(feature = "core", since = "1.6.0")]
fn is_sign_positive(self) -> bool; fn is_sign_positive(self) -> bool;
/// Returns `true` if `self` is negative, including `-0.0` and /// Returns `true` if `self` is negative, including `-0.0` and
/// `Float::neg_infinity()`. /// `Float::neg_infinity()`.
#[stable(feature = "core", since = "1.6.0")]
fn is_sign_negative(self) -> bool; fn is_sign_negative(self) -> bool;
/// Take the reciprocal (inverse) of a number, `1/x`. /// Take the reciprocal (inverse) of a number, `1/x`.
#[stable(feature = "core", since = "1.6.0")]
fn recip(self) -> Self; fn recip(self) -> Self;
/// Convert radians to degrees. /// Convert radians to degrees.
#[stable(feature = "deg_rad_conversions", since="1.7.0")]
fn to_degrees(self) -> Self; fn to_degrees(self) -> Self;
/// Convert degrees to radians. /// Convert degrees to radians.
#[stable(feature = "deg_rad_conversions", since="1.7.0")]
fn to_radians(self) -> Self; fn to_radians(self) -> Self;
/// Returns the maximum of the two numbers. /// Returns the maximum of the two numbers.
#[stable(feature = "core_float_min_max", since="1.20.0")]
fn max(self, other: Self) -> Self; fn max(self, other: Self) -> Self;
/// Returns the minimum of the two numbers. /// Returns the minimum of the two numbers.
#[stable(feature = "core_float_min_max", since="1.20.0")]
fn min(self, other: Self) -> Self; fn min(self, other: Self) -> Self;
/// Raw transmutation to integer. /// Raw transmutation to integer.
#[stable(feature = "core_float_bits", since="1.25.0")]
fn to_bits(self) -> Self::Bits; fn to_bits(self) -> Self::Bits;
/// Raw transmutation from integer. /// Raw transmutation from integer.
#[stable(feature = "core_float_bits", since="1.25.0")]
fn from_bits(v: Self::Bits) -> Self; fn from_bits(v: Self::Bits) -> Self;
} }

View file

@ -68,12 +68,15 @@ struct Repr<T> {
// Extension traits // Extension traits
// //
public_in_stage0! {
{
/// Extension methods for slices. /// Extension methods for slices.
#[unstable(feature = "core_slice_ext", #[unstable(feature = "core_slice_ext",
reason = "stable interface provided by `impl [T]` in later crates", reason = "stable interface provided by `impl [T]` in later crates",
issue = "32110")] issue = "32110")]
#[allow(missing_docs)] // documented elsewhere #[allow(missing_docs)] // documented elsewhere
pub trait SliceExt { }
trait SliceExt {
type Item; type Item;
#[stable(feature = "core", since = "1.6.0")] #[stable(feature = "core", since = "1.6.0")]
@ -238,7 +241,7 @@ pub trait SliceExt {
fn sort_unstable_by_key<B, F>(&mut self, f: F) fn sort_unstable_by_key<B, F>(&mut self, f: F)
where F: FnMut(&Self::Item) -> B, where F: FnMut(&Self::Item) -> B,
B: Ord; B: Ord;
} }}
// Use macros to be generic over const/mut // Use macros to be generic over const/mut
macro_rules! slice_offset { macro_rules! slice_offset {

View file

@ -2117,14 +2117,16 @@ mod traits {
} }
public_in_stage0! {
{
/// Methods for string slices /// Methods for string slices
#[allow(missing_docs)] #[allow(missing_docs)]
#[doc(hidden)] #[doc(hidden)]
#[unstable(feature = "core_str_ext", #[unstable(feature = "core_str_ext",
reason = "stable interface provided by `impl str` in later crates", reason = "stable interface provided by `impl str` in later crates",
issue = "32110")] issue = "32110")]
pub trait StrExt { }
trait StrExt {
// NB there are no docs here are they're all located on the StrExt trait in // NB there are no docs here are they're all located on the StrExt trait in
// liballoc, not here. // liballoc, not here.
@ -2224,7 +2226,7 @@ pub trait StrExt {
fn trim_left(&self) -> &str; fn trim_left(&self) -> &str;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn trim_right(&self) -> &str; fn trim_right(&self) -> &str;
} }}
// truncate `&str` to length at most equal to `max` // truncate `&str` to length at most equal to `max`
// return `true` if it were truncated, and the new str. // return `true` if it were truncated, and the new str.

View file

@ -17,6 +17,7 @@
#![feature(decode_utf8)] #![feature(decode_utf8)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#![feature(fixed_size_array)] #![feature(fixed_size_array)]
#![feature(float_internals)]
#![feature(flt2dec)] #![feature(flt2dec)]
#![feature(fmt_internals)] #![feature(fmt_internals)]
#![feature(hashmap_internals)] #![feature(hashmap_internals)]

View file

@ -252,7 +252,7 @@
#![feature(collections_range)] #![feature(collections_range)]
#![feature(compiler_builtins_lib)] #![feature(compiler_builtins_lib)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(core_float)] #![cfg_attr(stage0, feature(core_float))]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(dropck_eyepatch)] #![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
@ -260,6 +260,7 @@
#![feature(fs_read_write)] #![feature(fs_read_write)]
#![feature(fixed_size_array)] #![feature(fixed_size_array)]
#![feature(float_from_str_radix)] #![feature(float_from_str_radix)]
#![cfg_attr(stage0, feature(float_internals))]
#![feature(fn_traits)] #![feature(fn_traits)]
#![feature(fnbox)] #![feature(fnbox)]
#![cfg_attr(stage0, feature(generic_param_attrs))] #![cfg_attr(stage0, feature(generic_param_attrs))]

View file

@ -8,10 +8,8 @@ LL | foo(|s| s.is_empty());
| ^^^^^^^^ | ^^^^^^^^
| |
= help: items from traits can only be used if the trait is implemented and in scope = help: items from traits can only be used if the trait is implemented and in scope
= note: the following traits define an item `is_empty`, perhaps you need to implement one of them: = note: the following trait defines an item `is_empty`, perhaps you need to implement it:
candidate #1: `std::iter::ExactSizeIterator` candidate #1: `std::iter::ExactSizeIterator`
candidate #2: `core::slice::SliceExt`
candidate #3: `core::str::StrExt`
error: aborting due to previous error error: aborting due to previous error