From b4c046b342f01bf2e750e6ac824b94be4b72c8ec Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 22 Oct 2018 20:25:31 +0200 Subject: [PATCH 01/13] constify libcore/time.rs --- src/libcore/time.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/libcore/time.rs diff --git a/src/libcore/time.rs b/src/libcore/time.rs old mode 100644 new mode 100755 index cfbd431aef0a0..938e97503deb6 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -209,7 +209,6 @@ impl Duration { /// /// [`subsec_nanos`]: #method.subsec_nanos #[stable(feature = "duration", since = "1.3.0")] - #[rustc_const_unstable(feature="duration_getters")] #[inline] pub const fn as_secs(&self) -> u64 { self.secs } @@ -229,7 +228,6 @@ impl Duration { /// assert_eq!(duration.subsec_millis(), 432); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] - #[rustc_const_unstable(feature="duration_getters")] #[inline] pub const fn subsec_millis(&self) -> u32 { self.nanos / NANOS_PER_MILLI } @@ -249,7 +247,6 @@ impl Duration { /// assert_eq!(duration.subsec_micros(), 234_567); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] - #[rustc_const_unstable(feature="duration_getters")] #[inline] pub const fn subsec_micros(&self) -> u32 { self.nanos / NANOS_PER_MICRO } @@ -269,7 +266,6 @@ impl Duration { /// assert_eq!(duration.subsec_nanos(), 10_000_000); /// ``` #[stable(feature = "duration", since = "1.3.0")] - #[rustc_const_unstable(feature="duration_getters")] #[inline] pub const fn subsec_nanos(&self) -> u32 { self.nanos } @@ -286,7 +282,7 @@ impl Duration { /// ``` #[unstable(feature = "duration_as_u128", issue = "50202")] #[inline] - pub fn as_millis(&self) -> u128 { + pub const fn as_millis(&self) -> u128 { self.secs as u128 * MILLIS_PER_SEC as u128 + (self.nanos / NANOS_PER_MILLI) as u128 } @@ -303,7 +299,7 @@ impl Duration { /// ``` #[unstable(feature = "duration_as_u128", issue = "50202")] #[inline] - pub fn as_micros(&self) -> u128 { + pub const fn as_micros(&self) -> u128 { self.secs as u128 * MICROS_PER_SEC as u128 + (self.nanos / NANOS_PER_MICRO) as u128 } @@ -320,7 +316,7 @@ impl Duration { /// ``` #[unstable(feature = "duration_as_u128", issue = "50202")] #[inline] - pub fn as_nanos(&self) -> u128 { + pub const fn as_nanos(&self) -> u128 { self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 } @@ -478,7 +474,7 @@ impl Duration { /// ``` #[unstable(feature = "duration_float", issue = "54361")] #[inline] - pub fn as_float_secs(&self) -> f64 { + pub const fn as_float_secs(&self) -> f64 { (self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64) } From 5b89877dda5b8267f1ec35dfc9bb6ddc4472f006 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 02:04:14 +0200 Subject: [PATCH 02/13] constify parts of libcore. --- src/libcore/alloc.rs | 4 +-- src/libcore/array.rs | 2 +- src/libcore/benches/iter.rs | 2 +- src/libcore/cell.rs | 8 ++--- src/libcore/char/decode.rs | 2 +- src/libcore/char/methods.rs | 2 +- src/libcore/convert.rs | 1 - src/libcore/fmt/mod.rs | 32 ++++++++++++------- src/libcore/iter/mod.rs | 2 +- src/libcore/iter/sources.rs | 2 +- src/libcore/lib.rs | 1 - src/libcore/mem.rs | 5 ++- src/libcore/num/dec2flt/mod.rs | 4 +-- src/libcore/num/dec2flt/parse.rs | 2 +- src/libcore/num/dec2flt/rawfp.rs | 2 +- src/libcore/num/flt2dec/estimator.rs | 3 +- src/libcore/num/flt2dec/mod.rs | 1 - src/libcore/num/wrapping.rs | 30 ++++++++--------- src/libcore/ops/range.rs | 4 +-- src/libcore/panic.rs | 14 ++++---- src/libcore/pin.rs | 4 +-- src/libcore/ptr.rs | 4 +-- src/libcore/slice/memchr.rs | 6 ++-- src/libcore/slice/mod.rs | 7 ++-- src/libcore/str/lossy.rs | 2 +- src/libcore/str/mod.rs | 11 +++---- src/libcore/task/wake.rs | 2 +- src/libcore/unicode/bool_trie.rs | 2 +- src/libcore/unicode/tables.rs | 1 - .../consts/const-eval/duration_conversion.rs | 2 -- .../ui/rfc-2306/convert-id-const-no-gate.rs | 17 ---------- .../rfc-2306/convert-id-const-no-gate.stderr | 10 ------ .../ui/rfc-2306/convert-id-const-with-gate.rs | 5 ++- 33 files changed, 84 insertions(+), 112 deletions(-) delete mode 100644 src/test/ui/rfc-2306/convert-id-const-no-gate.rs delete mode 100644 src/test/ui/rfc-2306/convert-id-const-no-gate.stderr diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 113a85abecbef..8b9f7f2c81651 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -25,7 +25,7 @@ use num::NonZeroUsize; #[derive(Debug)] pub struct Excess(pub NonNull, pub usize); -fn size_align() -> (usize, usize) { +const fn size_align() -> (usize, usize) { (mem::size_of::(), mem::align_of::()) } @@ -116,7 +116,7 @@ impl Layout { /// The minimum size in bytes for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] #[inline] - pub fn size(&self) -> usize { self.size_ } + pub const fn size(&self) -> usize { self.size_ } /// The minimum byte alignment for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 3d24f8902bd83..0bea541e16349 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -77,7 +77,7 @@ impl TryFromSliceError { issue = "0")] #[inline] #[doc(hidden)] - pub fn __description(&self) -> &str { + pub const fn __description(&self) -> &str { "could not convert slice to array" } } diff --git a/src/libcore/benches/iter.rs b/src/libcore/benches/iter.rs index 6c597301ac204..c8b8c2eff97b1 100644 --- a/src/libcore/benches/iter.rs +++ b/src/libcore/benches/iter.rs @@ -39,7 +39,7 @@ fn bench_multiple_take(b: &mut Bencher) { }); } -fn scatter(x: i32) -> i32 { (x * 31) % 127 } +const fn scatter(x: i32) -> i32 { (x * 31) % 127 } #[bench] fn bench_max_by_key(b: &mut Bencher) { diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 689cf319bd750..3fe77fe688fa8 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -474,7 +474,7 @@ impl Cell { /// ``` #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] - pub fn as_ptr(&self) -> *mut T { + pub const fn as_ptr(&self) -> *mut T { self.value.get() } @@ -636,12 +636,12 @@ type BorrowFlag = isize; const UNUSED: BorrowFlag = 0; #[inline(always)] -fn is_writing(x: BorrowFlag) -> bool { +const fn is_writing(x: BorrowFlag) -> bool { x < UNUSED } #[inline(always)] -fn is_reading(x: BorrowFlag) -> bool { +const fn is_reading(x: BorrowFlag) -> bool { x > UNUSED } @@ -1508,7 +1508,7 @@ impl UnsafeCell { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn get(&self) -> *mut T { + pub const fn get(&self) -> *mut T { &self.value as *const T as *mut T } } diff --git a/src/libcore/char/decode.rs b/src/libcore/char/decode.rs index cc52f048b891b..bcd1e92c6d86e 100644 --- a/src/libcore/char/decode.rs +++ b/src/libcore/char/decode.rs @@ -130,7 +130,7 @@ impl> Iterator for DecodeUtf16 { impl DecodeUtf16Error { /// Returns the unpaired surrogate which caused this error. #[stable(feature = "decode_utf16", since = "1.9.0")] - pub fn unpaired_surrogate(&self) -> u16 { + pub const fn unpaired_surrogate(&self) -> u16 { self.code } } diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 64a17786b0a6b..35181afea3da6 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -903,7 +903,7 @@ impl char { /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[inline] - pub fn is_ascii(&self) -> bool { + pub const fn is_ascii(&self) -> bool { *self as u32 <= 0x7F } diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index b900990d0a726..dbc28ef7cf6a9 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -104,7 +104,6 @@ /// assert_eq!(vec![1, 3], filtered); /// ``` #[unstable(feature = "convert_id", issue = "53500")] -#[rustc_const_unstable(feature = "const_convert_id")] #[inline] pub const fn identity(x: T) -> T { x } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 75ec0d7d50be6..56576f8334b85 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -341,7 +341,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] - pub fn new_v1(pieces: &'a [&'a str], + pub const fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { Arguments { pieces, @@ -359,7 +359,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] - pub fn new_v1_formatted(pieces: &'a [&'a str], + pub const fn new_v1_formatted(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>], fmt: &'a [rt::v1::Argument]) -> Arguments<'a> { Arguments { @@ -1492,7 +1492,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{:t>6}", Foo), "tttttt"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn fill(&self) -> char { self.fill } + pub const fn fill(&self) -> char { self.fill } /// Flag indicating what form of alignment was requested. /// @@ -1562,7 +1562,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn width(&self) -> Option { self.width } + pub const fn width(&self) -> Option { self.width } /// Optionally specified precision for numeric types. /// @@ -1589,7 +1589,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn precision(&self) -> Option { self.precision } + pub const fn precision(&self) -> Option { self.precision } /// Determines if the `+` flag was specified. /// @@ -1617,7 +1617,9 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 } + pub const fn sign_plus(&self) -> bool { + self.flags & (1 << FlagV1::SignPlus as u32) != 0 + } /// Determines if the `-` flag was specified. /// @@ -1643,7 +1645,9 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 } + pub const fn sign_minus(&self) -> bool { + self.flags & (1 << FlagV1::SignMinus as u32) != 0 + } /// Determines if the `#` flag was specified. /// @@ -1668,7 +1672,9 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 } + pub const fn alternate(&self) -> bool { + self.flags & (1 << FlagV1::Alternate as u32) != 0 + } /// Determines if the `0` flag was specified. /// @@ -1691,15 +1697,19 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{:04}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_aware_zero_pad(&self) -> bool { + pub const fn sign_aware_zero_pad(&self) -> bool { self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0 } // FIXME: Decide what public API we want for these two flags. // https://github.com/rust-lang/rust/issues/48584 - fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 } + const fn debug_lower_hex(&self) -> bool { + self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 + } - fn debug_upper_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 } + const fn debug_upper_hex(&self) -> bool { + self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 + } /// Creates a [`DebugStruct`] builder designed to assist with creation of /// [`fmt::Debug`] implementations for structs. diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index c42fb7019c771..72a032b57d09f 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -2658,7 +2658,7 @@ impl FusedIterator for Flatten I::Item: IntoIterator {} /// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`. -fn flatten_compat(iter: I) -> FlattenCompat { +const fn flatten_compat(iter: I) -> FlattenCompat { FlattenCompat { iter, frontiter: None, backiter: None } } diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index d500cc99fa13c..7fa3a4bcce7bb 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -283,7 +283,7 @@ impl Default for Empty { /// assert_eq!(None, nope.next()); /// ``` #[stable(feature = "iter_empty", since = "1.2.0")] -pub fn empty() -> Empty { +pub const fn empty() -> Empty { Empty(marker::PhantomData) } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 1bbc7892c6bef..2445d93692748 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -82,7 +82,6 @@ #![feature(const_fn)] #![feature(const_int_ops)] #![feature(const_fn_union)] -#![feature(const_manually_drop_new)] #![feature(custom_attribute)] #![feature(doc_cfg)] #![feature(doc_spotlight)] diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 1d0b194487e68..0aa374c7a6446 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -139,7 +139,7 @@ pub use intrinsics::transmute; /// [ub]: ../../reference/behavior-considered-undefined.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] -pub fn forget(t: T) { +pub const fn forget(t: T) { ManuallyDrop::new(t); } @@ -942,7 +942,6 @@ impl ManuallyDrop { /// ManuallyDrop::new(Box::new(())); /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] - #[rustc_const_unstable(feature = "const_manually_drop_new")] #[inline] pub const fn new(value: T) -> ManuallyDrop { ManuallyDrop { value } @@ -961,7 +960,7 @@ impl ManuallyDrop { /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] #[inline] - pub fn into_inner(slot: ManuallyDrop) -> T { + pub const fn into_inner(slot: ManuallyDrop) -> T { slot.value } diff --git a/src/libcore/num/dec2flt/mod.rs b/src/libcore/num/dec2flt/mod.rs index f93564c2849f5..0e1f6664d9656 100644 --- a/src/libcore/num/dec2flt/mod.rs +++ b/src/libcore/num/dec2flt/mod.rs @@ -187,11 +187,11 @@ impl fmt::Display for ParseFloatError { } } -fn pfe_empty() -> ParseFloatError { +const fn pfe_empty() -> ParseFloatError { ParseFloatError { kind: FloatErrorKind::Empty } } -fn pfe_invalid() -> ParseFloatError { +const fn pfe_invalid() -> ParseFloatError { ParseFloatError { kind: FloatErrorKind::Invalid } } diff --git a/src/libcore/num/dec2flt/parse.rs b/src/libcore/num/dec2flt/parse.rs index e7ed94d4d91c2..8d8f357425ef0 100644 --- a/src/libcore/num/dec2flt/parse.rs +++ b/src/libcore/num/dec2flt/parse.rs @@ -39,7 +39,7 @@ pub struct Decimal<'a> { } impl<'a> Decimal<'a> { - pub fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> { + pub const fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> { Decimal { integral, fractional, exp } } } diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index 38f4e4687a99b..c5d4aa689583c 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -44,7 +44,7 @@ pub struct Unpacked { } impl Unpacked { - pub fn new(sig: u64, k: i16) -> Self { + pub const fn new(sig: u64, k: i16) -> Self { Unpacked { sig, k } } } diff --git a/src/libcore/num/flt2dec/estimator.rs b/src/libcore/num/flt2dec/estimator.rs index d42e05a91f140..2a87bf436646d 100644 --- a/src/libcore/num/flt2dec/estimator.rs +++ b/src/libcore/num/flt2dec/estimator.rs @@ -15,11 +15,10 @@ /// This is used to approximate `k = ceil(log_10 (mant * 2^exp))`; /// the true `k` is either `k_0` or `k_0+1`. #[doc(hidden)] -pub fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { +pub const fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { // 2^(nbits-1) < mant <= 2^nbits if mant > 0 let nbits = 64 - (mant - 1).leading_zeros() as i64; // 1292913986 = floor(2^32 * log_10 2) // therefore this always underestimates (or is exact), but not much. (((nbits + exp as i64) * 1292913986) >> 32) as i16 } - diff --git a/src/libcore/num/flt2dec/mod.rs b/src/libcore/num/flt2dec/mod.rs index 21a2e72dac8c3..d58015beecb1e 100644 --- a/src/libcore/num/flt2dec/mod.rs +++ b/src/libcore/num/flt2dec/mod.rs @@ -658,4 +658,3 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T, } } } - diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 1c826c2fa76bd..00134a58d30f1 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -387,7 +387,7 @@ assert_eq!(n.count_ones(), 3); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn count_ones(self) -> u32 { + pub const fn count_ones(self) -> u32 { self.0.count_ones() } } @@ -407,7 +407,7 @@ assert_eq!(Wrapping(!0", stringify!($t), ").count_zeros(), 0); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn count_zeros(self) -> u32 { + pub const fn count_zeros(self) -> u32 { self.0.count_zeros() } } @@ -430,7 +430,7 @@ assert_eq!(n.trailing_zeros(), 3); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn trailing_zeros(self) -> u32 { + pub const fn trailing_zeros(self) -> u32 { self.0.trailing_zeros() } } @@ -456,7 +456,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn rotate_left(self, n: u32) -> Self { + pub const fn rotate_left(self, n: u32) -> Self { Wrapping(self.0.rotate_left(n)) } @@ -481,7 +481,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn rotate_right(self, n: u32) -> Self { + pub const fn rotate_right(self, n: u32) -> Self { Wrapping(self.0.rotate_right(n)) } @@ -505,7 +505,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn swap_bytes(self) -> Self { + pub const fn swap_bytes(self) -> Self { Wrapping(self.0.swap_bytes()) } @@ -532,7 +532,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[unstable(feature = "reverse_bits", issue = "48763")] #[inline] - pub fn reverse_bits(self) -> Self { + pub const fn reverse_bits(self) -> Self { Wrapping(self.0.reverse_bits()) } @@ -560,7 +560,7 @@ if cfg!(target_endian = \"big\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn from_be(x: Self) -> Self { + pub const fn from_be(x: Self) -> Self { Wrapping(<$t>::from_be(x.0)) } } @@ -589,7 +589,7 @@ if cfg!(target_endian = \"little\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn from_le(x: Self) -> Self { + pub const fn from_le(x: Self) -> Self { Wrapping(<$t>::from_le(x.0)) } } @@ -618,7 +618,7 @@ if cfg!(target_endian = \"big\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn to_be(self) -> Self { + pub const fn to_be(self) -> Self { Wrapping(self.0.to_be()) } } @@ -647,7 +647,7 @@ if cfg!(target_endian = \"little\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn to_le(self) -> Self { + pub const fn to_le(self) -> Self { Wrapping(self.0.to_le()) } } @@ -707,7 +707,7 @@ assert_eq!(n.leading_zeros(), 3); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn leading_zeros(self) -> u32 { + pub const fn leading_zeros(self) -> u32 { self.0.leading_zeros() } } @@ -784,7 +784,7 @@ assert!(!Wrapping(-10", stringify!($t), ").is_positive()); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn is_positive(self) -> bool { + pub const fn is_positive(self) -> bool { self.0.is_positive() } } @@ -806,7 +806,7 @@ assert!(!Wrapping(10", stringify!($t), ").is_negative()); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn is_negative(self) -> bool { + pub const fn is_negative(self) -> bool { self.0.is_negative() } } @@ -836,7 +836,7 @@ assert_eq!(n.leading_zeros(), 2); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn leading_zeros(self) -> u32 { + pub const fn leading_zeros(self) -> u32 { self.0.leading_zeros() } } diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 6cfb1005325ba..908490e1c839e 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -416,7 +416,7 @@ impl RangeInclusive { /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] #[inline] - pub fn start(&self) -> &Idx { + pub const fn start(&self) -> &Idx { &self.start } @@ -440,7 +440,7 @@ impl RangeInclusive { /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] #[inline] - pub fn end(&self) -> &Idx { + pub const fn end(&self) -> &Idx { &self.end } diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index f0efeb59e8d6e..af9d1596938e0 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -55,7 +55,7 @@ impl<'a> PanicInfo<'a> { issue = "0")] #[doc(hidden)] #[inline] - pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, + pub const fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, location: Location<'a>) -> Self { struct NoPayload; @@ -96,7 +96,7 @@ impl<'a> PanicInfo<'a> { /// /// [`fmt::write`]: ../fmt/fn.write.html #[unstable(feature = "panic_info_message", issue = "44489")] - pub fn message(&self) -> Option<&fmt::Arguments> { + pub const fn message(&self) -> Option<&fmt::Arguments> { self.message } @@ -125,7 +125,7 @@ impl<'a> PanicInfo<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn location(&self) -> Option<&Location> { + pub const fn location(&self) -> Option<&Location> { // NOTE: If this is changed to sometimes return None, // deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt. Some(&self.location) @@ -186,7 +186,7 @@ impl<'a> Location<'a> { and related macros", issue = "0")] #[doc(hidden)] - pub fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { + pub const fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { Location { file, line, col } } @@ -208,7 +208,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn file(&self) -> &str { + pub const fn file(&self) -> &str { self.file } @@ -230,7 +230,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn line(&self) -> u32 { + pub const fn line(&self) -> u32 { self.line } @@ -252,7 +252,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_col", since = "1.25.0")] - pub fn column(&self) -> u32 { + pub const fn column(&self) -> u32 { self.col } } diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index 68de82d294529..63a433a8b2301 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -207,7 +207,7 @@ impl<'a, T: ?Sized> Pin<&'a T> { /// with the same lifetime as the original `Pin`. #[unstable(feature = "pin", issue = "49150")] #[inline(always)] - pub fn get_ref(this: Pin<&'a T>) -> &'a T { + pub const fn get_ref(this: Pin<&'a T>) -> &'a T { this.pointer } } @@ -216,7 +216,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> { /// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime. #[unstable(feature = "pin", issue = "49150")] #[inline(always)] - pub fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> { + pub const fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> { Pin { pointer: this.pointer } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 62ccf6c865cd9..c06e580e30eb5 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2759,7 +2759,7 @@ impl Unique { } /// Acquires the underlying `*mut` pointer. - pub fn as_ptr(self) -> *mut T { + pub const fn as_ptr(self) -> *mut T { self.pointer.0 as *mut T } @@ -2905,7 +2905,7 @@ impl NonNull { /// Acquires the underlying `*mut` pointer. #[stable(feature = "nonnull", since = "1.25.0")] #[inline] - pub fn as_ptr(self) -> *mut T { + pub const fn as_ptr(self) -> *mut T { self.pointer.0 as *mut T } diff --git a/src/libcore/slice/memchr.rs b/src/libcore/slice/memchr.rs index cf95333af9cbb..deaeb53e84a3a 100644 --- a/src/libcore/slice/memchr.rs +++ b/src/libcore/slice/memchr.rs @@ -29,19 +29,19 @@ const HI_USIZE: usize = HI_U64 as usize; /// bytes where the borrow propagated all the way to the most significant /// bit." #[inline] -fn contains_zero_byte(x: usize) -> bool { +const fn contains_zero_byte(x: usize) -> bool { x.wrapping_sub(LO_USIZE) & !x & HI_USIZE != 0 } #[cfg(target_pointer_width = "16")] #[inline] -fn repeat_byte(b: u8) -> usize { +const fn repeat_byte(b: u8) -> usize { (b as usize) << 8 | b as usize } #[cfg(not(target_pointer_width = "16"))] #[inline] -fn repeat_byte(b: u8) -> usize { +const fn repeat_byte(b: u8) -> usize { (b as usize) * (::usize::MAX / 255) } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 8a6b212020b4e..f8dee5370621d 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -385,7 +385,6 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - #[rustc_const_unstable(feature = "const_slice_as_ptr")] pub const fn as_ptr(&self) -> *const T { self as *const [T] as *const T } @@ -2738,7 +2737,7 @@ impl<'a, T> IntoIterator for &'a mut [T] { // Macro helper functions #[inline(always)] -fn size_from_ptr(_: *const T) -> usize { +const fn size_from_ptr(_: *const T) -> usize { mem::size_of::() } @@ -4022,7 +4021,7 @@ impl<'a, T> ChunksExact<'a, T> { /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. #[stable(feature = "chunks_exact", since = "1.31.0")] - pub fn remainder(&self) -> &'a [T] { + pub const fn remainder(&self) -> &'a [T] { self.rem } } @@ -4518,7 +4517,7 @@ impl<'a, T> RChunksExact<'a, T> { /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. #[stable(feature = "rchunks", since = "1.31.0")] - pub fn remainder(&self) -> &'a [T] { + pub const fn remainder(&self) -> &'a [T] { self.rem } } diff --git a/src/libcore/str/lossy.rs b/src/libcore/str/lossy.rs index 186d6adbc91cf..950552fc6b172 100644 --- a/src/libcore/str/lossy.rs +++ b/src/libcore/str/lossy.rs @@ -29,7 +29,7 @@ impl Utf8Lossy { unsafe { mem::transmute(bytes) } } - pub fn chunks(&self) -> Utf8LossyChunksIter { + pub const fn chunks(&self) -> Utf8LossyChunksIter { Utf8LossyChunksIter { source: &self.bytes } } } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index a2782dd8e2e43..d73e5db727c91 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -231,7 +231,7 @@ impl Utf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "utf8_error", since = "1.5.0")] - pub fn valid_up_to(&self) -> usize { self.valid_up_to } + pub const fn valid_up_to(&self) -> usize { self.valid_up_to } /// Provide more information about the failure: /// @@ -476,16 +476,16 @@ pub struct Chars<'a> { /// The first byte is special, only want bottom 5 bits for width 2, 4 bits /// for width 3, and 3 bits for width 4. #[inline] -fn utf8_first_byte(byte: u8, width: u32) -> u32 { (byte & (0x7F >> width)) as u32 } +const fn utf8_first_byte(byte: u8, width: u32) -> u32 { (byte & (0x7F >> width)) as u32 } /// Returns the value of `ch` updated with continuation byte `byte`. #[inline] -fn utf8_acc_cont_byte(ch: u32, byte: u8) -> u32 { (ch << 6) | (byte & CONT_MASK) as u32 } +const fn utf8_acc_cont_byte(ch: u32, byte: u8) -> u32 { (ch << 6) | (byte & CONT_MASK) as u32 } /// Checks whether the byte is a UTF-8 continuation byte (i.e. starts with the /// bits `10`). #[inline] -fn utf8_is_cont_byte(byte: u8) -> bool { (byte & !CONT_MASK) == TAG_CONT_U8 } +const fn utf8_is_cont_byte(byte: u8) -> bool { (byte & !CONT_MASK) == TAG_CONT_U8 } #[inline] fn unwrap_or_0(opt: Option<&u8>) -> u8 { @@ -1420,7 +1420,7 @@ const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; /// Returns `true` if any byte in the word `x` is nonascii (>= 128). #[inline] -fn contains_nonascii(x: usize) -> bool { +const fn contains_nonascii(x: usize) -> bool { (x & NONASCII_MASK) != 0 } @@ -2277,7 +2277,6 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - #[rustc_const_unstable(feature = "const_str_as_ptr")] pub const fn as_ptr(&self) -> *const u8 { self as *const str as *const u8 } diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index c9fb22e0080dd..1db3a290e046f 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -141,7 +141,7 @@ impl LocalWaker { /// `Waker` is nearly identical to `LocalWaker`, but is threadsafe /// (implements `Send` and `Sync`). #[inline] - pub fn as_waker(&self) -> &Waker { + pub const fn as_waker(&self) -> &Waker { &self.0 } diff --git a/src/libcore/unicode/bool_trie.rs b/src/libcore/unicode/bool_trie.rs index 0e6437fded594..995795839b7d8 100644 --- a/src/libcore/unicode/bool_trie.rs +++ b/src/libcore/unicode/bool_trie.rs @@ -71,6 +71,6 @@ impl SmallBoolTrie { } } -fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool { +const fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool { ((bitmap_chunk >> (c & 63)) & 1) != 0 } diff --git a/src/libcore/unicode/tables.rs b/src/libcore/unicode/tables.rs index 3de855ac94315..e525c0574002b 100644 --- a/src/libcore/unicode/tables.rs +++ b/src/libcore/unicode/tables.rs @@ -2598,4 +2598,3 @@ pub mod conversions { ]; } - diff --git a/src/test/ui/consts/const-eval/duration_conversion.rs b/src/test/ui/consts/const-eval/duration_conversion.rs index 4481b75840487..c8bed4a2b77e1 100644 --- a/src/test/ui/consts/const-eval/duration_conversion.rs +++ b/src/test/ui/consts/const-eval/duration_conversion.rs @@ -10,8 +10,6 @@ // compile-pass -#![feature(duration_getters)] - use std::time::Duration; fn main() { diff --git a/src/test/ui/rfc-2306/convert-id-const-no-gate.rs b/src/test/ui/rfc-2306/convert-id-const-no-gate.rs deleted file mode 100644 index 545c179dec9fc..0000000000000 --- a/src/test/ui/rfc-2306/convert-id-const-no-gate.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This test should fail since identity is not stable as a const fn yet. - -#![feature(convert_id)] - -fn main() { - const _FOO: u8 = ::std::convert::identity(42u8); -} diff --git a/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr b/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr deleted file mode 100644 index dfd8619d87516..0000000000000 --- a/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `std::convert::identity` is not yet stable as a const fn - --> $DIR/convert-id-const-no-gate.rs:16:22 - | -LL | const _FOO: u8 = ::std::convert::identity(42u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: in Nightly builds, add `#![feature(const_convert_id)]` to the crate attributes to enable - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2306/convert-id-const-with-gate.rs b/src/test/ui/rfc-2306/convert-id-const-with-gate.rs index c546f11914f81..2e71aee57c2f1 100644 --- a/src/test/ui/rfc-2306/convert-id-const-with-gate.rs +++ b/src/test/ui/rfc-2306/convert-id-const-with-gate.rs @@ -8,12 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// This test should pass since we've opted into 'identity' as an -// unstable const fn. +// This test should pass since 'identity' is const fn. // compile-pass -#![feature(convert_id, const_convert_id)] +#![feature(convert_id)] fn main() { const _FOO: u8 = ::std::convert::identity(42u8); From 061d345c1657a86a9d94e90f916a0be8c966d062 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 02:04:31 +0200 Subject: [PATCH 03/13] constify parts of liballoc. --- src/liballoc/collections/binary_heap.rs | 2 +- src/liballoc/collections/btree/map.rs | 4 ++-- src/liballoc/collections/btree/node.rs | 2 +- src/liballoc/collections/btree/set.rs | 4 ++-- src/liballoc/collections/linked_list.rs | 12 ++++++------ src/liballoc/collections/vec_deque.rs | 4 ++-- src/liballoc/raw_vec.rs | 4 ++-- src/liballoc/string.rs | 6 +++--- src/liballoc/vec.rs | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index fcadcb544c431..e7e741dea4ce3 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -884,7 +884,7 @@ impl<'a, T> Hole<'a, T> { } #[inline] - fn pos(&self) -> usize { + const fn pos(&self) -> usize { self.pos } diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 24c8fd3a969ca..8a721a50b4689 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -2074,7 +2074,7 @@ impl BTreeMap { /// assert_eq!(a.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.length } @@ -2093,7 +2093,7 @@ impl BTreeMap { /// assert!(!a.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 } } diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index deca9591fbd5c..10665b8e46334 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -357,7 +357,7 @@ impl NodeRef { /// Returns the height of this node in the whole tree. Zero height denotes the /// leaf level. - pub fn height(&self) -> usize { + pub const fn height(&self) -> usize { self.height } diff --git a/src/liballoc/collections/btree/set.rs b/src/liballoc/collections/btree/set.rs index af9a7074e4a4f..6a0ecfd3f5815 100644 --- a/src/liballoc/collections/btree/set.rs +++ b/src/liballoc/collections/btree/set.rs @@ -730,7 +730,7 @@ impl BTreeSet { /// assert_eq!(v.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.map.len() } @@ -747,7 +747,7 @@ impl BTreeSet { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 } } diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 2ef84dbade0fb..9b2975b81a3c7 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -135,7 +135,7 @@ impl fmt::Debug for IntoIter { } impl Node { - fn new(element: T) -> Self { + const fn new(element: T) -> Self { Node { next: None, prev: None, @@ -264,7 +264,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn new() -> Self { + pub const fn new() -> Self { LinkedList { head: None, tail: None, @@ -341,7 +341,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn iter(&self) -> Iter { + pub const fn iter(&self) -> Iter { Iter { head: self.head, tail: self.tail, @@ -401,8 +401,8 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { - self.head.is_none() + pub const fn is_empty(&self) -> bool { + self.len() == 0 } /// Returns the length of the `LinkedList`. @@ -427,7 +427,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.len } diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 88e76033f273e..b139b440fe160 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -933,7 +933,7 @@ impl VecDeque { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.tail == self.head } @@ -1275,7 +1275,7 @@ impl VecDeque { } #[inline] - fn is_contiguous(&self) -> bool { + const fn is_contiguous(&self) -> bool { self.tail <= self.head } diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 837770feecef5..0b6f400a40303 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -204,7 +204,7 @@ impl RawVec { /// Gets a raw pointer to the start of the allocation. Note that this is /// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must /// be careful. - pub fn ptr(&self) -> *mut T { + pub const fn ptr(&self) -> *mut T { self.ptr.as_ptr() } @@ -221,7 +221,7 @@ impl RawVec { } /// Returns a shared reference to the allocator backing this RawVec. - pub fn alloc(&self) -> &A { + pub const fn alloc(&self) -> &A { &self.a } diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 5c776292f53d7..8f379c4cfb459 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1374,7 +1374,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.vec.len() } @@ -1395,7 +1395,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 } @@ -1662,7 +1662,7 @@ impl FromUtf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn utf8_error(&self) -> Utf8Error { + pub const fn utf8_error(&self) -> Utf8Error { self.error } } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index f7a0bbdceafc9..78e9da2084dbe 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1165,7 +1165,7 @@ impl Vec { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.len } @@ -1181,7 +1181,7 @@ impl Vec { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 } From f65b630d33ef2e57f0966c9b7b1f179e78502a9d Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 02:04:42 +0200 Subject: [PATCH 04/13] constify parts of libstd. --- src/libcore/time.rs | 0 src/libstd/collections/hash/map.rs | 6 +++--- src/libstd/collections/hash/table.rs | 12 ++++++------ src/libstd/ffi/c_str.rs | 10 +++++----- src/libstd/io/buffered.rs | 2 +- src/libstd/io/cursor.rs | 6 +++--- src/libstd/io/mod.rs | 10 +++++----- src/libstd/io/util.rs | 4 ++-- src/libstd/net/addr.rs | 4 ++-- src/libstd/net/ip.rs | 7 +++---- src/libstd/path.rs | 8 ++++---- src/libstd/process.rs | 6 +++--- src/libstd/sync/condvar.rs | 2 +- src/libstd/sync/mpsc/mod.rs | 6 +++--- src/libstd/sync/mpsc/oneshot.rs | 2 +- src/libstd/sync/once.rs | 2 +- src/libstd/sys_common/mutex.rs | 2 +- src/libstd/sys_common/net.rs | 6 +++--- src/libstd/sys_common/wtf8.rs | 4 ++-- src/libstd/thread/mod.rs | 4 ++-- src/libstd/time.rs | 2 +- 21 files changed, 52 insertions(+), 53 deletions(-) mode change 100755 => 100644 src/libcore/time.rs diff --git a/src/libcore/time.rs b/src/libcore/time.rs old mode 100755 new mode 100644 diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8de415e8aed5c..b95449d11eac3 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -36,7 +36,7 @@ struct DefaultResizePolicy; impl DefaultResizePolicy { #[inline] - fn new() -> DefaultResizePolicy { + const fn new() -> DefaultResizePolicy { DefaultResizePolicy } @@ -69,7 +69,7 @@ impl DefaultResizePolicy { /// The capacity of the given raw capacity. #[inline] - fn capacity(&self, raw_cap: usize) -> usize { + const fn capacity(&self, raw_cap: usize) -> usize { // This doesn't have to be checked for overflow since allocation size // in bytes will overflow earlier than multiplication by 10. // @@ -3013,7 +3013,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> { /// assert_eq!(map.entry("poneyland").key(), &"poneyland"); /// ``` #[stable(feature = "map_entry_keys", since = "1.10.0")] - pub fn key(&self) -> &K { + pub const fn key(&self) -> &K { &self.key } diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 547f97cc8acee..0df20395b012b 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -247,7 +247,7 @@ impl RawBucket { // Buckets hold references to the table. impl FullBucket { /// Borrow a reference to the table. - pub fn table(&self) -> &M { + pub const fn table(&self) -> &M { &self.table } /// Borrow a mutable reference to the table. @@ -259,18 +259,18 @@ impl FullBucket { self.table } /// Get the raw index. - pub fn index(&self) -> usize { + pub const fn index(&self) -> usize { self.raw.idx } /// Get the raw bucket. - pub fn raw(&self) -> RawBucket { + pub const fn raw(&self) -> RawBucket { self.raw } } impl EmptyBucket { /// Borrow a reference to the table. - pub fn table(&self) -> &M { + pub const fn table(&self) -> &M { &self.table } /// Borrow a mutable reference to the table. @@ -281,7 +281,7 @@ impl EmptyBucket { impl Bucket { /// Get the raw index. - pub fn index(&self) -> usize { + pub const fn index(&self) -> usize { self.raw.idx } /// get the table. @@ -772,7 +772,7 @@ impl RawTable { /// The number of elements ever `put` in the hashtable, minus the number /// of elements ever `take`n. - pub fn size(&self) -> usize { + pub const fn size(&self) -> usize { self.size } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index dfec13cd2ec00..feff65bff3f2a 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -265,12 +265,12 @@ enum FromBytesWithNulErrorKind { } impl FromBytesWithNulError { - fn interior_nul(pos: usize) -> FromBytesWithNulError { + const fn interior_nul(pos: usize) -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::InteriorNul(pos), } } - fn not_nul_terminated() -> FromBytesWithNulError { + const fn not_nul_terminated() -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::NotNulTerminated, } @@ -833,7 +833,7 @@ impl NulError { /// assert_eq!(nul_error.nul_position(), 7); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn nul_position(&self) -> usize { self.0 } + pub const fn nul_position(&self) -> usize { self.0 } /// Consumes this error, returning the underlying vector of bytes which /// generated the error in the first place. @@ -909,7 +909,7 @@ impl IntoStringError { /// Access the underlying UTF-8 error that was the cause of this error. #[stable(feature = "cstring_into", since = "1.7.0")] - pub fn utf8_error(&self) -> Utf8Error { + pub const fn utf8_error(&self) -> Utf8Error { self.error } } @@ -1091,7 +1091,7 @@ impl CStr { /// [`CString`]: struct.CString.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn as_ptr(&self) -> *const c_char { + pub const fn as_ptr(&self) -> *const c_char { self.inner.as_ptr() } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index e26e6d391f84d..bde9c57c57cc5 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -633,7 +633,7 @@ impl IntoInnerError { /// }; /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn error(&self) -> &Error { &self.1 } + pub const fn error(&self) -> &Error { &self.1 } /// Returns the buffered writer instance which generated the error. /// diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 14f20151dca86..05bee19c93f54 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -104,7 +104,7 @@ impl Cursor { /// # force_inference(&buff); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(inner: T) -> Cursor { + pub const fn new(inner: T) -> Cursor { Cursor { pos: 0, inner: inner } } @@ -138,7 +138,7 @@ impl Cursor { /// let reference = buff.get_ref(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn get_ref(&self) -> &T { &self.inner } + pub const fn get_ref(&self) -> &T { &self.inner } /// Gets a mutable reference to the underlying value in this cursor. /// @@ -179,7 +179,7 @@ impl Cursor { /// assert_eq!(buff.position(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn position(&self) -> u64 { self.pos } + pub const fn position(&self) -> u64 { self.pos } /// Sets the position of this cursor. /// diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index e263db24fc2c8..4c3117260feeb 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -885,7 +885,7 @@ impl Initializer { /// Returns a new `Initializer` which will zero out buffers. #[unstable(feature = "read_initializer", issue = "42788")] #[inline] - pub fn zeroing() -> Initializer { + pub const fn zeroing() -> Initializer { Initializer(true) } @@ -906,7 +906,7 @@ impl Initializer { /// Indicates if a buffer should be initialized. #[unstable(feature = "read_initializer", issue = "42788")] #[inline] - pub fn should_initialize(&self) -> bool { + pub const fn should_initialize(&self) -> bool { self.0 } @@ -1653,7 +1653,7 @@ impl Chain { /// } /// ``` #[stable(feature = "more_io_inner_methods", since = "1.20.0")] - pub fn get_ref(&self) -> (&T, &U) { + pub const fn get_ref(&self) -> (&T, &U) { (&self.first, &self.second) } @@ -1780,7 +1780,7 @@ impl Take { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn limit(&self) -> u64 { self.limit } + pub const fn limit(&self) -> u64 { self.limit } /// Sets the number of bytes that can be read before this instance will /// return EOF. This is the same as constructing a new `Take` instance, so @@ -1856,7 +1856,7 @@ impl Take { /// } /// ``` #[stable(feature = "more_io_inner_methods", since = "1.20.0")] - pub fn get_ref(&self) -> &T { + pub const fn get_ref(&self) -> &T { &self.inner } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 12995d0868345..d0db4cfc704be 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -99,7 +99,7 @@ pub struct Empty { _priv: () } /// assert!(buffer.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn empty() -> Empty { Empty { _priv: () } } +pub const fn empty() -> Empty { Empty { _priv: () } } #[stable(feature = "rust1", since = "1.0.0")] impl Read for Empty { @@ -199,7 +199,7 @@ pub struct Sink { _priv: () } /// assert_eq!(num_bytes, 5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn sink() -> Sink { Sink { _priv: () } } +pub const fn sink() -> Sink { Sink { _priv: () } } #[stable(feature = "rust1", since = "1.0.0")] impl Write for Sink { diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index ff35325ab4fda..fc2e810478263 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -475,7 +475,7 @@ impl SocketAddrV6 { /// assert_eq!(socket.flowinfo(), 10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn flowinfo(&self) -> u32 { + pub const fn flowinfo(&self) -> u32 { self.inner.sin6_flowinfo } @@ -515,7 +515,7 @@ impl SocketAddrV6 { /// assert_eq!(socket.scope_id(), 78); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn scope_id(&self) -> u32 { + pub const fn scope_id(&self) -> u32 { self.inner.sin6_scope_id } diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index d45a66ef66532..c5106c9abb9b4 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -402,7 +402,7 @@ impl Ipv4Addr { /// assert_eq!(addr.octets(), [127, 0, 0, 1]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn octets(&self) -> [u8; 4] { + pub fn octets(&self) -> [u8; 4] { let bits = u32::from_be(self.inner.s_addr); [(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8] } @@ -424,7 +424,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false); /// ``` #[stable(feature = "ip_shared", since = "1.12.0")] - pub fn is_unspecified(&self) -> bool { + pub const fn is_unspecified(&self) -> bool { self.inner.s_addr == 0 } @@ -862,7 +862,6 @@ impl Ipv6Addr { /// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ip")] pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { Ipv6Addr { @@ -1224,7 +1223,7 @@ impl Ipv6Addr { /// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); /// ``` #[stable(feature = "ipv6_to_octets", since = "1.12.0")] - pub fn octets(&self) -> [u8; 16] { + pub const fn octets(&self) -> [u8; 16] { self.inner.s6_addr } } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index a153456370c6f..71f39ff85e71a 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -439,7 +439,7 @@ impl<'a> PrefixComponent<'a> { /// /// [`Prefix`]: enum.Prefix.html #[stable(feature = "rust1", since = "1.0.0")] - pub fn kind(&self) -> Prefix<'a> { + pub const fn kind(&self) -> Prefix<'a> { self.parsed } @@ -447,7 +447,7 @@ impl<'a> PrefixComponent<'a> { /// /// [`OsStr`]: ../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] - pub fn as_os_str(&self) -> &'a OsStr { + pub const fn as_os_str(&self) -> &'a OsStr { self.raw } } @@ -1918,7 +1918,7 @@ impl Path { /// [`None`]: ../../std/option/enum.Option.html#variant.None /// [`parent`]: struct.Path.html#method.parent #[stable(feature = "path_ancestors", since = "1.28.0")] - pub fn ancestors(&self) -> Ancestors { + pub const fn ancestors(&self) -> Ancestors { Ancestors { next: Some(&self), } @@ -2267,7 +2267,7 @@ impl Path { /// println!("{}", path.display()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn display(&self) -> Display { + pub const fn display(&self) -> Display { Display { path: self } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index a9219f75362db..d5047ef6ad728 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -926,7 +926,7 @@ impl Stdio { /// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n"); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } + pub const fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } /// The child inherits from the corresponding parent descriptor. /// @@ -961,7 +961,7 @@ impl Stdio { /// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout)); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } + pub const fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } /// This stream will be ignored. This is the equivalent of attaching the /// stream to `/dev/null` @@ -998,7 +998,7 @@ impl Stdio { /// // Ignores any piped-in input /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn null() -> Stdio { Stdio(imp::Stdio::Null) } + pub const fn null() -> Stdio { Stdio(imp::Stdio::Null) } } impl FromInner for Stdio { diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 3014283da5b27..1c6cc9cb361e5 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -72,7 +72,7 @@ impl WaitTimeoutResult { /// } /// ``` #[stable(feature = "wait_timeout", since = "1.5.0")] - pub fn timed_out(&self) -> bool { + pub const fn timed_out(&self) -> bool { self.0 } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 059ced4f56efd..2a2e5c030b32f 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -785,7 +785,7 @@ pub fn sync_channel(bound: usize) -> (SyncSender, Receiver) { //////////////////////////////////////////////////////////////////////////////// impl Sender { - fn new(inner: Flavor) -> Sender { + const fn new(inner: Flavor) -> Sender { Sender { inner: UnsafeCell::new(inner), } @@ -1469,7 +1469,7 @@ impl Receiver { /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn iter(&self) -> Iter { + pub const fn iter(&self) -> Iter { Iter { rx: self } } @@ -1512,7 +1512,7 @@ impl Receiver { /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "receiver_try_iter", since = "1.15.0")] - pub fn try_iter(&self) -> TryIter { + pub const fn try_iter(&self) -> TryIter { TryIter { rx: self } } diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index b8e50c9297b64..273644cb902db 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -89,7 +89,7 @@ enum MyUpgrade { } impl Packet { - pub fn new() -> Packet { + pub const fn new() -> Packet { Packet { data: UnsafeCell::new(None), upgrade: UnsafeCell::new(NothingSent), diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index cf9698cb2a971..4dd37ec387884 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -517,7 +517,7 @@ impl OnceState { /// assert!(!state.poisoned()); /// }); #[unstable(feature = "once_poison", issue = "33577")] - pub fn poisoned(&self) -> bool { + pub const fn poisoned(&self) -> bool { self.poisoned } } diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs index c6d531c7a1ac5..dc9edb306de0d 100644 --- a/src/libstd/sys_common/mutex.rs +++ b/src/libstd/sys_common/mutex.rs @@ -80,7 +80,7 @@ impl Mutex { } // not meant to be exported to the outside world, just the containing module -pub fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } +pub const fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } #[must_use] /// A simple RAII utility for the above Mutex without the poisoning semantics. diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index d09a233ed896f..f58c26ef4280a 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -199,7 +199,7 @@ impl TcpStream { Ok(TcpStream { inner: sock }) } - pub fn socket(&self) -> &Socket { &self.inner } + pub const fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -339,7 +339,7 @@ impl TcpListener { Ok(TcpListener { inner: sock }) } - pub fn socket(&self) -> &Socket { &self.inner } + pub const fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -427,7 +427,7 @@ impl UdpSocket { Ok(UdpSocket { inner: sock }) } - pub fn socket(&self) -> &Socket { &self.inner } + pub const fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 19ce932aa1233..5f6747a1224ae 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -85,13 +85,13 @@ impl CodePoint { /// /// Since all Unicode scalar values are code points, this always succeeds. #[inline] - pub fn from_char(value: char) -> CodePoint { + pub const fn from_char(value: char) -> CodePoint { CodePoint { value: value as u32 } } /// Returns the numeric value of the code point. #[inline] - pub fn to_u32(&self) -> u32 { + pub const fn to_u32(&self) -> u32 { self.value } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index a57b8dc723767..3a3d2450014c1 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -286,7 +286,7 @@ impl Builder { /// handler.join().unwrap(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new() -> Builder { + pub const fn new() -> Builder { Builder { name: None, stack_size: None, @@ -1391,7 +1391,7 @@ impl JoinHandle { /// println!("thread id: {:?}", thread.id()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn thread(&self) -> &Thread { + pub const fn thread(&self) -> &Thread { &self.0.thread } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 90ab349159915..a9344941f4218 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -449,7 +449,7 @@ impl SystemTimeError { /// } /// ``` #[stable(feature = "time2", since = "1.8.0")] - pub fn duration(&self) -> Duration { + pub const fn duration(&self) -> Duration { self.0 } } From 88da279e45bf3bb245f5408ce45578e72818d30e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 04:59:13 +0200 Subject: [PATCH 05/13] --bless mod-static-with-const-fn.stderr --- .../consts/const-eval/mod-static-with-const-fn.stderr | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr index 8eaed1dcab116..23bd30b641225 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr @@ -1,9 +1,3 @@ -error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/mod-static-with-const-fn.rs:27:6 - | -LL | *FOO.0.get() = 5; - | ^^^^^^^^^^^ - error[E0658]: statements in statics are unstable (see issue #48821) --> $DIR/mod-static-with-const-fn.rs:27:5 | @@ -12,7 +6,6 @@ LL | *FOO.0.get() = 5; | = help: add #![feature(const_let)] to the crate attributes to enable -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors occurred: E0015, E0658. -For more information about an error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0658`. From 53fe6294170e5f872877e87c1b05795b2b4d11d1 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 05:11:31 +0200 Subject: [PATCH 06/13] fix mod-static-with-const-fn.rs. --- src/test/ui/consts/const-eval/mod-static-with-const-fn.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs b/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs index d6ffca09e96d8..b6e6021aeda6d 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs @@ -25,11 +25,9 @@ static FOO: Foo = Foo(UnsafeCell::new(42)); static BAR: () = unsafe { *FOO.0.get() = 5; - //~^ ERROR calls in statics are limited to constant functions, tuple structs and tuple variants - + //~^ ERROR statements in statics are unstable (see issue #48821) // This error is caused by a separate bug that the feature gate error is reported // even though the feature gate "const_let" is active. - //~| statements in statics are unstable (see issue #48821) }; fn main() { From d1d2aa22c0d15465af1daccdb3821450c98d0ed0 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 18:06:11 +0200 Subject: [PATCH 07/13] reduce list to functions callable in const ctx. --- src/liballoc/collections/btree/map.rs | 4 ++-- src/liballoc/collections/btree/set.rs | 4 ++-- src/liballoc/collections/vec_deque.rs | 2 +- src/liballoc/string.rs | 6 +++--- src/liballoc/vec.rs | 4 ++-- src/libcore/alloc.rs | 2 +- src/libcore/char/decode.rs | 2 +- src/libcore/fmt/mod.rs | 18 +++++++++--------- src/libcore/panic.rs | 14 +++++++------- src/libcore/pin.rs | 4 ++-- src/libcore/slice/mod.rs | 4 ++-- src/libcore/str/lossy.rs | 2 +- src/libcore/str/mod.rs | 2 +- src/libcore/task/wake.rs | 2 +- src/libstd/collections/hash/map.rs | 2 +- src/libstd/ffi/c_str.rs | 4 ++-- src/libstd/io/buffered.rs | 2 +- src/libstd/io/mod.rs | 6 +++--- src/libstd/net/addr.rs | 4 ++-- src/libstd/net/ip.rs | 2 +- src/libstd/path.rs | 8 ++++---- src/libstd/sync/condvar.rs | 2 +- src/libstd/sync/mpsc/mod.rs | 4 ++-- src/libstd/sync/once.rs | 2 +- src/libstd/thread/mod.rs | 2 +- src/libstd/time.rs | 2 +- 26 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 8a721a50b4689..24c8fd3a969ca 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -2074,7 +2074,7 @@ impl BTreeMap { /// assert_eq!(a.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn len(&self) -> usize { + pub fn len(&self) -> usize { self.length } @@ -2093,7 +2093,7 @@ impl BTreeMap { /// assert!(!a.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } } diff --git a/src/liballoc/collections/btree/set.rs b/src/liballoc/collections/btree/set.rs index 6a0ecfd3f5815..af9a7074e4a4f 100644 --- a/src/liballoc/collections/btree/set.rs +++ b/src/liballoc/collections/btree/set.rs @@ -730,7 +730,7 @@ impl BTreeSet { /// assert_eq!(v.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn len(&self) -> usize { + pub fn len(&self) -> usize { self.map.len() } @@ -747,7 +747,7 @@ impl BTreeSet { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } } diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index b139b440fe160..e0ae7561d4553 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -933,7 +933,7 @@ impl VecDeque { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.tail == self.head } diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 8f379c4cfb459..5c776292f53d7 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1374,7 +1374,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn len(&self) -> usize { + pub fn len(&self) -> usize { self.vec.len() } @@ -1395,7 +1395,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } @@ -1662,7 +1662,7 @@ impl FromUtf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn utf8_error(&self) -> Utf8Error { + pub fn utf8_error(&self) -> Utf8Error { self.error } } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 78e9da2084dbe..f7a0bbdceafc9 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1165,7 +1165,7 @@ impl Vec { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn len(&self) -> usize { + pub fn len(&self) -> usize { self.len } @@ -1181,7 +1181,7 @@ impl Vec { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 8b9f7f2c81651..045fabca2688e 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -116,7 +116,7 @@ impl Layout { /// The minimum size in bytes for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] #[inline] - pub const fn size(&self) -> usize { self.size_ } + pub fn size(&self) -> usize { self.size_ } /// The minimum byte alignment for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] diff --git a/src/libcore/char/decode.rs b/src/libcore/char/decode.rs index bcd1e92c6d86e..cc52f048b891b 100644 --- a/src/libcore/char/decode.rs +++ b/src/libcore/char/decode.rs @@ -130,7 +130,7 @@ impl> Iterator for DecodeUtf16 { impl DecodeUtf16Error { /// Returns the unpaired surrogate which caused this error. #[stable(feature = "decode_utf16", since = "1.9.0")] - pub const fn unpaired_surrogate(&self) -> u16 { + pub fn unpaired_surrogate(&self) -> u16 { self.code } } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 56576f8334b85..4fde4e79ee20d 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -341,7 +341,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] - pub const fn new_v1(pieces: &'a [&'a str], + pub fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { Arguments { pieces, @@ -359,7 +359,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] - pub const fn new_v1_formatted(pieces: &'a [&'a str], + pub fn new_v1_formatted(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>], fmt: &'a [rt::v1::Argument]) -> Arguments<'a> { Arguments { @@ -1492,7 +1492,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{:t>6}", Foo), "tttttt"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn fill(&self) -> char { self.fill } + pub fn fill(&self) -> char { self.fill } /// Flag indicating what form of alignment was requested. /// @@ -1562,7 +1562,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn width(&self) -> Option { self.width } + pub fn width(&self) -> Option { self.width } /// Optionally specified precision for numeric types. /// @@ -1589,7 +1589,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn precision(&self) -> Option { self.precision } + pub fn precision(&self) -> Option { self.precision } /// Determines if the `+` flag was specified. /// @@ -1617,7 +1617,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn sign_plus(&self) -> bool { + pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 } @@ -1645,7 +1645,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn sign_minus(&self) -> bool { + pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 } @@ -1672,7 +1672,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn alternate(&self) -> bool { + pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 } @@ -1697,7 +1697,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{:04}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub const fn sign_aware_zero_pad(&self) -> bool { + pub fn sign_aware_zero_pad(&self) -> bool { self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0 } diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index af9d1596938e0..f0efeb59e8d6e 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -55,7 +55,7 @@ impl<'a> PanicInfo<'a> { issue = "0")] #[doc(hidden)] #[inline] - pub const fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, + pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, location: Location<'a>) -> Self { struct NoPayload; @@ -96,7 +96,7 @@ impl<'a> PanicInfo<'a> { /// /// [`fmt::write`]: ../fmt/fn.write.html #[unstable(feature = "panic_info_message", issue = "44489")] - pub const fn message(&self) -> Option<&fmt::Arguments> { + pub fn message(&self) -> Option<&fmt::Arguments> { self.message } @@ -125,7 +125,7 @@ impl<'a> PanicInfo<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub const fn location(&self) -> Option<&Location> { + pub fn location(&self) -> Option<&Location> { // NOTE: If this is changed to sometimes return None, // deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt. Some(&self.location) @@ -186,7 +186,7 @@ impl<'a> Location<'a> { and related macros", issue = "0")] #[doc(hidden)] - pub const fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { + pub fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { Location { file, line, col } } @@ -208,7 +208,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub const fn file(&self) -> &str { + pub fn file(&self) -> &str { self.file } @@ -230,7 +230,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub const fn line(&self) -> u32 { + pub fn line(&self) -> u32 { self.line } @@ -252,7 +252,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_col", since = "1.25.0")] - pub const fn column(&self) -> u32 { + pub fn column(&self) -> u32 { self.col } } diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index 63a433a8b2301..68de82d294529 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -207,7 +207,7 @@ impl<'a, T: ?Sized> Pin<&'a T> { /// with the same lifetime as the original `Pin`. #[unstable(feature = "pin", issue = "49150")] #[inline(always)] - pub const fn get_ref(this: Pin<&'a T>) -> &'a T { + pub fn get_ref(this: Pin<&'a T>) -> &'a T { this.pointer } } @@ -216,7 +216,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> { /// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime. #[unstable(feature = "pin", issue = "49150")] #[inline(always)] - pub const fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> { + pub fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> { Pin { pointer: this.pointer } } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index f8dee5370621d..dae425da78916 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -4021,7 +4021,7 @@ impl<'a, T> ChunksExact<'a, T> { /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. #[stable(feature = "chunks_exact", since = "1.31.0")] - pub const fn remainder(&self) -> &'a [T] { + pub fn remainder(&self) -> &'a [T] { self.rem } } @@ -4517,7 +4517,7 @@ impl<'a, T> RChunksExact<'a, T> { /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. #[stable(feature = "rchunks", since = "1.31.0")] - pub const fn remainder(&self) -> &'a [T] { + pub fn remainder(&self) -> &'a [T] { self.rem } } diff --git a/src/libcore/str/lossy.rs b/src/libcore/str/lossy.rs index 950552fc6b172..186d6adbc91cf 100644 --- a/src/libcore/str/lossy.rs +++ b/src/libcore/str/lossy.rs @@ -29,7 +29,7 @@ impl Utf8Lossy { unsafe { mem::transmute(bytes) } } - pub const fn chunks(&self) -> Utf8LossyChunksIter { + pub fn chunks(&self) -> Utf8LossyChunksIter { Utf8LossyChunksIter { source: &self.bytes } } } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index d73e5db727c91..f5bfe80489959 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -231,7 +231,7 @@ impl Utf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "utf8_error", since = "1.5.0")] - pub const fn valid_up_to(&self) -> usize { self.valid_up_to } + pub fn valid_up_to(&self) -> usize { self.valid_up_to } /// Provide more information about the failure: /// diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index 1db3a290e046f..c9fb22e0080dd 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -141,7 +141,7 @@ impl LocalWaker { /// `Waker` is nearly identical to `LocalWaker`, but is threadsafe /// (implements `Send` and `Sync`). #[inline] - pub const fn as_waker(&self) -> &Waker { + pub fn as_waker(&self) -> &Waker { &self.0 } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index b95449d11eac3..c18f200872d74 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -3013,7 +3013,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> { /// assert_eq!(map.entry("poneyland").key(), &"poneyland"); /// ``` #[stable(feature = "map_entry_keys", since = "1.10.0")] - pub const fn key(&self) -> &K { + pub fn key(&self) -> &K { &self.key } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index feff65bff3f2a..e2dc02e40bfcb 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -833,7 +833,7 @@ impl NulError { /// assert_eq!(nul_error.nul_position(), 7); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn nul_position(&self) -> usize { self.0 } + pub fn nul_position(&self) -> usize { self.0 } /// Consumes this error, returning the underlying vector of bytes which /// generated the error in the first place. @@ -909,7 +909,7 @@ impl IntoStringError { /// Access the underlying UTF-8 error that was the cause of this error. #[stable(feature = "cstring_into", since = "1.7.0")] - pub const fn utf8_error(&self) -> Utf8Error { + pub fn utf8_error(&self) -> Utf8Error { self.error } } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index bde9c57c57cc5..e26e6d391f84d 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -633,7 +633,7 @@ impl IntoInnerError { /// }; /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn error(&self) -> &Error { &self.1 } + pub fn error(&self) -> &Error { &self.1 } /// Returns the buffered writer instance which generated the error. /// diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 4c3117260feeb..c07d4a2e7554e 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1653,7 +1653,7 @@ impl Chain { /// } /// ``` #[stable(feature = "more_io_inner_methods", since = "1.20.0")] - pub const fn get_ref(&self) -> (&T, &U) { + pub fn get_ref(&self) -> (&T, &U) { (&self.first, &self.second) } @@ -1780,7 +1780,7 @@ impl Take { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn limit(&self) -> u64 { self.limit } + pub fn limit(&self) -> u64 { self.limit } /// Sets the number of bytes that can be read before this instance will /// return EOF. This is the same as constructing a new `Take` instance, so @@ -1856,7 +1856,7 @@ impl Take { /// } /// ``` #[stable(feature = "more_io_inner_methods", since = "1.20.0")] - pub const fn get_ref(&self) -> &T { + pub fn get_ref(&self) -> &T { &self.inner } diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index fc2e810478263..ff35325ab4fda 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -475,7 +475,7 @@ impl SocketAddrV6 { /// assert_eq!(socket.flowinfo(), 10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn flowinfo(&self) -> u32 { + pub fn flowinfo(&self) -> u32 { self.inner.sin6_flowinfo } @@ -515,7 +515,7 @@ impl SocketAddrV6 { /// assert_eq!(socket.scope_id(), 78); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn scope_id(&self) -> u32 { + pub fn scope_id(&self) -> u32 { self.inner.sin6_scope_id } diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index c5106c9abb9b4..2517c45696a2d 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -402,7 +402,7 @@ impl Ipv4Addr { /// assert_eq!(addr.octets(), [127, 0, 0, 1]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn octets(&self) -> [u8; 4] { + pub fn octets(&self) -> [u8; 4] { let bits = u32::from_be(self.inner.s_addr); [(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8] } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 71f39ff85e71a..a153456370c6f 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -439,7 +439,7 @@ impl<'a> PrefixComponent<'a> { /// /// [`Prefix`]: enum.Prefix.html #[stable(feature = "rust1", since = "1.0.0")] - pub const fn kind(&self) -> Prefix<'a> { + pub fn kind(&self) -> Prefix<'a> { self.parsed } @@ -447,7 +447,7 @@ impl<'a> PrefixComponent<'a> { /// /// [`OsStr`]: ../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] - pub const fn as_os_str(&self) -> &'a OsStr { + pub fn as_os_str(&self) -> &'a OsStr { self.raw } } @@ -1918,7 +1918,7 @@ impl Path { /// [`None`]: ../../std/option/enum.Option.html#variant.None /// [`parent`]: struct.Path.html#method.parent #[stable(feature = "path_ancestors", since = "1.28.0")] - pub const fn ancestors(&self) -> Ancestors { + pub fn ancestors(&self) -> Ancestors { Ancestors { next: Some(&self), } @@ -2267,7 +2267,7 @@ impl Path { /// println!("{}", path.display()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn display(&self) -> Display { + pub fn display(&self) -> Display { Display { path: self } } diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 1c6cc9cb361e5..3014283da5b27 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -72,7 +72,7 @@ impl WaitTimeoutResult { /// } /// ``` #[stable(feature = "wait_timeout", since = "1.5.0")] - pub const fn timed_out(&self) -> bool { + pub fn timed_out(&self) -> bool { self.0 } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 2a2e5c030b32f..b726168c7c616 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1469,7 +1469,7 @@ impl Receiver { /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter { Iter { rx: self } } @@ -1512,7 +1512,7 @@ impl Receiver { /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "receiver_try_iter", since = "1.15.0")] - pub const fn try_iter(&self) -> TryIter { + pub fn try_iter(&self) -> TryIter { TryIter { rx: self } } diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 4dd37ec387884..cf9698cb2a971 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -517,7 +517,7 @@ impl OnceState { /// assert!(!state.poisoned()); /// }); #[unstable(feature = "once_poison", issue = "33577")] - pub const fn poisoned(&self) -> bool { + pub fn poisoned(&self) -> bool { self.poisoned } } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 3a3d2450014c1..e9a97f7c74746 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1391,7 +1391,7 @@ impl JoinHandle { /// println!("thread id: {:?}", thread.id()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn thread(&self) -> &Thread { + pub fn thread(&self) -> &Thread { &self.0.thread } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index a9344941f4218..90ab349159915 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -449,7 +449,7 @@ impl SystemTimeError { /// } /// ``` #[stable(feature = "time2", since = "1.8.0")] - pub const fn duration(&self) -> Duration { + pub fn duration(&self) -> Duration { self.0 } } From e15c62d61fa02fac93992db9297aa4a8a56cef93 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 23 Oct 2018 23:09:44 +0200 Subject: [PATCH 08/13] revert making internal APIs const fn. --- src/liballoc/collections/binary_heap.rs | 2 +- src/liballoc/collections/btree/node.rs | 2 +- src/liballoc/collections/linked_list.rs | 2 +- src/liballoc/collections/vec_deque.rs | 2 +- src/liballoc/raw_vec.rs | 4 ++-- src/libcore/alloc.rs | 2 +- src/libcore/array.rs | 2 +- src/libcore/benches/iter.rs | 2 +- src/libcore/cell.rs | 4 ++-- src/libcore/fmt/mod.rs | 4 ++-- src/libcore/iter/mod.rs | 2 +- src/libcore/num/dec2flt/mod.rs | 4 ++-- src/libcore/num/dec2flt/parse.rs | 2 +- src/libcore/num/dec2flt/rawfp.rs | 2 +- src/libcore/num/flt2dec/estimator.rs | 2 +- src/libcore/ptr.rs | 2 +- src/libcore/slice/memchr.rs | 6 +++--- src/libcore/slice/mod.rs | 2 +- src/libcore/str/mod.rs | 8 ++++---- src/libcore/unicode/bool_trie.rs | 2 +- src/libstd/collections/hash/map.rs | 4 ++-- src/libstd/collections/hash/table.rs | 12 ++++++------ src/libstd/ffi/c_str.rs | 4 ++-- src/libstd/sync/mpsc/mod.rs | 2 +- src/libstd/sync/mpsc/oneshot.rs | 2 +- src/libstd/sys_common/mutex.rs | 2 +- src/libstd/sys_common/net.rs | 6 +++--- src/libstd/sys_common/wtf8.rs | 4 ++-- 28 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index e7e741dea4ce3..fcadcb544c431 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -884,7 +884,7 @@ impl<'a, T> Hole<'a, T> { } #[inline] - const fn pos(&self) -> usize { + fn pos(&self) -> usize { self.pos } diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 10665b8e46334..deca9591fbd5c 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -357,7 +357,7 @@ impl NodeRef { /// Returns the height of this node in the whole tree. Zero height denotes the /// leaf level. - pub const fn height(&self) -> usize { + pub fn height(&self) -> usize { self.height } diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 9b2975b81a3c7..3d66b9f54daac 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -135,7 +135,7 @@ impl fmt::Debug for IntoIter { } impl Node { - const fn new(element: T) -> Self { + fn new(element: T) -> Self { Node { next: None, prev: None, diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index e0ae7561d4553..88e76033f273e 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -1275,7 +1275,7 @@ impl VecDeque { } #[inline] - const fn is_contiguous(&self) -> bool { + fn is_contiguous(&self) -> bool { self.tail <= self.head } diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 0b6f400a40303..837770feecef5 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -204,7 +204,7 @@ impl RawVec { /// Gets a raw pointer to the start of the allocation. Note that this is /// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must /// be careful. - pub const fn ptr(&self) -> *mut T { + pub fn ptr(&self) -> *mut T { self.ptr.as_ptr() } @@ -221,7 +221,7 @@ impl RawVec { } /// Returns a shared reference to the allocator backing this RawVec. - pub const fn alloc(&self) -> &A { + pub fn alloc(&self) -> &A { &self.a } diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 045fabca2688e..113a85abecbef 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -25,7 +25,7 @@ use num::NonZeroUsize; #[derive(Debug)] pub struct Excess(pub NonNull, pub usize); -const fn size_align() -> (usize, usize) { +fn size_align() -> (usize, usize) { (mem::size_of::(), mem::align_of::()) } diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 0bea541e16349..3d24f8902bd83 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -77,7 +77,7 @@ impl TryFromSliceError { issue = "0")] #[inline] #[doc(hidden)] - pub const fn __description(&self) -> &str { + pub fn __description(&self) -> &str { "could not convert slice to array" } } diff --git a/src/libcore/benches/iter.rs b/src/libcore/benches/iter.rs index c8b8c2eff97b1..6c597301ac204 100644 --- a/src/libcore/benches/iter.rs +++ b/src/libcore/benches/iter.rs @@ -39,7 +39,7 @@ fn bench_multiple_take(b: &mut Bencher) { }); } -const fn scatter(x: i32) -> i32 { (x * 31) % 127 } +fn scatter(x: i32) -> i32 { (x * 31) % 127 } #[bench] fn bench_max_by_key(b: &mut Bencher) { diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 3fe77fe688fa8..9cf42eff219ba 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -636,12 +636,12 @@ type BorrowFlag = isize; const UNUSED: BorrowFlag = 0; #[inline(always)] -const fn is_writing(x: BorrowFlag) -> bool { +fn is_writing(x: BorrowFlag) -> bool { x < UNUSED } #[inline(always)] -const fn is_reading(x: BorrowFlag) -> bool { +fn is_reading(x: BorrowFlag) -> bool { x > UNUSED } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 4fde4e79ee20d..284617a416751 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1703,11 +1703,11 @@ impl<'a> Formatter<'a> { // FIXME: Decide what public API we want for these two flags. // https://github.com/rust-lang/rust/issues/48584 - const fn debug_lower_hex(&self) -> bool { + fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 } - const fn debug_upper_hex(&self) -> bool { + fn debug_upper_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 } diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 72a032b57d09f..c42fb7019c771 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -2658,7 +2658,7 @@ impl FusedIterator for Flatten I::Item: IntoIterator {} /// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`. -const fn flatten_compat(iter: I) -> FlattenCompat { +fn flatten_compat(iter: I) -> FlattenCompat { FlattenCompat { iter, frontiter: None, backiter: None } } diff --git a/src/libcore/num/dec2flt/mod.rs b/src/libcore/num/dec2flt/mod.rs index 0e1f6664d9656..f93564c2849f5 100644 --- a/src/libcore/num/dec2flt/mod.rs +++ b/src/libcore/num/dec2flt/mod.rs @@ -187,11 +187,11 @@ impl fmt::Display for ParseFloatError { } } -const fn pfe_empty() -> ParseFloatError { +fn pfe_empty() -> ParseFloatError { ParseFloatError { kind: FloatErrorKind::Empty } } -const fn pfe_invalid() -> ParseFloatError { +fn pfe_invalid() -> ParseFloatError { ParseFloatError { kind: FloatErrorKind::Invalid } } diff --git a/src/libcore/num/dec2flt/parse.rs b/src/libcore/num/dec2flt/parse.rs index 8d8f357425ef0..e7ed94d4d91c2 100644 --- a/src/libcore/num/dec2flt/parse.rs +++ b/src/libcore/num/dec2flt/parse.rs @@ -39,7 +39,7 @@ pub struct Decimal<'a> { } impl<'a> Decimal<'a> { - pub const fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> { + pub fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> { Decimal { integral, fractional, exp } } } diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index c5d4aa689583c..38f4e4687a99b 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -44,7 +44,7 @@ pub struct Unpacked { } impl Unpacked { - pub const fn new(sig: u64, k: i16) -> Self { + pub fn new(sig: u64, k: i16) -> Self { Unpacked { sig, k } } } diff --git a/src/libcore/num/flt2dec/estimator.rs b/src/libcore/num/flt2dec/estimator.rs index 2a87bf436646d..4e33fcfd76e61 100644 --- a/src/libcore/num/flt2dec/estimator.rs +++ b/src/libcore/num/flt2dec/estimator.rs @@ -15,7 +15,7 @@ /// This is used to approximate `k = ceil(log_10 (mant * 2^exp))`; /// the true `k` is either `k_0` or `k_0+1`. #[doc(hidden)] -pub const fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { +pub fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { // 2^(nbits-1) < mant <= 2^nbits if mant > 0 let nbits = 64 - (mant - 1).leading_zeros() as i64; // 1292913986 = floor(2^32 * log_10 2) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index c06e580e30eb5..b795cd7215008 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2759,7 +2759,7 @@ impl Unique { } /// Acquires the underlying `*mut` pointer. - pub const fn as_ptr(self) -> *mut T { + pub fn as_ptr(self) -> *mut T { self.pointer.0 as *mut T } diff --git a/src/libcore/slice/memchr.rs b/src/libcore/slice/memchr.rs index deaeb53e84a3a..cf95333af9cbb 100644 --- a/src/libcore/slice/memchr.rs +++ b/src/libcore/slice/memchr.rs @@ -29,19 +29,19 @@ const HI_USIZE: usize = HI_U64 as usize; /// bytes where the borrow propagated all the way to the most significant /// bit." #[inline] -const fn contains_zero_byte(x: usize) -> bool { +fn contains_zero_byte(x: usize) -> bool { x.wrapping_sub(LO_USIZE) & !x & HI_USIZE != 0 } #[cfg(target_pointer_width = "16")] #[inline] -const fn repeat_byte(b: u8) -> usize { +fn repeat_byte(b: u8) -> usize { (b as usize) << 8 | b as usize } #[cfg(not(target_pointer_width = "16"))] #[inline] -const fn repeat_byte(b: u8) -> usize { +fn repeat_byte(b: u8) -> usize { (b as usize) * (::usize::MAX / 255) } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index dae425da78916..fece328f51f47 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -2737,7 +2737,7 @@ impl<'a, T> IntoIterator for &'a mut [T] { // Macro helper functions #[inline(always)] -const fn size_from_ptr(_: *const T) -> usize { +fn size_from_ptr(_: *const T) -> usize { mem::size_of::() } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f5bfe80489959..e710cbffe4d35 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -476,16 +476,16 @@ pub struct Chars<'a> { /// The first byte is special, only want bottom 5 bits for width 2, 4 bits /// for width 3, and 3 bits for width 4. #[inline] -const fn utf8_first_byte(byte: u8, width: u32) -> u32 { (byte & (0x7F >> width)) as u32 } +fn utf8_first_byte(byte: u8, width: u32) -> u32 { (byte & (0x7F >> width)) as u32 } /// Returns the value of `ch` updated with continuation byte `byte`. #[inline] -const fn utf8_acc_cont_byte(ch: u32, byte: u8) -> u32 { (ch << 6) | (byte & CONT_MASK) as u32 } +fn utf8_acc_cont_byte(ch: u32, byte: u8) -> u32 { (ch << 6) | (byte & CONT_MASK) as u32 } /// Checks whether the byte is a UTF-8 continuation byte (i.e. starts with the /// bits `10`). #[inline] -const fn utf8_is_cont_byte(byte: u8) -> bool { (byte & !CONT_MASK) == TAG_CONT_U8 } +fn utf8_is_cont_byte(byte: u8) -> bool { (byte & !CONT_MASK) == TAG_CONT_U8 } #[inline] fn unwrap_or_0(opt: Option<&u8>) -> u8 { @@ -1420,7 +1420,7 @@ const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; /// Returns `true` if any byte in the word `x` is nonascii (>= 128). #[inline] -const fn contains_nonascii(x: usize) -> bool { +fn contains_nonascii(x: usize) -> bool { (x & NONASCII_MASK) != 0 } diff --git a/src/libcore/unicode/bool_trie.rs b/src/libcore/unicode/bool_trie.rs index 995795839b7d8..0e6437fded594 100644 --- a/src/libcore/unicode/bool_trie.rs +++ b/src/libcore/unicode/bool_trie.rs @@ -71,6 +71,6 @@ impl SmallBoolTrie { } } -const fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool { +fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool { ((bitmap_chunk >> (c & 63)) & 1) != 0 } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index c18f200872d74..8de415e8aed5c 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -36,7 +36,7 @@ struct DefaultResizePolicy; impl DefaultResizePolicy { #[inline] - const fn new() -> DefaultResizePolicy { + fn new() -> DefaultResizePolicy { DefaultResizePolicy } @@ -69,7 +69,7 @@ impl DefaultResizePolicy { /// The capacity of the given raw capacity. #[inline] - const fn capacity(&self, raw_cap: usize) -> usize { + fn capacity(&self, raw_cap: usize) -> usize { // This doesn't have to be checked for overflow since allocation size // in bytes will overflow earlier than multiplication by 10. // diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 0df20395b012b..547f97cc8acee 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -247,7 +247,7 @@ impl RawBucket { // Buckets hold references to the table. impl FullBucket { /// Borrow a reference to the table. - pub const fn table(&self) -> &M { + pub fn table(&self) -> &M { &self.table } /// Borrow a mutable reference to the table. @@ -259,18 +259,18 @@ impl FullBucket { self.table } /// Get the raw index. - pub const fn index(&self) -> usize { + pub fn index(&self) -> usize { self.raw.idx } /// Get the raw bucket. - pub const fn raw(&self) -> RawBucket { + pub fn raw(&self) -> RawBucket { self.raw } } impl EmptyBucket { /// Borrow a reference to the table. - pub const fn table(&self) -> &M { + pub fn table(&self) -> &M { &self.table } /// Borrow a mutable reference to the table. @@ -281,7 +281,7 @@ impl EmptyBucket { impl Bucket { /// Get the raw index. - pub const fn index(&self) -> usize { + pub fn index(&self) -> usize { self.raw.idx } /// get the table. @@ -772,7 +772,7 @@ impl RawTable { /// The number of elements ever `put` in the hashtable, minus the number /// of elements ever `take`n. - pub const fn size(&self) -> usize { + pub fn size(&self) -> usize { self.size } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index e2dc02e40bfcb..cb91453998540 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -265,12 +265,12 @@ enum FromBytesWithNulErrorKind { } impl FromBytesWithNulError { - const fn interior_nul(pos: usize) -> FromBytesWithNulError { + fn interior_nul(pos: usize) -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::InteriorNul(pos), } } - const fn not_nul_terminated() -> FromBytesWithNulError { + fn not_nul_terminated() -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::NotNulTerminated, } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index b726168c7c616..059ced4f56efd 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -785,7 +785,7 @@ pub fn sync_channel(bound: usize) -> (SyncSender, Receiver) { //////////////////////////////////////////////////////////////////////////////// impl Sender { - const fn new(inner: Flavor) -> Sender { + fn new(inner: Flavor) -> Sender { Sender { inner: UnsafeCell::new(inner), } diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index 273644cb902db..b8e50c9297b64 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -89,7 +89,7 @@ enum MyUpgrade { } impl Packet { - pub const fn new() -> Packet { + pub fn new() -> Packet { Packet { data: UnsafeCell::new(None), upgrade: UnsafeCell::new(NothingSent), diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs index dc9edb306de0d..c6d531c7a1ac5 100644 --- a/src/libstd/sys_common/mutex.rs +++ b/src/libstd/sys_common/mutex.rs @@ -80,7 +80,7 @@ impl Mutex { } // not meant to be exported to the outside world, just the containing module -pub const fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } +pub fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } #[must_use] /// A simple RAII utility for the above Mutex without the poisoning semantics. diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index f58c26ef4280a..d09a233ed896f 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -199,7 +199,7 @@ impl TcpStream { Ok(TcpStream { inner: sock }) } - pub const fn socket(&self) -> &Socket { &self.inner } + pub fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -339,7 +339,7 @@ impl TcpListener { Ok(TcpListener { inner: sock }) } - pub const fn socket(&self) -> &Socket { &self.inner } + pub fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -427,7 +427,7 @@ impl UdpSocket { Ok(UdpSocket { inner: sock }) } - pub const fn socket(&self) -> &Socket { &self.inner } + pub fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 5f6747a1224ae..19ce932aa1233 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -85,13 +85,13 @@ impl CodePoint { /// /// Since all Unicode scalar values are code points, this always succeeds. #[inline] - pub const fn from_char(value: char) -> CodePoint { + pub fn from_char(value: char) -> CodePoint { CodePoint { value: value as u32 } } /// Returns the numeric value of the code point. #[inline] - pub const fn to_u32(&self) -> u32 { + pub fn to_u32(&self) -> u32 { self.value } From 38a90406d3b0a8aec72cb62f794ceddb026c86b6 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 25 Oct 2018 19:37:52 +0200 Subject: [PATCH 09/13] revert some more constification. --- src/liballoc/collections/linked_list.rs | 8 ++++---- src/libcore/mem.rs | 2 +- src/libstd/io/cursor.rs | 6 +++--- src/libstd/io/mod.rs | 4 ++-- src/libstd/io/util.rs | 4 ++-- src/libstd/process.rs | 6 +++--- src/libstd/thread/mod.rs | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 3d66b9f54daac..4b1cbb0d90895 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -264,7 +264,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn new() -> Self { + pub fn new() -> Self { LinkedList { head: None, tail: None, @@ -341,7 +341,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter { Iter { head: self.head, tail: self.tail, @@ -401,7 +401,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } @@ -427,7 +427,7 @@ impl LinkedList { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub const fn len(&self) -> usize { + pub fn len(&self) -> usize { self.len } diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 0aa374c7a6446..b89f37fa5ce25 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -139,7 +139,7 @@ pub use intrinsics::transmute; /// [ub]: ../../reference/behavior-considered-undefined.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] -pub const fn forget(t: T) { +pub fn forget(t: T) { ManuallyDrop::new(t); } diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 05bee19c93f54..14f20151dca86 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -104,7 +104,7 @@ impl Cursor { /// # force_inference(&buff); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn new(inner: T) -> Cursor { + pub fn new(inner: T) -> Cursor { Cursor { pos: 0, inner: inner } } @@ -138,7 +138,7 @@ impl Cursor { /// let reference = buff.get_ref(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn get_ref(&self) -> &T { &self.inner } + pub fn get_ref(&self) -> &T { &self.inner } /// Gets a mutable reference to the underlying value in this cursor. /// @@ -179,7 +179,7 @@ impl Cursor { /// assert_eq!(buff.position(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn position(&self) -> u64 { self.pos } + pub fn position(&self) -> u64 { self.pos } /// Sets the position of this cursor. /// diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c07d4a2e7554e..e263db24fc2c8 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -885,7 +885,7 @@ impl Initializer { /// Returns a new `Initializer` which will zero out buffers. #[unstable(feature = "read_initializer", issue = "42788")] #[inline] - pub const fn zeroing() -> Initializer { + pub fn zeroing() -> Initializer { Initializer(true) } @@ -906,7 +906,7 @@ impl Initializer { /// Indicates if a buffer should be initialized. #[unstable(feature = "read_initializer", issue = "42788")] #[inline] - pub const fn should_initialize(&self) -> bool { + pub fn should_initialize(&self) -> bool { self.0 } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index d0db4cfc704be..12995d0868345 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -99,7 +99,7 @@ pub struct Empty { _priv: () } /// assert!(buffer.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub const fn empty() -> Empty { Empty { _priv: () } } +pub fn empty() -> Empty { Empty { _priv: () } } #[stable(feature = "rust1", since = "1.0.0")] impl Read for Empty { @@ -199,7 +199,7 @@ pub struct Sink { _priv: () } /// assert_eq!(num_bytes, 5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub const fn sink() -> Sink { Sink { _priv: () } } +pub fn sink() -> Sink { Sink { _priv: () } } #[stable(feature = "rust1", since = "1.0.0")] impl Write for Sink { diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d5047ef6ad728..a9219f75362db 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -926,7 +926,7 @@ impl Stdio { /// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n"); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub const fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } + pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } /// The child inherits from the corresponding parent descriptor. /// @@ -961,7 +961,7 @@ impl Stdio { /// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout)); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub const fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } + pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } /// This stream will be ignored. This is the equivalent of attaching the /// stream to `/dev/null` @@ -998,7 +998,7 @@ impl Stdio { /// // Ignores any piped-in input /// ``` #[stable(feature = "process", since = "1.0.0")] - pub const fn null() -> Stdio { Stdio(imp::Stdio::Null) } + pub fn null() -> Stdio { Stdio(imp::Stdio::Null) } } impl FromInner for Stdio { diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index e9a97f7c74746..a57b8dc723767 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -286,7 +286,7 @@ impl Builder { /// handler.join().unwrap(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub const fn new() -> Builder { + pub fn new() -> Builder { Builder { name: None, stack_size: None, From 56768235e18a8c02ace37489c4e033bde6118efb Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 25 Oct 2018 20:53:05 +0200 Subject: [PATCH 10/13] Add a few tests around raw pointers and interior mutability --- src/test/ui/consts/std/cell.rs | 30 ++++++++++++++++++++++++++++++ src/test/ui/consts/std/cell.stderr | 15 +++++++++++++++ src/test/ui/consts/std/char.rs | 9 +++++++++ src/test/ui/consts/std/iter.rs | 9 +++++++++ src/test/ui/consts/std/slice.rs | 10 ++++++++++ 5 files changed, 73 insertions(+) create mode 100644 src/test/ui/consts/std/cell.rs create mode 100644 src/test/ui/consts/std/cell.stderr create mode 100644 src/test/ui/consts/std/char.rs create mode 100644 src/test/ui/consts/std/iter.rs create mode 100644 src/test/ui/consts/std/slice.rs diff --git a/src/test/ui/consts/std/cell.rs b/src/test/ui/consts/std/cell.rs new file mode 100644 index 0000000000000..db0bcbe2c443e --- /dev/null +++ b/src/test/ui/consts/std/cell.rs @@ -0,0 +1,30 @@ +use std::cell::*; + +// not ok, because this would create a silent constant with interior mutability. +// the rules could be relaxed in the future +static FOO: Wrap<*mut u32> = Wrap(Cell::new(42).as_ptr()); +//~^ ERROR cannot borrow a constant which may contain interior mutability + +static FOO3: Wrap> = Wrap(Cell::new(42)); +// ok +static FOO4: Wrap<*mut u32> = Wrap(FOO3.0.as_ptr()); + +// not ok, because the `as_ptr` call takes a reference to a type with interior mutability +// which is not allowed in constants +const FOO2: *mut u32 = Cell::new(42).as_ptr(); +//~^ ERROR cannot borrow a constant which may contain interior mutability + +struct IMSafeTrustMe(UnsafeCell); +unsafe impl Send for IMSafeTrustMe {} +unsafe impl Sync for IMSafeTrustMe {} + +static BAR: IMSafeTrustMe = IMSafeTrustMe(UnsafeCell::new(5)); + + +struct Wrap(T); +unsafe impl Send for Wrap {} +unsafe impl Sync for Wrap {} + +static BAR_PTR: Wrap<*mut u32> = Wrap(BAR.0.get()); + +fn main() {} \ No newline at end of file diff --git a/src/test/ui/consts/std/cell.stderr b/src/test/ui/consts/std/cell.stderr new file mode 100644 index 0000000000000..f75aadff6d5ea --- /dev/null +++ b/src/test/ui/consts/std/cell.stderr @@ -0,0 +1,15 @@ +error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead + --> $DIR/cell.rs:5:35 + | +LL | static FOO: Wrap<*mut u32> = Wrap(Cell::new(42).as_ptr()); + | ^^^^^^^^^^^^^ + +error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead + --> $DIR/cell.rs:14:24 + | +LL | const FOO2: *mut u32 = Cell::new(42).as_ptr(); + | ^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0492`. diff --git a/src/test/ui/consts/std/char.rs b/src/test/ui/consts/std/char.rs new file mode 100644 index 0000000000000..ce43f66a30c26 --- /dev/null +++ b/src/test/ui/consts/std/char.rs @@ -0,0 +1,9 @@ +// run-pass + +static X: bool = 'a'.is_ascii(); +static Y: bool = 'ä'.is_ascii(); + +fn main() { + assert!(X); + assert!(!Y); +} \ No newline at end of file diff --git a/src/test/ui/consts/std/iter.rs b/src/test/ui/consts/std/iter.rs new file mode 100644 index 0000000000000..e36d5cccd5be8 --- /dev/null +++ b/src/test/ui/consts/std/iter.rs @@ -0,0 +1,9 @@ +// run-pass + +const I: std::iter::Empty = std::iter::empty(); + +fn main() { + for i in I { + panic!("magical value creation: {}", i); + } +} \ No newline at end of file diff --git a/src/test/ui/consts/std/slice.rs b/src/test/ui/consts/std/slice.rs new file mode 100644 index 0000000000000..7598a20fc28d4 --- /dev/null +++ b/src/test/ui/consts/std/slice.rs @@ -0,0 +1,10 @@ +// compile-pass + +struct Wrap(T); +unsafe impl Send for Wrap {} +unsafe impl Sync for Wrap {} + +static FOO: Wrap<*const u32> = Wrap([42, 44, 46].as_ptr()); +static BAR: Wrap<*const u8> = Wrap("hello".as_ptr()); + +fn main() {} \ No newline at end of file From c8e23d8c4c1409f3f348e6c485a3a689f5e10cca Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 25 Oct 2018 22:10:41 +0200 Subject: [PATCH 11/13] =?UTF-8?q?Tidy=20=E2=99=AA=20all=20=E2=99=AA=20the?= =?UTF-8?q?=20=E2=99=AA=20way=20=E2=99=AA=E2=99=AA=E2=99=AA=E2=99=AA=20wit?= =?UTF-8?q?h=20=E2=99=AA=20a=20=E2=99=AA=20newline=20=E2=99=AA=20missing?= =?UTF-8?q?=20=E2=99=AA=20cry=20=E2=99=AA=E2=99=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/ui/consts/std/cell.rs | 2 +- src/test/ui/consts/std/char.rs | 2 +- src/test/ui/consts/std/iter.rs | 2 +- src/test/ui/consts/std/slice.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/ui/consts/std/cell.rs b/src/test/ui/consts/std/cell.rs index db0bcbe2c443e..cf6c0f2379d1e 100644 --- a/src/test/ui/consts/std/cell.rs +++ b/src/test/ui/consts/std/cell.rs @@ -27,4 +27,4 @@ unsafe impl Sync for Wrap {} static BAR_PTR: Wrap<*mut u32> = Wrap(BAR.0.get()); -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/ui/consts/std/char.rs b/src/test/ui/consts/std/char.rs index ce43f66a30c26..fe79059a2e497 100644 --- a/src/test/ui/consts/std/char.rs +++ b/src/test/ui/consts/std/char.rs @@ -6,4 +6,4 @@ static Y: bool = 'ä'.is_ascii(); fn main() { assert!(X); assert!(!Y); -} \ No newline at end of file +} diff --git a/src/test/ui/consts/std/iter.rs b/src/test/ui/consts/std/iter.rs index e36d5cccd5be8..e9af781eb2b8d 100644 --- a/src/test/ui/consts/std/iter.rs +++ b/src/test/ui/consts/std/iter.rs @@ -6,4 +6,4 @@ fn main() { for i in I { panic!("magical value creation: {}", i); } -} \ No newline at end of file +} diff --git a/src/test/ui/consts/std/slice.rs b/src/test/ui/consts/std/slice.rs index 7598a20fc28d4..ad38105b6aa0e 100644 --- a/src/test/ui/consts/std/slice.rs +++ b/src/test/ui/consts/std/slice.rs @@ -7,4 +7,4 @@ unsafe impl Sync for Wrap {} static FOO: Wrap<*const u32> = Wrap([42, 44, 46].as_ptr()); static BAR: Wrap<*const u8> = Wrap("hello".as_ptr()); -fn main() {} \ No newline at end of file +fn main() {} From ea73edbc0fa8fb2ae2c5c4fc4d1f08cc64e150ce Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 10 Nov 2018 02:33:21 +0100 Subject: [PATCH 12/13] revert spurious edits. --- src/liballoc/collections/linked_list.rs | 2 +- src/libcore/fmt/mod.rs | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 4b1cbb0d90895..2ef84dbade0fb 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -402,7 +402,7 @@ impl LinkedList { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_empty(&self) -> bool { - self.len() == 0 + self.head.is_none() } /// Returns the length of the `LinkedList`. diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 284617a416751..75ec0d7d50be6 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1617,9 +1617,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_plus(&self) -> bool { - self.flags & (1 << FlagV1::SignPlus as u32) != 0 - } + pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 } /// Determines if the `-` flag was specified. /// @@ -1645,9 +1643,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_minus(&self) -> bool { - self.flags & (1 << FlagV1::SignMinus as u32) != 0 - } + pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 } /// Determines if the `#` flag was specified. /// @@ -1672,9 +1668,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn alternate(&self) -> bool { - self.flags & (1 << FlagV1::Alternate as u32) != 0 - } + pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 } /// Determines if the `0` flag was specified. /// @@ -1703,13 +1697,9 @@ impl<'a> Formatter<'a> { // FIXME: Decide what public API we want for these two flags. // https://github.com/rust-lang/rust/issues/48584 - fn debug_lower_hex(&self) -> bool { - self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 - } + fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 } - fn debug_upper_hex(&self) -> bool { - self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 - } + fn debug_upper_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 } /// Creates a [`DebugStruct`] builder designed to assist with creation of /// [`fmt::Debug`] implementations for structs. From ac1c6b0378789250a5070772ad18e936949c7a3c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 10 Nov 2018 02:36:19 +0100 Subject: [PATCH 13/13] adjust ui/../mod-static-with-const-fn.rs --- .../consts/const-eval/mod-static-with-const-fn.rs | 5 +++++ .../const-eval/mod-static-with-const-fn.stderr | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs b/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs index b6e6021aeda6d..4136a7b6a724f 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs @@ -23,11 +23,16 @@ unsafe impl Sync for Foo {} static FOO: Foo = Foo(UnsafeCell::new(42)); +fn foo() {} + static BAR: () = unsafe { *FOO.0.get() = 5; //~^ ERROR statements in statics are unstable (see issue #48821) // This error is caused by a separate bug that the feature gate error is reported // even though the feature gate "const_let" is active. + + foo(); + //~^ ERROR calls in statics are limited to constant functions, tuple structs and tuple variants }; fn main() { diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr index 23bd30b641225..c2bba27e4d1e2 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr @@ -1,11 +1,18 @@ error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/mod-static-with-const-fn.rs:27:5 + --> $DIR/mod-static-with-const-fn.rs:29:5 | LL | *FOO.0.get() = 5; | ^^^^^^^^^^^^^^^^ | = help: add #![feature(const_let)] to the crate attributes to enable -error: aborting due to previous error +error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants + --> $DIR/mod-static-with-const-fn.rs:34:5 + | +LL | foo(); + | ^^^^^ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors occurred: E0015, E0658. +For more information about an error, try `rustc --explain E0015`.