Skip to content

Commit 5eea099

Browse files
committed
Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)
`Float` still needs to be public for libcore unit tests.
1 parent d41d08c commit 5eea099

File tree

8 files changed

+40
-29
lines changed

8 files changed

+40
-29
lines changed

src/liballoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#![deny(missing_debug_implementations)]
7676

7777
#![cfg_attr(test, allow(deprecated))] // rand
78-
#![cfg_attr(not(test), feature(core_float))]
78+
#![cfg_attr(all(not(test), stage0), feature(float_internals))]
7979
#![cfg_attr(not(test), feature(exact_size_is_empty))]
8080
#![cfg_attr(not(test), feature(generator_trait))]
8181
#![cfg_attr(test, feature(rand, test))]

src/libcore/internal_macros.rs

+13
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,16 @@ macro_rules! forward_ref_op_assign {
8787
}
8888
}
8989

90+
#[cfg(stage0)]
91+
macro_rules! public_in_stage0 {
92+
( { $(#[$attr:meta])* } $($Item: tt)*) => {
93+
$(#[$attr])* pub $($Item)*
94+
}
95+
}
96+
97+
#[cfg(not(stage0))]
98+
macro_rules! public_in_stage0 {
99+
( { $(#[$attr:meta])* } $($Item: tt)*) => {
100+
$(#[$attr])* pub(crate) $($Item)*
101+
}
102+
}

src/libcore/num/mod.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -4009,65 +4009,58 @@ pub enum FpCategory {
40094009
Normal,
40104010
}
40114011

4012-
/// A built-in floating point number.
4012+
// Technically private and only exposed for coretests:
40134013
#[doc(hidden)]
4014-
#[unstable(feature = "core_float",
4015-
reason = "stable interface is via `impl f{32,64}` in later crates",
4016-
issue = "32110")]
4014+
#[unstable(feature = "float_internals",
4015+
reason = "internal routines only exposed for testing",
4016+
issue = "0")]
40174017
pub trait Float: Sized {
40184018
/// Type used by `to_bits` and `from_bits`.
4019-
#[stable(feature = "core_float_bits", since = "1.25.0")]
40204019
type Bits;
40214020

40224021
/// Returns `true` if this value is NaN and false otherwise.
4023-
#[stable(feature = "core", since = "1.6.0")]
40244022
fn is_nan(self) -> bool;
4023+
40254024
/// Returns `true` if this value is positive infinity or negative infinity and
40264025
/// false otherwise.
4027-
#[stable(feature = "core", since = "1.6.0")]
40284026
fn is_infinite(self) -> bool;
4027+
40294028
/// Returns `true` if this number is neither infinite nor NaN.
4030-
#[stable(feature = "core", since = "1.6.0")]
40314029
fn is_finite(self) -> bool;
4030+
40324031
/// Returns `true` if this number is neither zero, infinite, denormal, or NaN.
4033-
#[stable(feature = "core", since = "1.6.0")]
40344032
fn is_normal(self) -> bool;
4033+
40354034
/// Returns the category that this number falls into.
4036-
#[stable(feature = "core", since = "1.6.0")]
40374035
fn classify(self) -> FpCategory;
40384036

40394037
/// Returns `true` if `self` is positive, including `+0.0` and
40404038
/// `Float::infinity()`.
4041-
#[stable(feature = "core", since = "1.6.0")]
40424039
fn is_sign_positive(self) -> bool;
4040+
40434041
/// Returns `true` if `self` is negative, including `-0.0` and
40444042
/// `Float::neg_infinity()`.
4045-
#[stable(feature = "core", since = "1.6.0")]
40464043
fn is_sign_negative(self) -> bool;
40474044

40484045
/// Take the reciprocal (inverse) of a number, `1/x`.
4049-
#[stable(feature = "core", since = "1.6.0")]
40504046
fn recip(self) -> Self;
40514047

40524048
/// Convert radians to degrees.
4053-
#[stable(feature = "deg_rad_conversions", since="1.7.0")]
40544049
fn to_degrees(self) -> Self;
4050+
40554051
/// Convert degrees to radians.
4056-
#[stable(feature = "deg_rad_conversions", since="1.7.0")]
40574052
fn to_radians(self) -> Self;
40584053

40594054
/// Returns the maximum of the two numbers.
4060-
#[stable(feature = "core_float_min_max", since="1.20.0")]
40614055
fn max(self, other: Self) -> Self;
4056+
40624057
/// Returns the minimum of the two numbers.
4063-
#[stable(feature = "core_float_min_max", since="1.20.0")]
40644058
fn min(self, other: Self) -> Self;
40654059

40664060
/// Raw transmutation to integer.
4067-
#[stable(feature = "core_float_bits", since="1.25.0")]
40684061
fn to_bits(self) -> Self::Bits;
4062+
40694063
/// Raw transmutation from integer.
4070-
#[stable(feature = "core_float_bits", since="1.25.0")]
40714064
fn from_bits(v: Self::Bits) -> Self;
40724065
}
40734066

src/libcore/slice/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ struct Repr<T> {
6868
// Extension traits
6969
//
7070

71+
public_in_stage0! {
72+
{
7173
/// Extension methods for slices.
7274
#[unstable(feature = "core_slice_ext",
7375
reason = "stable interface provided by `impl [T]` in later crates",
7476
issue = "32110")]
7577
#[allow(missing_docs)] // documented elsewhere
76-
pub trait SliceExt {
78+
}
79+
trait SliceExt {
7780
type Item;
7881

7982
#[stable(feature = "core", since = "1.6.0")]
@@ -238,7 +241,7 @@ pub trait SliceExt {
238241
fn sort_unstable_by_key<B, F>(&mut self, f: F)
239242
where F: FnMut(&Self::Item) -> B,
240243
B: Ord;
241-
}
244+
}}
242245

243246
// Use macros to be generic over const/mut
244247
macro_rules! slice_offset {

src/libcore/str/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2117,14 +2117,16 @@ mod traits {
21172117

21182118
}
21192119

2120-
2120+
public_in_stage0! {
2121+
{
21212122
/// Methods for string slices
21222123
#[allow(missing_docs)]
21232124
#[doc(hidden)]
21242125
#[unstable(feature = "core_str_ext",
21252126
reason = "stable interface provided by `impl str` in later crates",
21262127
issue = "32110")]
2127-
pub trait StrExt {
2128+
}
2129+
trait StrExt {
21282130
// NB there are no docs here are they're all located on the StrExt trait in
21292131
// liballoc, not here.
21302132

@@ -2228,7 +2230,7 @@ pub trait StrExt {
22282230
fn trim_left(&self) -> &str;
22292231
#[stable(feature = "rust1", since = "1.0.0")]
22302232
fn trim_right(&self) -> &str;
2231-
}
2233+
}}
22322234

22332235
// truncate `&str` to length at most equal to `max`
22342236
// return `true` if it were truncated, and the new str.

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(decode_utf8)]
1818
#![feature(exact_size_is_empty)]
1919
#![feature(fixed_size_array)]
20+
#![feature(float_internals)]
2021
#![feature(flt2dec)]
2122
#![feature(fmt_internals)]
2223
#![feature(hashmap_internals)]

src/libstd/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,15 @@
252252
#![feature(collections_range)]
253253
#![feature(compiler_builtins_lib)]
254254
#![feature(const_fn)]
255-
#![feature(core_float)]
255+
#![cfg_attr(stage0, feature(core_float))]
256256
#![feature(core_intrinsics)]
257257
#![feature(dropck_eyepatch)]
258258
#![feature(exact_size_is_empty)]
259259
#![feature(external_doc)]
260260
#![feature(fs_read_write)]
261261
#![feature(fixed_size_array)]
262262
#![feature(float_from_str_radix)]
263+
#![cfg_attr(stage0, feature(float_internals))]
263264
#![feature(fn_traits)]
264265
#![feature(fnbox)]
265266
#![cfg_attr(stage0, feature(generic_param_attrs))]

src/test/ui/impl-trait/method-suggestion-no-duplication.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ LL | foo(|s| s.is_empty());
88
| ^^^^^^^^
99
|
1010
= help: items from traits can only be used if the trait is implemented and in scope
11-
= note: the following traits define an item `is_empty`, perhaps you need to implement one of them:
11+
= note: the following trait defines an item `is_empty`, perhaps you need to implement it:
1212
candidate #1: `std::iter::ExactSizeIterator`
13-
candidate #2: `core::slice::SliceExt`
14-
candidate #3: `core::str::StrExt`
1513

1614
error: aborting due to previous error
1715

0 commit comments

Comments
 (0)