Skip to content

Commit 70fdd1b

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 18ab16b commit 70fdd1b

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
@@ -4098,65 +4098,58 @@ pub enum FpCategory {
40984098
Normal,
40994099
}
41004100

4101-
/// A built-in floating point number.
4101+
// Technically private and only exposed for coretests:
41024102
#[doc(hidden)]
4103-
#[unstable(feature = "core_float",
4104-
reason = "stable interface is via `impl f{32,64}` in later crates",
4105-
issue = "32110")]
4103+
#[unstable(feature = "float_internals",
4104+
reason = "internal routines only exposed for testing",
4105+
issue = "0")]
41064106
pub trait Float: Sized {
41074107
/// Type used by `to_bits` and `from_bits`.
4108-
#[stable(feature = "core_float_bits", since = "1.25.0")]
41094108
type Bits;
41104109

41114110
/// Returns `true` if this value is NaN and false otherwise.
4112-
#[stable(feature = "core", since = "1.6.0")]
41134111
fn is_nan(self) -> bool;
4112+
41144113
/// Returns `true` if this value is positive infinity or negative infinity and
41154114
/// false otherwise.
4116-
#[stable(feature = "core", since = "1.6.0")]
41174115
fn is_infinite(self) -> bool;
4116+
41184117
/// Returns `true` if this number is neither infinite nor NaN.
4119-
#[stable(feature = "core", since = "1.6.0")]
41204118
fn is_finite(self) -> bool;
4119+
41214120
/// Returns `true` if this number is neither zero, infinite, denormal, or NaN.
4122-
#[stable(feature = "core", since = "1.6.0")]
41234121
fn is_normal(self) -> bool;
4122+
41244123
/// Returns the category that this number falls into.
4125-
#[stable(feature = "core", since = "1.6.0")]
41264124
fn classify(self) -> FpCategory;
41274125

41284126
/// Returns `true` if `self` is positive, including `+0.0` and
41294127
/// `Float::infinity()`.
4130-
#[stable(feature = "core", since = "1.6.0")]
41314128
fn is_sign_positive(self) -> bool;
4129+
41324130
/// Returns `true` if `self` is negative, including `-0.0` and
41334131
/// `Float::neg_infinity()`.
4134-
#[stable(feature = "core", since = "1.6.0")]
41354132
fn is_sign_negative(self) -> bool;
41364133

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

41414137
/// Convert radians to degrees.
4142-
#[stable(feature = "deg_rad_conversions", since="1.7.0")]
41434138
fn to_degrees(self) -> Self;
4139+
41444140
/// Convert degrees to radians.
4145-
#[stable(feature = "deg_rad_conversions", since="1.7.0")]
41464141
fn to_radians(self) -> Self;
41474142

41484143
/// Returns the maximum of the two numbers.
4149-
#[stable(feature = "core_float_min_max", since="1.20.0")]
41504144
fn max(self, other: Self) -> Self;
4145+
41514146
/// Returns the minimum of the two numbers.
4152-
#[stable(feature = "core_float_min_max", since="1.20.0")]
41534147
fn min(self, other: Self) -> Self;
41544148

41554149
/// Raw transmutation to integer.
4156-
#[stable(feature = "core_float_bits", since="1.25.0")]
41574150
fn to_bits(self) -> Self::Bits;
4151+
41584152
/// Raw transmutation from integer.
4159-
#[stable(feature = "core_float_bits", since="1.25.0")]
41604153
fn from_bits(v: Self::Bits) -> Self;
41614154
}
41624155

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

@@ -2224,7 +2226,7 @@ pub trait StrExt {
22242226
fn trim_left(&self) -> &str;
22252227
#[stable(feature = "rust1", since = "1.0.0")]
22262228
fn trim_right(&self) -> &str;
2227-
}
2229+
}}
22282230

22292231
// truncate `&str` to length at most equal to `max`
22302232
// 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)