From a76274e533969c8458c4471fbfc1b84ba44137e0 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 11:25:05 -0700 Subject: [PATCH 01/10] Remove EnumSet [unstable, deprecated since 1.16.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/library-features/enumset.md | 7 - src/libcollections/enum_set.rs | 313 ------------------ src/libcollections/lib.rs | 4 - .../sync-send-iterators-in-libcollections.rs | 19 +- 5 files changed, 1 insertion(+), 343 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/enumset.md delete mode 100644 src/libcollections/enum_set.rs diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 3e0415439774c..b803b6556cfa1 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -130,7 +130,6 @@ - [derive_clone_copy](library-features/derive-clone-copy.md) - [derive_eq](library-features/derive-eq.md) - [discriminant_value](library-features/discriminant-value.md) - - [enumset](library-features/enumset.md) - [error_type_id](library-features/error-type-id.md) - [exact_size_is_empty](library-features/exact-size-is-empty.md) - [fd](library-features/fd.md) diff --git a/src/doc/unstable-book/src/library-features/enumset.md b/src/doc/unstable-book/src/library-features/enumset.md deleted file mode 100644 index 24c8d8fa7dbb9..0000000000000 --- a/src/doc/unstable-book/src/library-features/enumset.md +++ /dev/null @@ -1,7 +0,0 @@ -# `enumset` - -The tracking issue for this feature is: [#37966] - -[#37966]: https://github.com/rust-lang/rust/issues/37966 - ------------------------- diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs deleted file mode 100644 index aaee567bf1dbf..0000000000000 --- a/src/libcollections/enum_set.rs +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2012 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. - -//! A structure for holding a set of enum variants. -//! -//! This module defines a container which uses an efficient bit mask -//! representation to hold C-like enum variants. - -#![unstable(feature = "enumset", - reason = "matches collection reform specification, \ - waiting for dust to settle", - issue = "37966")] -#![rustc_deprecated(since = "1.16.0", reason = "long since replaced")] -#![allow(deprecated)] - -use core::marker; -use core::fmt; -use core::iter::{FromIterator, FusedIterator}; -use core::ops::{Sub, BitOr, BitAnd, BitXor}; - -// FIXME(contentions): implement union family of methods? (general design may be -// wrong here) - -/// A specialized set implementation to use enum types. -/// -/// It is a logic error for an item to be modified in such a way that the -/// transformation of the item to or from a `usize`, as determined by the -/// `CLike` trait, changes while the item is in the set. This is normally only -/// possible through `Cell`, `RefCell`, global state, I/O, or unsafe code. -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct EnumSet { - // We must maintain the invariant that no bits are set - // for which no variant exists - bits: usize, - marker: marker::PhantomData, -} - -impl Copy for EnumSet {} - -impl Clone for EnumSet { - fn clone(&self) -> EnumSet { - *self - } -} - -impl fmt::Debug for EnumSet { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_set().entries(self).finish() - } -} - -/// An interface for casting C-like enum to usize and back. -/// A typically implementation is as below. -/// -/// ```{rust,ignore} -/// #[repr(usize)] -/// enum Foo { -/// A, B, C -/// } -/// -/// impl CLike for Foo { -/// fn to_usize(&self) -> usize { -/// *self as usize -/// } -/// -/// fn from_usize(v: usize) -> Foo { -/// unsafe { mem::transmute(v) } -/// } -/// } -/// ``` -pub trait CLike { - /// Converts a C-like enum to a `usize`. - fn to_usize(&self) -> usize; - /// Converts a `usize` to a C-like enum. - fn from_usize(usize) -> Self; -} - -fn bit(e: &E) -> usize { - use core::mem; - let value = e.to_usize(); - let bits = mem::size_of::() * 8; - assert!(value < bits, - "EnumSet only supports up to {} variants.", - bits - 1); - 1 << value -} - -impl EnumSet { - /// Returns an empty `EnumSet`. - pub fn new() -> EnumSet { - EnumSet { - bits: 0, - marker: marker::PhantomData, - } - } - - /// Returns the number of elements in the given `EnumSet`. - pub fn len(&self) -> usize { - self.bits.count_ones() as usize - } - - /// Returns `true` if the `EnumSet` is empty. - pub fn is_empty(&self) -> bool { - self.bits == 0 - } - - pub fn clear(&mut self) { - self.bits = 0; - } - - /// Returns `false` if the `EnumSet` contains any enum of the given `EnumSet`. - pub fn is_disjoint(&self, other: &EnumSet) -> bool { - (self.bits & other.bits) == 0 - } - - /// Returns `true` if a given `EnumSet` is included in this `EnumSet`. - pub fn is_superset(&self, other: &EnumSet) -> bool { - (self.bits & other.bits) == other.bits - } - - /// Returns `true` if this `EnumSet` is included in the given `EnumSet`. - pub fn is_subset(&self, other: &EnumSet) -> bool { - other.is_superset(self) - } - - /// Returns the union of both `EnumSets`. - pub fn union(&self, e: EnumSet) -> EnumSet { - EnumSet { - bits: self.bits | e.bits, - marker: marker::PhantomData, - } - } - - /// Returns the intersection of both `EnumSets`. - pub fn intersection(&self, e: EnumSet) -> EnumSet { - EnumSet { - bits: self.bits & e.bits, - marker: marker::PhantomData, - } - } - - /// Adds an enum to the `EnumSet`, and returns `true` if it wasn't there before - pub fn insert(&mut self, e: E) -> bool { - let result = !self.contains(&e); - self.bits |= bit(&e); - result - } - - /// Removes an enum from the EnumSet - pub fn remove(&mut self, e: &E) -> bool { - let result = self.contains(e); - self.bits &= !bit(e); - result - } - - /// Returns `true` if an `EnumSet` contains a given enum. - pub fn contains(&self, e: &E) -> bool { - (self.bits & bit(e)) != 0 - } - - /// Returns an iterator over an `EnumSet`. - pub fn iter(&self) -> Iter { - Iter::new(self.bits) - } -} - -impl Sub for EnumSet { - type Output = EnumSet; - - fn sub(self, e: EnumSet) -> EnumSet { - EnumSet { - bits: self.bits & !e.bits, - marker: marker::PhantomData, - } - } -} - -impl BitOr for EnumSet { - type Output = EnumSet; - - fn bitor(self, e: EnumSet) -> EnumSet { - EnumSet { - bits: self.bits | e.bits, - marker: marker::PhantomData, - } - } -} - -impl BitAnd for EnumSet { - type Output = EnumSet; - - fn bitand(self, e: EnumSet) -> EnumSet { - EnumSet { - bits: self.bits & e.bits, - marker: marker::PhantomData, - } - } -} - -impl BitXor for EnumSet { - type Output = EnumSet; - - fn bitxor(self, e: EnumSet) -> EnumSet { - EnumSet { - bits: self.bits ^ e.bits, - marker: marker::PhantomData, - } - } -} - -/// An iterator over an `EnumSet` -pub struct Iter { - index: usize, - bits: usize, - marker: marker::PhantomData, -} - -impl fmt::Debug for Iter { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("Iter") - .field(&self.index) - .field(&self.bits) - .finish() - } -} - -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -impl Clone for Iter { - fn clone(&self) -> Iter { - Iter { - index: self.index, - bits: self.bits, - marker: marker::PhantomData, - } - } -} - -impl Iter { - fn new(bits: usize) -> Iter { - Iter { - index: 0, - bits: bits, - marker: marker::PhantomData, - } - } -} - -impl Iterator for Iter { - type Item = E; - - fn next(&mut self) -> Option { - if self.bits == 0 { - return None; - } - - while (self.bits & 1) == 0 { - self.index += 1; - self.bits >>= 1; - } - let elem = CLike::from_usize(self.index); - self.index += 1; - self.bits >>= 1; - Some(elem) - } - - fn size_hint(&self) -> (usize, Option) { - let exact = self.bits.count_ones() as usize; - (exact, Some(exact)) - } -} - -#[unstable(feature = "fused", issue = "35602")] -impl FusedIterator for Iter {} - -impl FromIterator for EnumSet { - fn from_iter>(iter: I) -> EnumSet { - let mut ret = EnumSet::new(); - ret.extend(iter); - ret - } -} - -impl<'a, E> IntoIterator for &'a EnumSet - where E: CLike -{ - type Item = E; - type IntoIter = Iter; - - fn into_iter(self) -> Iter { - self.iter() - } -} - -impl Extend for EnumSet { - fn extend>(&mut self, iter: I) { - for element in iter { - self.insert(element); - } - } -} - -impl<'a, E: 'a + CLike + Copy> Extend<&'a E> for EnumSet { - fn extend>(&mut self, iter: I) { - self.extend(iter.into_iter().cloned()); - } -} diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 3bea61f6220b6..8d056afdb571a 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -89,9 +89,6 @@ pub use btree_set::BTreeSet; #[doc(no_inline)] pub use linked_list::LinkedList; #[doc(no_inline)] -#[allow(deprecated)] -pub use enum_set::EnumSet; -#[doc(no_inline)] pub use vec_deque::VecDeque; #[doc(no_inline)] pub use string::String; @@ -107,7 +104,6 @@ mod macros; pub mod binary_heap; mod btree; pub mod borrow; -pub mod enum_set; pub mod fmt; pub mod linked_list; pub mod range; diff --git a/src/test/run-pass/sync-send-iterators-in-libcollections.rs b/src/test/run-pass/sync-send-iterators-in-libcollections.rs index d046705c94bbe..ea154590deef0 100644 --- a/src/test/run-pass/sync-send-iterators-in-libcollections.rs +++ b/src/test/run-pass/sync-send-iterators-in-libcollections.rs @@ -10,13 +10,12 @@ #![allow(warnings)] #![feature(collections)] -#![feature(drain, enumset, collections_bound, btree_range, vecmap)] +#![feature(drain, collections_bound, btree_range, vecmap)] extern crate collections; use collections::BinaryHeap; use collections::{BTreeMap, BTreeSet}; -use collections::EnumSet; use collections::LinkedList; use collections::String; use collections::Vec; @@ -25,7 +24,6 @@ use std::collections::HashMap; use std::collections::HashSet; use collections::Bound::Included; -use collections::enum_set::CLike; use std::mem; fn is_sync(_: T) where T: Sync {} @@ -76,21 +74,6 @@ fn main() { all_sync_send!(LinkedList::::new(), iter, iter_mut, into_iter); - #[derive(Copy, Clone)] - #[repr(usize)] - #[allow(dead_code)] - enum Foo { A, B, C } - impl CLike for Foo { - fn to_usize(&self) -> usize { - *self as usize - } - - fn from_usize(v: usize) -> Foo { - unsafe { mem::transmute(v) } - } - } - all_sync_send!(EnumSet::::new(), iter); - all_sync_send!(VecDeque::::new(), iter, iter_mut, into_iter); is_sync_send!(VecDeque::::new(), drain(..)); From a724ff90e744c782e425e634defbf143b8ef62b9 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 13:36:23 -0700 Subject: [PATCH 02/10] Remove BinaryHeap::{push_pop,replace} [unstable, deprecated since 1.13.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../library-features/binary-heap-extras.md | 7 -- src/libcollections/binary_heap.rs | 76 ------------------- src/libcollections/tests/binary_heap.rs | 37 --------- src/libcollections/tests/lib.rs | 1 - src/test/run-pass/while-let.rs | 2 - 6 files changed, 124 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/binary-heap-extras.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index b803b6556cfa1..4951ff7965a89 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -103,7 +103,6 @@ - [as_c_str](library-features/as-c-str.md) - [as_unsafe_cell](library-features/as-unsafe-cell.md) - [ascii_ctype](library-features/ascii-ctype.md) - - [binary_heap_extras](library-features/binary-heap-extras.md) - [binary_heap_peek_mut_pop](library-features/binary-heap-peek-mut-pop.md) - [borrow_state](library-features/borrow-state.md) - [box_heap](library-features/box-heap.md) diff --git a/src/doc/unstable-book/src/library-features/binary-heap-extras.md b/src/doc/unstable-book/src/library-features/binary-heap-extras.md deleted file mode 100644 index aa535f3b67840..0000000000000 --- a/src/doc/unstable-book/src/library-features/binary-heap-extras.md +++ /dev/null @@ -1,7 +0,0 @@ -# `binary_heap_extras` - -The tracking issue for this feature is: [#28147] - -[#28147]: https://github.com/rust-lang/rust/issues/28147 - ------------------------- diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 149c285a72a98..e61d5b3169607 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -555,82 +555,6 @@ impl BinaryHeap { self.sift_up(0, old_len); } - /// Pushes an item onto the binary heap, then pops the greatest item off the queue in - /// an optimized fashion. - /// - /// # Examples - /// - /// Basic usage: - /// - /// ``` - /// #![feature(binary_heap_extras)] - /// #![allow(deprecated)] - /// - /// use std::collections::BinaryHeap; - /// let mut heap = BinaryHeap::new(); - /// heap.push(1); - /// heap.push(5); - /// - /// assert_eq!(heap.push_pop(3), 5); - /// assert_eq!(heap.push_pop(9), 9); - /// assert_eq!(heap.len(), 2); - /// assert_eq!(heap.peek(), Some(&3)); - /// ``` - #[unstable(feature = "binary_heap_extras", - reason = "needs to be audited", - issue = "28147")] - #[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")] - pub fn push_pop(&mut self, mut item: T) -> T { - match self.data.get_mut(0) { - None => return item, - Some(top) => { - if *top > item { - swap(&mut item, top); - } else { - return item; - } - } - } - - self.sift_down(0); - item - } - - /// Pops the greatest item off the binary heap, then pushes an item onto the queue in - /// an optimized fashion. The push is done regardless of whether the binary heap - /// was empty. - /// - /// # Examples - /// - /// Basic usage: - /// - /// ``` - /// #![feature(binary_heap_extras)] - /// #![allow(deprecated)] - /// - /// use std::collections::BinaryHeap; - /// let mut heap = BinaryHeap::new(); - /// - /// assert_eq!(heap.replace(1), None); - /// assert_eq!(heap.replace(3), Some(1)); - /// assert_eq!(heap.len(), 1); - /// assert_eq!(heap.peek(), Some(&3)); - /// ``` - #[unstable(feature = "binary_heap_extras", - reason = "needs to be audited", - issue = "28147")] - #[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")] - pub fn replace(&mut self, mut item: T) -> Option { - if !self.is_empty() { - swap(&mut item, &mut self.data[0]); - self.sift_down(0); - Some(item) - } else { - self.push(item); - None - } - } - /// Consumes the `BinaryHeap` and returns the underlying vector /// in arbitrary order. /// diff --git a/src/libcollections/tests/binary_heap.rs b/src/libcollections/tests/binary_heap.rs index d284937a9e676..af18cddaddb01 100644 --- a/src/libcollections/tests/binary_heap.rs +++ b/src/libcollections/tests/binary_heap.rs @@ -152,36 +152,6 @@ fn test_push_unique() { assert!(*heap.peek().unwrap() == box 103); } -#[test] -#[allow(deprecated)] -fn test_push_pop() { - let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]); - assert_eq!(heap.len(), 5); - assert_eq!(heap.push_pop(6), 6); - assert_eq!(heap.len(), 5); - assert_eq!(heap.push_pop(0), 5); - assert_eq!(heap.len(), 5); - assert_eq!(heap.push_pop(4), 5); - assert_eq!(heap.len(), 5); - assert_eq!(heap.push_pop(1), 4); - assert_eq!(heap.len(), 5); -} - -#[test] -#[allow(deprecated)] -fn test_replace() { - let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]); - assert_eq!(heap.len(), 5); - assert_eq!(heap.replace(6).unwrap(), 5); - assert_eq!(heap.len(), 5); - assert_eq!(heap.replace(0).unwrap(), 6); - assert_eq!(heap.len(), 5); - assert_eq!(heap.replace(4).unwrap(), 5); - assert_eq!(heap.len(), 5); - assert_eq!(heap.replace(1).unwrap(), 4); - assert_eq!(heap.len(), 5); -} - fn check_to_vec(mut data: Vec) { let heap = BinaryHeap::from(data.clone()); let mut v = heap.clone().into_vec(); @@ -227,13 +197,6 @@ fn test_empty_peek_mut() { assert!(empty.peek_mut().is_none()); } -#[test] -#[allow(deprecated)] -fn test_empty_replace() { - let mut heap = BinaryHeap::new(); - assert!(heap.replace(5).is_none()); -} - #[test] fn test_from_iter() { let xs = vec![9, 8, 7, 6, 5, 4, 3, 2, 1]; diff --git a/src/libcollections/tests/lib.rs b/src/libcollections/tests/lib.rs index 618eb386c0f4c..9c6e31d70a541 100644 --- a/src/libcollections/tests/lib.rs +++ b/src/libcollections/tests/lib.rs @@ -10,7 +10,6 @@ #![deny(warnings)] -#![feature(binary_heap_extras)] #![feature(binary_heap_peek_mut_pop)] #![feature(box_syntax)] #![feature(inclusive_range_syntax)] diff --git a/src/test/run-pass/while-let.rs b/src/test/run-pass/while-let.rs index 9ffba2c7999f1..aed6986c5fe5d 100644 --- a/src/test/run-pass/while-let.rs +++ b/src/test/run-pass/while-let.rs @@ -9,8 +9,6 @@ // except according to those terms. -#![feature(binary_heap_extras)] - use std::collections::BinaryHeap; fn make_pq() -> BinaryHeap { From df86cecdd2ca927110c48c97227a62d1d0c8f7ce Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 13:50:47 -0700 Subject: [PATCH 03/10] Remove OccupiedEntry::remove_pair [unstable, deprecated since 1.12.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/library-features/map-entry-recover-keys.md | 5 ----- src/libcollections/btree/map.rs | 7 ------- src/libstd/collections/hash/map.rs | 7 ------- 4 files changed, 20 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/map-entry-recover-keys.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 4951ff7965a89..0d5aa4b5c422c 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -163,7 +163,6 @@ - [linked_list_extras](library-features/linked-list-extras.md) - [lookup_host](library-features/lookup-host.md) - [manually_drop](library-features/manually-drop.md) - - [map_entry_recover_keys](library-features/map-entry-recover-keys.md) - [mpsc_select](library-features/mpsc-select.md) - [n16](library-features/n16.md) - [never_type_impls](library-features/never-type-impls.md) diff --git a/src/doc/unstable-book/src/library-features/map-entry-recover-keys.md b/src/doc/unstable-book/src/library-features/map-entry-recover-keys.md deleted file mode 100644 index 2d15aa0e90de8..0000000000000 --- a/src/doc/unstable-book/src/library-features/map-entry-recover-keys.md +++ /dev/null @@ -1,5 +0,0 @@ -# `map_entry_recover_keys` - -The tracking issue for this feature is: [#34285] - -[#34285]: https://github.com/rust-lang/rust/issues/34285 diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index fb0b852d10271..885b97dda8168 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -2217,13 +2217,6 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> { self.handle.reborrow().into_kv().0 } - /// Deprecated, renamed to `remove_entry` - #[unstable(feature = "map_entry_recover_keys", issue = "34285")] - #[rustc_deprecated(since = "1.12.0", reason = "renamed to `remove_entry`")] - pub fn remove_pair(self) -> (K, V) { - self.remove_entry() - } - /// Take ownership of the key and value from the map. /// /// # Examples diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index eacb59d375a50..c8732e68c8539 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2017,13 +2017,6 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { self.elem.read().0 } - /// Deprecated, renamed to `remove_entry` - #[unstable(feature = "map_entry_recover_keys", issue = "34285")] - #[rustc_deprecated(since = "1.12.0", reason = "renamed to `remove_entry`")] - pub fn remove_pair(self) -> (K, V) { - self.remove_entry() - } - /// Take the ownership of the key and value from the map. /// /// # Examples From f4aaae9bdbca695d8d60feaa63cb09cf06598d50 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 13:55:38 -0700 Subject: [PATCH 04/10] Remove Rc::would_wrap [unstable, deprecated since 1.15.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/library-features/rc-would-unwrap.md | 5 ----- src/liballoc/rc.rs | 13 ------------- 3 files changed, 19 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/rc-would-unwrap.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 0d5aa4b5c422c..cc03ac4d244dd 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -185,7 +185,6 @@ - [rand](library-features/rand.md) - [range_contains](library-features/range-contains.md) - [raw](library-features/raw.md) - - [rc_would_unwrap](library-features/rc-would-unwrap.md) - [retain_hash_collection](library-features/retain-hash-collection.md) - [reverse_cmp_key](library-features/reverse-cmp-key.md) - [rt](library-features/rt.md) diff --git a/src/doc/unstable-book/src/library-features/rc-would-unwrap.md b/src/doc/unstable-book/src/library-features/rc-would-unwrap.md deleted file mode 100644 index 462387dfdcc40..0000000000000 --- a/src/doc/unstable-book/src/library-features/rc-would-unwrap.md +++ /dev/null @@ -1,5 +0,0 @@ -# `rc_would_unwrap` - -The tracking issue for this feature is: [#28356] - -[#28356]: https://github.com/rust-lang/rust/issues/28356 diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index fed718e9be4c6..dab6cf011bdf4 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -341,19 +341,6 @@ impl Rc { } } - /// Checks whether [`Rc::try_unwrap`][try_unwrap] would return - /// [`Ok`]. - /// - /// [try_unwrap]: struct.Rc.html#method.try_unwrap - /// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok - #[unstable(feature = "rc_would_unwrap", - reason = "just added for niche usecase", - issue = "28356")] - #[rustc_deprecated(since = "1.15.0", reason = "too niche; use `strong_count` instead")] - pub fn would_unwrap(this: &Self) -> bool { - Rc::strong_count(&this) == 1 - } - /// Consumes the `Rc`, returning the wrapped pointer. /// /// To avoid a memory leak the pointer must be converted back to an `Rc` using From f0c5e8b8fc6d3631de39cfc250868da993ff4086 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 14:02:20 -0700 Subject: [PATCH 05/10] Privatize Rc::is_unique [unstable, deprecated since 1.15.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - src/doc/unstable-book/src/library-features/is-unique.md | 7 ------- src/liballoc/rc.rs | 6 +----- 3 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/is-unique.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index cc03ac4d244dd..0362ed6ba9d39 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -155,7 +155,6 @@ - [io_error_internals](library-features/io-error-internals.md) - [io](library-features/io.md) - [ip](library-features/ip.md) - - [is_unique](library-features/is-unique.md) - [iter_rfind](library-features/iter-rfind.md) - [libstd_io_internals](library-features/libstd-io-internals.md) - [libstd_sys_internals](library-features/libstd-sys-internals.md) diff --git a/src/doc/unstable-book/src/library-features/is-unique.md b/src/doc/unstable-book/src/library-features/is-unique.md deleted file mode 100644 index 6070006758b7a..0000000000000 --- a/src/doc/unstable-book/src/library-features/is-unique.md +++ /dev/null @@ -1,7 +0,0 @@ -# `is_unique` - -The tracking issue for this feature is: [#28356] - -[#28356]: https://github.com/rust-lang/rust/issues/28356 - ------------------------- diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index dab6cf011bdf4..b12d89867c8ef 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -488,11 +488,7 @@ impl Rc { /// /// [weak]: struct.Weak.html #[inline] - #[unstable(feature = "is_unique", reason = "uniqueness has unclear meaning", - issue = "28356")] - #[rustc_deprecated(since = "1.15.0", - reason = "too niche; use `strong_count` and `weak_count` instead")] - pub fn is_unique(this: &Self) -> bool { + fn is_unique(this: &Self) -> bool { Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1 } From cc605c895e3ac3d19b70da58a683a65200c491fe Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 14:06:18 -0700 Subject: [PATCH 06/10] Remove {Cell,RefCell}::as_unsafe_cell [unstable, deprecated since 1.12.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/library-features/as-unsafe-cell.md | 7 --- src/libcore/cell.rs | 43 ------------------- 3 files changed, 51 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/as-unsafe-cell.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 0362ed6ba9d39..2a932e342f6a7 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -101,7 +101,6 @@ - [alloc_system](library-features/alloc-system.md) - [alloc](library-features/alloc.md) - [as_c_str](library-features/as-c-str.md) - - [as_unsafe_cell](library-features/as-unsafe-cell.md) - [ascii_ctype](library-features/ascii-ctype.md) - [binary_heap_peek_mut_pop](library-features/binary-heap-peek-mut-pop.md) - [borrow_state](library-features/borrow-state.md) diff --git a/src/doc/unstable-book/src/library-features/as-unsafe-cell.md b/src/doc/unstable-book/src/library-features/as-unsafe-cell.md deleted file mode 100644 index 79d7a7cad0b6e..0000000000000 --- a/src/doc/unstable-book/src/library-features/as-unsafe-cell.md +++ /dev/null @@ -1,7 +0,0 @@ -# `as_unsafe_cell` - -The tracking issue for this feature is: [#27708] - -[#27708]: https://github.com/rust-lang/rust/issues/27708 - ------------------------- diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 0186d9727828d..a5dda5625bd3a 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -310,26 +310,6 @@ impl Cell { } } - /// Returns a reference to the underlying `UnsafeCell`. - /// - /// # Examples - /// - /// ``` - /// #![feature(as_unsafe_cell)] - /// - /// use std::cell::Cell; - /// - /// let c = Cell::new(5); - /// - /// let uc = c.as_unsafe_cell(); - /// ``` - #[inline] - #[unstable(feature = "as_unsafe_cell", issue = "27708")] - #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")] - pub fn as_unsafe_cell(&self) -> &UnsafeCell { - &self.value - } - /// Returns a raw pointer to the underlying data in this cell. /// /// # Examples @@ -769,29 +749,6 @@ impl RefCell { } } - /// Returns a reference to the underlying `UnsafeCell`. - /// - /// This can be used to circumvent `RefCell`'s safety checks. - /// - /// This function is `unsafe` because `UnsafeCell`'s field is public. - /// - /// # Examples - /// - /// ``` - /// #![feature(as_unsafe_cell)] - /// - /// use std::cell::RefCell; - /// - /// let c = RefCell::new(5); - /// let c = unsafe { c.as_unsafe_cell() }; - /// ``` - #[inline] - #[unstable(feature = "as_unsafe_cell", issue = "27708")] - #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")] - pub unsafe fn as_unsafe_cell(&self) -> &UnsafeCell { - &self.value - } - /// Returns a raw pointer to the underlying data in this cell. /// /// # Examples From 313aab8fbeb98730f8ffa741ccf54f843d5e3525 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 14:10:22 -0700 Subject: [PATCH 07/10] Remove RefCell::borrow_state [unstable, deprecated since 1.15.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/library-features/borrow-state.md | 7 --- src/libcore/cell.rs | 46 ------------------- src/libstd/lib.rs | 1 - 4 files changed, 55 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/borrow-state.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 2a932e342f6a7..ae3b23a33b24e 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -103,7 +103,6 @@ - [as_c_str](library-features/as-c-str.md) - [ascii_ctype](library-features/ascii-ctype.md) - [binary_heap_peek_mut_pop](library-features/binary-heap-peek-mut-pop.md) - - [borrow_state](library-features/borrow-state.md) - [box_heap](library-features/box-heap.md) - [c_void_variant](library-features/c-void-variant.md) - [char_escape_debug](library-features/char-escape-debug.md) diff --git a/src/doc/unstable-book/src/library-features/borrow-state.md b/src/doc/unstable-book/src/library-features/borrow-state.md deleted file mode 100644 index 304b8dffe9867..0000000000000 --- a/src/doc/unstable-book/src/library-features/borrow-state.md +++ /dev/null @@ -1,7 +0,0 @@ -# `borrow_state` - -The tracking issue for this feature is: [#27733] - -[#27733]: https://github.com/rust-lang/rust/issues/27733 - ------------------------- diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index a5dda5625bd3a..ba04cbb0543cd 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -460,20 +460,6 @@ pub struct RefCell { value: UnsafeCell, } -/// An enumeration of values returned from the `state` method on a `RefCell`. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -#[unstable(feature = "borrow_state", issue = "27733")] -#[rustc_deprecated(since = "1.15.0", reason = "use `try_borrow` instead")] -#[allow(deprecated)] -pub enum BorrowState { - /// The cell is currently being read, there is at least one active `borrow`. - Reading, - /// The cell is currently being written to, there is an active `borrow_mut`. - Writing, - /// There are no outstanding borrows on this cell. - Unused, -} - /// An error returned by [`RefCell::try_borrow`](struct.RefCell.html#method.try_borrow). #[stable(feature = "try_borrow", since = "1.13.0")] pub struct BorrowError { @@ -562,38 +548,6 @@ impl RefCell { } impl RefCell { - /// Query the current state of this `RefCell` - /// - /// The returned value can be dispatched on to determine if a call to - /// `borrow` or `borrow_mut` would succeed. - /// - /// # Examples - /// - /// ``` - /// #![feature(borrow_state)] - /// - /// use std::cell::{BorrowState, RefCell}; - /// - /// let c = RefCell::new(5); - /// - /// match c.borrow_state() { - /// BorrowState::Writing => println!("Cannot be borrowed"), - /// BorrowState::Reading => println!("Cannot be borrowed mutably"), - /// BorrowState::Unused => println!("Can be borrowed (mutably as well)"), - /// } - /// ``` - #[unstable(feature = "borrow_state", issue = "27733")] - #[rustc_deprecated(since = "1.15.0", reason = "use `try_borrow` instead")] - #[allow(deprecated)] - #[inline] - pub fn borrow_state(&self) -> BorrowState { - match self.borrow.get() { - WRITING => BorrowState::Writing, - UNUSED => BorrowState::Unused, - _ => BorrowState::Reading, - } - } - /// Immutably borrows the wrapped value. /// /// The borrow lasts until the returned `Ref` exits scope. Multiple diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 367779bb701c8..6c3abf99d11fa 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -248,7 +248,6 @@ #![feature(allow_internal_unstable)] #![feature(asm)] #![feature(associated_consts)] -#![feature(borrow_state)] #![feature(box_syntax)] #![feature(cfg_target_has_atomic)] #![feature(cfg_target_thread_local)] From c903ac64e58241a71ec42e791b0cc1451ffc3840 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 15:12:42 -0700 Subject: [PATCH 08/10] Remove num::{Zero,One} [unstable, deprecated since 1.11.0] --- src/doc/unstable-book/src/SUMMARY.md | 2 - .../src/library-features/zero-one.md | 7 -- src/libcore/fmt/num.rs | 5 +- src/libcore/num/mod.rs | 72 ------------------- src/libstd/lib.rs | 1 - src/libstd/num.rs | 3 - src/test/run-pass/issue-8460.rs | 35 +++++---- 7 files changed, 26 insertions(+), 99 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/zero-one.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index ae3b23a33b24e..48659413cad00 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -217,5 +217,3 @@ - [windows_handle](library-features/windows-handle.md) - [windows_net](library-features/windows-net.md) - [windows_stdio](library-features/windows-stdio.md) - - [zero_one](library-features/zero-one.md) ->>>>>> Add top level sections to the Unstable Book. diff --git a/src/doc/unstable-book/src/library-features/zero-one.md b/src/doc/unstable-book/src/library-features/zero-one.md deleted file mode 100644 index 4d1cf38c3c2ea..0000000000000 --- a/src/doc/unstable-book/src/library-features/zero-one.md +++ /dev/null @@ -1,7 +0,0 @@ -# `zero_one` - -The tracking issue for this feature is: [#27739] - -[#27739]: https://github.com/rust-lang/rust/issues/27739 - ------------------------- diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index a324a4aed2576..4ca303dee43f2 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -15,7 +15,6 @@ // FIXME: #6220 Implement floating point formatting use fmt; -use num::Zero; use ops::{Div, Rem, Sub}; use str; use slice; @@ -23,8 +22,9 @@ use ptr; use mem; #[doc(hidden)] -trait Int: Zero + PartialEq + PartialOrd + Div + Rem + +trait Int: PartialEq + PartialOrd + Div + Rem + Sub + Copy { + fn zero() -> Self; fn from_u8(u: u8) -> Self; fn to_u8(&self) -> u8; fn to_u16(&self) -> u16; @@ -35,6 +35,7 @@ trait Int: Zero + PartialEq + PartialOrd + Div + Rem + macro_rules! doit { ($($t:ident)*) => ($(impl Int for $t { + fn zero() -> $t { 0 } fn from_u8(u: u8) -> $t { u as $t } fn to_u8(&self) -> u8 { *self as u8 } fn to_u16(&self) -> u16 { *self as u16 } diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index f665cfdee77ae..1e25d45bfbb51 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -96,78 +96,6 @@ pub mod dec2flt; pub mod bignum; pub mod diy_float; -/// Types that have a "zero" value. -/// -/// This trait is intended for use in conjunction with `Add`, as an identity: -/// `x + T::zero() == x`. -#[unstable(feature = "zero_one", - reason = "unsure of placement, wants to use associated constants", - issue = "27739")] -#[rustc_deprecated(since = "1.11.0", reason = "no longer used for \ - Iterator::sum")] -pub trait Zero: Sized { - /// The "zero" (usually, additive identity) for this type. - fn zero() -> Self; -} - -/// Types that have a "one" value. -/// -/// This trait is intended for use in conjunction with `Mul`, as an identity: -/// `x * T::one() == x`. -#[unstable(feature = "zero_one", - reason = "unsure of placement, wants to use associated constants", - issue = "27739")] -#[rustc_deprecated(since = "1.11.0", reason = "no longer used for \ - Iterator::product")] -pub trait One: Sized { - /// The "one" (usually, multiplicative identity) for this type. - fn one() -> Self; -} - -macro_rules! zero_one_impl { - ($($t:ty)*) => ($( - #[unstable(feature = "zero_one", - reason = "unsure of placement, wants to use associated constants", - issue = "27739")] - #[allow(deprecated)] - impl Zero for $t { - #[inline] - fn zero() -> Self { 0 } - } - #[unstable(feature = "zero_one", - reason = "unsure of placement, wants to use associated constants", - issue = "27739")] - #[allow(deprecated)] - impl One for $t { - #[inline] - fn one() -> Self { 1 } - } - )*) -} -zero_one_impl! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } - -macro_rules! zero_one_impl_float { - ($($t:ty)*) => ($( - #[unstable(feature = "zero_one", - reason = "unsure of placement, wants to use associated constants", - issue = "27739")] - #[allow(deprecated)] - impl Zero for $t { - #[inline] - fn zero() -> Self { 0.0 } - } - #[unstable(feature = "zero_one", - reason = "unsure of placement, wants to use associated constants", - issue = "27739")] - #[allow(deprecated)] - impl One for $t { - #[inline] - fn one() -> Self { 1.0 } - } - )*) -} -zero_one_impl_float! { f32 f64 } - macro_rules! checked_op { ($U:ty, $op:path, $x:expr, $y:expr) => {{ let (result, overflowed) = unsafe { $op($x as $U, $y as $U) }; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6c3abf99d11fa..28b94107c425a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -318,7 +318,6 @@ #![feature(untagged_unions)] #![feature(unwind_attributes)] #![feature(vec_push_all)] -#![feature(zero_one)] #![cfg_attr(test, feature(update_panic_count))] #![cfg_attr(stage0, feature(pub_restricted))] #![cfg_attr(test, feature(float_bits_conv))] diff --git a/src/libstd/num.rs b/src/libstd/num.rs index 5f83d077a1368..ff89887ac92c3 100644 --- a/src/libstd/num.rs +++ b/src/libstd/num.rs @@ -16,9 +16,6 @@ #![stable(feature = "rust1", since = "1.0.0")] #![allow(missing_docs)] -#[stable(feature = "rust1", since = "1.0.0")] -#[allow(deprecated)] -pub use core::num::{Zero, One}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::num::{FpCategory, ParseIntError, ParseFloatError, TryFromIntError}; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/test/run-pass/issue-8460.rs b/src/test/run-pass/issue-8460.rs index 5148be5af8307..17ea5b9a79489 100644 --- a/src/test/run-pass/issue-8460.rs +++ b/src/test/run-pass/issue-8460.rs @@ -9,11 +9,22 @@ // except according to those terms. // ignore-emscripten no threads support -#![feature(rustc_attrs, zero_one)] +#![feature(rustc_attrs)] -use std::num::Zero; use std::thread; +trait Int { + fn zero() -> Self; + fn one() -> Self; +} +macro_rules! doit { + ($($t:ident)*) => ($(impl Int for $t { + fn zero() -> $t { 0 } + fn one() -> $t { 1 } + })*) +} +doit! { i8 i16 i32 i64 isize } + macro_rules! check { ($($e:expr),*) => { $(assert!(thread::spawn({ @@ -24,21 +35,21 @@ macro_rules! check { fn main() { check![ - isize::min_value() / -1, - i8::min_value() / -1, - i16::min_value() / -1, - i32::min_value() / -1, - i64::min_value() / -1, + isize::min_value() / -isize::one(), + i8::min_value() / -i8::one(), + i16::min_value() / -i16::one(), + i32::min_value() / -i32::one(), + i64::min_value() / -i64::one(), 1isize / isize::zero(), 1i8 / i8::zero(), 1i16 / i16::zero(), 1i32 / i32::zero(), 1i64 / i64::zero(), - isize::min_value() % -1, - i8::min_value() % -1, - i16::min_value() % -1, - i32::min_value() % -1, - i64::min_value() % -1, + isize::min_value() % -isize::one(), + i8::min_value() % -i8::one(), + i16::min_value() % -i16::one(), + i32::min_value() % -i32::one(), + i64::min_value() % -i64::one(), 1isize % isize::zero(), 1i8 % i8::zero(), 1i16 % i16::zero(), From c1aaa60d8de1c90939671f10ce7ce08400e27ad7 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 20 Apr 2017 16:09:54 -0700 Subject: [PATCH 09/10] Remove float_extras [unstable, deprecated since 1.11.0] --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/library-features/float-extras.md | 7 - src/libcore/num/dec2flt/rawfp.rs | 41 +++- src/libcore/num/f32.rs | 45 ---- src/libcore/num/f64.rs | 45 ---- src/libcore/num/flt2dec/decoder.rs | 4 +- src/libcore/num/mod.rs | 51 ----- src/libcore/tests/num/dec2flt/rawfp.rs | 47 ++-- src/libstd/f32.rs | 204 ------------------ src/libstd/f64.rs | 179 --------------- src/libstd/lib.rs | 1 - src/test/run-pass/union/union-transmute.rs | 8 +- 12 files changed, 74 insertions(+), 559 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/float-extras.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 48659413cad00..9fbd4e300f8f8 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -133,7 +133,6 @@ - [fd_read](library-features/fd-read.md) - [fixed_size_array](library-features/fixed-size-array.md) - [float_bits_conv](library-features/float-bits-conv.md) - - [float_extras](library-features/float-extras.md) - [flt2dec](library-features/flt2dec.md) - [fmt_flags_align](library-features/fmt-flags-align.md) - [fmt_internals](library-features/fmt-internals.md) diff --git a/src/doc/unstable-book/src/library-features/float-extras.md b/src/doc/unstable-book/src/library-features/float-extras.md deleted file mode 100644 index ff2d20a545fe5..0000000000000 --- a/src/doc/unstable-book/src/library-features/float-extras.md +++ /dev/null @@ -1,7 +0,0 @@ -# `float_extras` - -The tracking issue for this feature is: [#27752] - -[#27752]: https://github.com/rust-lang/rust/issues/27752 - ------------------------- diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index 1485c79ead251..2a60292d0232e 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -63,11 +63,8 @@ pub trait RawFloat : Float + Copy + Debug + LowerExp const NAN: Self; const ZERO: Self; - // suffix of "2" because Float::integer_decode is deprecated - #[allow(deprecated)] - fn integer_decode2(self) -> (u64, i16, i8) { - Float::integer_decode(self) - } + /// Returns the mantissa, exponent and sign as integers. + fn integer_decode(self) -> (u64, i16, i8); /// Get the raw binary representation of the float. fn transmute(self) -> u64; @@ -160,6 +157,21 @@ impl RawFloat for f32 { const ZERO_CUTOFF: i64 = -48; other_constants!(f32); + /// Returns the mantissa, exponent and sign as integers. + fn integer_decode(self) -> (u64, i16, i8) { + let bits: u32 = unsafe { transmute(self) }; + let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 }; + let mut exponent: i16 = ((bits >> 23) & 0xff) as i16; + let mantissa = if exponent == 0 { + (bits & 0x7fffff) << 1 + } else { + (bits & 0x7fffff) | 0x800000 + }; + // Exponent bias + mantissa shift + exponent -= 127 + 23; + (mantissa as u64, exponent, sign) + } + fn transmute(self) -> u64 { let bits: u32 = unsafe { transmute(self) }; bits as u64 @@ -171,7 +183,7 @@ impl RawFloat for f32 { } fn unpack(self) -> Unpacked { - let (sig, exp, _sig) = self.integer_decode2(); + let (sig, exp, _sig) = self.integer_decode(); Unpacked::new(sig, exp) } @@ -196,6 +208,21 @@ impl RawFloat for f64 { const ZERO_CUTOFF: i64 = -326; other_constants!(f64); + /// Returns the mantissa, exponent and sign as integers. + fn integer_decode(self) -> (u64, i16, i8) { + let bits: u64 = unsafe { transmute(self) }; + let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 }; + let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16; + let mantissa = if exponent == 0 { + (bits & 0xfffffffffffff) << 1 + } else { + (bits & 0xfffffffffffff) | 0x10000000000000 + }; + // Exponent bias + mantissa shift + exponent -= 1023 + 52; + (mantissa, exponent, sign) + } + fn transmute(self) -> u64 { let bits: u64 = unsafe { transmute(self) }; bits @@ -206,7 +233,7 @@ impl RawFloat for f64 { } fn unpack(self) -> Unpacked { - let (sig, exp, _sig) = self.integer_decode2(); + let (sig, exp, _sig) = self.integer_decode(); Unpacked::new(sig, exp) } diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 4527d46a27d8a..91ca213e96e0d 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -143,36 +143,6 @@ pub mod consts { reason = "stable interface is via `impl f{32,64}` in later crates", issue = "32110")] impl Float for f32 { - #[inline] - fn nan() -> f32 { - NAN - } - - #[inline] - fn infinity() -> f32 { - INFINITY - } - - #[inline] - fn neg_infinity() -> f32 { - NEG_INFINITY - } - - #[inline] - fn zero() -> f32 { - 0.0 - } - - #[inline] - fn neg_zero() -> f32 { - -0.0 - } - - #[inline] - fn one() -> f32 { - 1.0 - } - /// Returns `true` if the number is NaN. #[inline] fn is_nan(self) -> bool { @@ -214,21 +184,6 @@ impl Float for f32 { } } - /// Returns the mantissa, exponent and sign as integers. - fn integer_decode(self) -> (u64, i16, i8) { - let bits: u32 = unsafe { mem::transmute(self) }; - let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 }; - let mut exponent: i16 = ((bits >> 23) & 0xff) as i16; - let mantissa = if exponent == 0 { - (bits & 0x7fffff) << 1 - } else { - (bits & 0x7fffff) | 0x800000 - }; - // Exponent bias + mantissa shift - exponent -= 127 + 23; - (mantissa as u64, exponent, sign) - } - /// Computes the absolute value of `self`. Returns `Float::nan()` if the /// number is `Float::nan()`. #[inline] diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 991a856834948..7d6d6cef04977 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -143,36 +143,6 @@ pub mod consts { reason = "stable interface is via `impl f{32,64}` in later crates", issue = "32110")] impl Float for f64 { - #[inline] - fn nan() -> f64 { - NAN - } - - #[inline] - fn infinity() -> f64 { - INFINITY - } - - #[inline] - fn neg_infinity() -> f64 { - NEG_INFINITY - } - - #[inline] - fn zero() -> f64 { - 0.0 - } - - #[inline] - fn neg_zero() -> f64 { - -0.0 - } - - #[inline] - fn one() -> f64 { - 1.0 - } - /// Returns `true` if the number is NaN. #[inline] fn is_nan(self) -> bool { @@ -214,21 +184,6 @@ impl Float for f64 { } } - /// Returns the mantissa, exponent and sign as integers. - fn integer_decode(self) -> (u64, i16, i8) { - let bits: u64 = unsafe { mem::transmute(self) }; - let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 }; - let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16; - let mantissa = if exponent == 0 { - (bits & 0xfffffffffffff) << 1 - } else { - (bits & 0xfffffffffffff) | 0x10000000000000 - }; - // Exponent bias + mantissa shift - exponent -= 1023 + 52; - (mantissa, exponent, sign) - } - /// Computes the absolute value of `self`. Returns `Float::nan()` if the /// number is `Float::nan()`. #[inline] diff --git a/src/libcore/num/flt2dec/decoder.rs b/src/libcore/num/flt2dec/decoder.rs index 72529d3da01d1..b779eefce5752 100644 --- a/src/libcore/num/flt2dec/decoder.rs +++ b/src/libcore/num/flt2dec/decoder.rs @@ -67,7 +67,7 @@ impl DecodableFloat for f64 { /// Returns a sign (true when negative) and `FullDecoded` value /// from given floating point number. pub fn decode(v: T) -> (/*negative?*/ bool, FullDecoded) { - let (mant, exp, sign) = v.integer_decode2(); + let (mant, exp, sign) = v.integer_decode(); let even = (mant & 1) == 0; let decoded = match v.classify() { FpCategory::Nan => FullDecoded::Nan, @@ -81,7 +81,7 @@ pub fn decode(v: T) -> (/*negative?*/ bool, FullDecoded) { exp: exp, inclusive: even }) } FpCategory::Normal => { - let minnorm = ::min_pos_norm_value().integer_decode2(); + let minnorm = ::min_pos_norm_value().integer_decode(); if mant == minnorm.0 { // neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp) // where maxmant = minnormmant * 2 - 1 diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 1e25d45bfbb51..5c4a43fbd110a 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2453,49 +2453,6 @@ pub enum FpCategory { reason = "stable interface is via `impl f{32,64}` in later crates", issue = "32110")] pub trait Float: Sized { - /// Returns the NaN value. - #[unstable(feature = "float_extras", reason = "needs removal", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn nan() -> Self; - /// Returns the infinite value. - #[unstable(feature = "float_extras", reason = "needs removal", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn infinity() -> Self; - /// Returns the negative infinite value. - #[unstable(feature = "float_extras", reason = "needs removal", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn neg_infinity() -> Self; - /// Returns -0.0. - #[unstable(feature = "float_extras", reason = "needs removal", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn neg_zero() -> Self; - /// Returns 0.0. - #[unstable(feature = "float_extras", reason = "needs removal", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn zero() -> Self; - /// Returns 1.0. - #[unstable(feature = "float_extras", reason = "needs removal", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn one() -> Self; - /// Returns `true` if this value is NaN and false otherwise. #[stable(feature = "core", since = "1.6.0")] fn is_nan(self) -> bool; @@ -2513,14 +2470,6 @@ pub trait Float: Sized { #[stable(feature = "core", since = "1.6.0")] fn classify(self) -> FpCategory; - /// Returns the mantissa, exponent and sign as integers, respectively. - #[unstable(feature = "float_extras", reason = "signature is undecided", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - fn integer_decode(self) -> (u64, i16, i8); - /// Computes the absolute value of `self`. Returns `Float::nan()` if the /// number is `Float::nan()`. #[stable(feature = "core", since = "1.6.0")] diff --git a/src/libcore/tests/num/dec2flt/rawfp.rs b/src/libcore/tests/num/dec2flt/rawfp.rs index 1a3533317dae6..2b0afc402027f 100644 --- a/src/libcore/tests/num/dec2flt/rawfp.rs +++ b/src/libcore/tests/num/dec2flt/rawfp.rs @@ -8,23 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::f32; use std::f64; -use std::mem; use core::num::diy_float::Fp; use core::num::dec2flt::rawfp::{fp_to_float, prev_float, next_float, round_normal}; +use core::num::dec2flt::rawfp::RawFloat; fn integer_decode(f: f64) -> (u64, i16, i8) { - let bits: u64 = unsafe { mem::transmute(f) }; - let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 }; - let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16; - let mantissa = if exponent == 0 { - (bits & 0xfffffffffffff) << 1 - } else { - (bits & 0xfffffffffffff) | 0x10000000000000 - }; - // Exponent bias + mantissa shift - exponent -= 1023 + 52; - (mantissa, exponent, sign) + RawFloat::integer_decode(f) } #[test] @@ -152,3 +143,35 @@ fn next_float_monotonic() { } assert!(x > 0.5); } + +#[test] +fn test_f32_integer_decode() { + assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1)); + assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1)); + assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1)); + assert_eq!(0f32.integer_decode(), (0, -150, 1)); + assert_eq!((-0f32).integer_decode(), (0, -150, -1)); + assert_eq!(f32::INFINITY.integer_decode(), (8388608, 105, 1)); + assert_eq!(f32::NEG_INFINITY.integer_decode(), (8388608, 105, -1)); + + // Ignore the "sign" (quiet / signalling flag) of NAN. + // It can vary between runtime operations and LLVM folding. + let (nan_m, nan_e, _nan_s) = f32::NAN.integer_decode(); + assert_eq!((nan_m, nan_e), (12582912, 105)); +} + +#[test] +fn test_f64_integer_decode() { + assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1)); + assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1)); + assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1)); + assert_eq!(0f64.integer_decode(), (0, -1075, 1)); + assert_eq!((-0f64).integer_decode(), (0, -1075, -1)); + assert_eq!(f64::INFINITY.integer_decode(), (4503599627370496, 972, 1)); + assert_eq!(f64::NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1)); + + // Ignore the "sign" (quiet / signalling flag) of NAN. + // It can vary between runtime operations and LLVM folding. + let (nan_m, nan_e, _nan_s) = f64::NAN.integer_decode(); + assert_eq!((nan_m, nan_e), (6755399441055744, 972)); +} diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 316e6841c4fea..4ed0afcfc2357 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -22,8 +22,6 @@ use core::num; #[cfg(not(test))] use intrinsics; #[cfg(not(test))] -use libc::c_int; -#[cfg(not(test))] use num::FpCategory; @@ -73,8 +71,6 @@ mod cmath { pub fn atan2f(a: c_float, b: c_float) -> c_float; pub fn atanf(n: c_float) -> c_float; pub fn coshf(n: c_float) -> c_float; - pub fn frexpf(n: c_float, value: &mut c_int) -> c_float; - pub fn ldexpf(x: c_float, n: c_int) -> c_float; pub fn sinhf(n: c_float) -> c_float; pub fn tanf(n: c_float) -> c_float; pub fn tanhf(n: c_float) -> c_float; @@ -111,20 +107,6 @@ mod cmath { f64::cosh(n as f64) as c_float } - #[inline] - #[allow(deprecated)] - pub unsafe fn frexpf(x: c_float, value: &mut c_int) -> c_float { - let (a, b) = f64::frexp(x as f64); - *value = b as c_int; - a as c_float - } - - #[inline] - #[allow(deprecated)] - pub unsafe fn ldexpf(x: c_float, n: c_int) -> c_float { - f64::ldexp(x as f64, n as isize) as c_float - } - #[inline] pub unsafe fn sinhf(n: c_float) -> c_float { f64::sinh(n as f64) as c_float @@ -244,40 +226,6 @@ impl f32 { #[inline] pub fn classify(self) -> FpCategory { num::Float::classify(self) } - /// Returns the mantissa, base 2 exponent, and sign as integers, respectively. - /// The original number can be recovered by `sign * mantissa * 2 ^ exponent`. - /// The floating point encoding is documented in the [Reference][floating-point]. - /// - /// ``` - /// #![feature(float_extras)] - /// - /// use std::f32; - /// - /// let num = 2.0f32; - /// - /// // (8388608, -22, 1) - /// let (mantissa, exponent, sign) = num.integer_decode(); - /// let sign_f = sign as f32; - /// let mantissa_f = mantissa as f32; - /// let exponent_f = num.powf(exponent as f32); - /// - /// // 1 * 8388608 * 2^(-22) == 2 - /// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs(); - /// - /// assert!(abs_difference <= f32::EPSILON); - /// ``` - /// [floating-point]: ../reference/types.html#machine-types - #[unstable(feature = "float_extras", reason = "signature is undecided", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - #[allow(deprecated)] - pub fn integer_decode(self) -> (u64, i16, i8) { - num::Float::integer_decode(self) - } - /// Returns the largest integer less than or equal to a number. /// /// ``` @@ -712,89 +660,6 @@ impl f32 { #[inline] pub fn to_radians(self) -> f32 { num::Float::to_radians(self) } - /// Constructs a floating point number of `x*2^exp`. - /// - /// ``` - /// #![feature(float_extras)] - /// - /// use std::f32; - /// // 3*2^2 - 12 == 0 - /// let abs_difference = (f32::ldexp(3.0, 2) - 12.0).abs(); - /// - /// assert!(abs_difference <= f32::EPSILON); - /// ``` - #[unstable(feature = "float_extras", - reason = "pending integer conventions", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - pub fn ldexp(x: f32, exp: isize) -> f32 { - unsafe { cmath::ldexpf(x, exp as c_int) } - } - - /// Breaks the number into a normalized fraction and a base-2 exponent, - /// satisfying: - /// - /// * `self = x * 2^exp` - /// * `0.5 <= abs(x) < 1.0` - /// - /// ``` - /// #![feature(float_extras)] - /// - /// use std::f32; - /// - /// let x = 4.0f32; - /// - /// // (1/2)*2^3 -> 1 * 8/2 -> 4.0 - /// let f = x.frexp(); - /// let abs_difference_0 = (f.0 - 0.5).abs(); - /// let abs_difference_1 = (f.1 as f32 - 3.0).abs(); - /// - /// assert!(abs_difference_0 <= f32::EPSILON); - /// assert!(abs_difference_1 <= f32::EPSILON); - /// ``` - #[unstable(feature = "float_extras", - reason = "pending integer conventions", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - pub fn frexp(self) -> (f32, isize) { - unsafe { - let mut exp = 0; - let x = cmath::frexpf(self, &mut exp); - (x, exp as isize) - } - } - - /// Returns the next representable floating-point value in the direction of - /// `other`. - /// - /// ``` - /// #![feature(float_extras)] - /// - /// use std::f32; - /// - /// let x = 1.0f32; - /// - /// let abs_diff = (x.next_after(2.0) - 1.00000011920928955078125_f32).abs(); - /// - /// assert!(abs_diff <= f32::EPSILON); - /// ``` - #[unstable(feature = "float_extras", - reason = "unsure about its place in the world", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - pub fn next_after(self, other: f32) -> f32 { - unsafe { cmath::nextafterf(self, other) } - } - /// Returns the maximum of the two numbers. /// /// ``` @@ -1462,23 +1327,6 @@ mod tests { assert_eq!(1e-38f32.classify(), Fp::Subnormal); } - #[test] - #[allow(deprecated)] - fn test_integer_decode() { - assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1)); - assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1)); - assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1)); - assert_eq!(0f32.integer_decode(), (0, -150, 1)); - assert_eq!((-0f32).integer_decode(), (0, -150, -1)); - assert_eq!(INFINITY.integer_decode(), (8388608, 105, 1)); - assert_eq!(NEG_INFINITY.integer_decode(), (8388608, 105, -1)); - - // Ignore the "sign" (quiet / signalling flag) of NAN. - // It can vary between runtime operations and LLVM folding. - let (nan_m, nan_e, _nan_s) = NAN.integer_decode(); - assert_eq!((nan_m, nan_e), (12582912, 105)); - } - #[test] fn test_floor() { assert_approx_eq!(1.0f32.floor(), 1.0f32); @@ -1790,58 +1638,6 @@ mod tests { assert_eq!(neg_inf.to_radians(), neg_inf); } - #[test] - #[allow(deprecated)] - fn test_ldexp() { - let f1 = 2.0f32.powi(-123); - let f2 = 2.0f32.powi(-111); - let f3 = 1.75 * 2.0f32.powi(-12); - assert_eq!(f32::ldexp(1f32, -123), f1); - assert_eq!(f32::ldexp(1f32, -111), f2); - assert_eq!(f32::ldexp(1.75f32, -12), f3); - - assert_eq!(f32::ldexp(0f32, -123), 0f32); - assert_eq!(f32::ldexp(-0f32, -123), -0f32); - - let inf: f32 = f32::INFINITY; - let neg_inf: f32 = f32::NEG_INFINITY; - let nan: f32 = f32::NAN; - assert_eq!(f32::ldexp(inf, -123), inf); - assert_eq!(f32::ldexp(neg_inf, -123), neg_inf); - assert!(f32::ldexp(nan, -123).is_nan()); - } - - #[test] - #[allow(deprecated)] - fn test_frexp() { - let f1 = 2.0f32.powi(-123); - let f2 = 2.0f32.powi(-111); - let f3 = 1.75 * 2.0f32.powi(-123); - let (x1, exp1) = f1.frexp(); - let (x2, exp2) = f2.frexp(); - let (x3, exp3) = f3.frexp(); - assert_eq!((x1, exp1), (0.5f32, -122)); - assert_eq!((x2, exp2), (0.5f32, -110)); - assert_eq!((x3, exp3), (0.875f32, -122)); - assert_eq!(f32::ldexp(x1, exp1), f1); - assert_eq!(f32::ldexp(x2, exp2), f2); - assert_eq!(f32::ldexp(x3, exp3), f3); - - assert_eq!(0f32.frexp(), (0f32, 0)); - assert_eq!((-0f32).frexp(), (-0f32, 0)); - } - - #[test] #[cfg_attr(windows, ignore)] // FIXME #8755 - #[allow(deprecated)] - fn test_frexp_nowin() { - let inf: f32 = f32::INFINITY; - let neg_inf: f32 = f32::NEG_INFINITY; - let nan: f32 = f32::NAN; - assert_eq!(match inf.frexp() { (x, _) => x }, inf); - assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf); - assert!(match nan.frexp() { (x, _) => x.is_nan() }) - } - #[test] fn test_asinh() { assert_eq!(0.0f32.asinh(), 0.0f32); diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index be55cb80c92fa..82e3903eec7b1 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -22,8 +22,6 @@ use core::num; #[cfg(not(test))] use intrinsics; #[cfg(not(test))] -use libc::c_int; -#[cfg(not(test))] use num::FpCategory; #[stable(feature = "rust1", since = "1.0.0")] @@ -188,36 +186,6 @@ impl f64 { #[inline] pub fn classify(self) -> FpCategory { num::Float::classify(self) } - /// Returns the mantissa, base 2 exponent, and sign as integers, respectively. - /// The original number can be recovered by `sign * mantissa * 2 ^ exponent`. - /// The floating point encoding is documented in the [Reference][floating-point]. - /// - /// ``` - /// #![feature(float_extras)] - /// - /// let num = 2.0f64; - /// - /// // (8388608, -22, 1) - /// let (mantissa, exponent, sign) = num.integer_decode(); - /// let sign_f = sign as f64; - /// let mantissa_f = mantissa as f64; - /// let exponent_f = num.powf(exponent as f64); - /// - /// // 1 * 8388608 * 2^(-22) == 2 - /// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs(); - /// - /// assert!(abs_difference < 1e-10); - /// ``` - /// [floating-point]: ../reference/types.html#machine-types - #[unstable(feature = "float_extras", reason = "signature is undecided", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - #[allow(deprecated)] - pub fn integer_decode(self) -> (u64, i16, i8) { num::Float::integer_decode(self) } - /// Returns the largest integer less than or equal to a number. /// /// ``` @@ -606,84 +574,6 @@ impl f64 { #[inline] pub fn to_radians(self) -> f64 { num::Float::to_radians(self) } - /// Constructs a floating point number of `x*2^exp`. - /// - /// ``` - /// #![feature(float_extras)] - /// - /// // 3*2^2 - 12 == 0 - /// let abs_difference = (f64::ldexp(3.0, 2) - 12.0).abs(); - /// - /// assert!(abs_difference < 1e-10); - /// ``` - #[unstable(feature = "float_extras", - reason = "pending integer conventions", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - pub fn ldexp(x: f64, exp: isize) -> f64 { - unsafe { cmath::ldexp(x, exp as c_int) } - } - - /// Breaks the number into a normalized fraction and a base-2 exponent, - /// satisfying: - /// - /// * `self = x * 2^exp` - /// * `0.5 <= abs(x) < 1.0` - /// - /// ``` - /// #![feature(float_extras)] - /// - /// let x = 4.0_f64; - /// - /// // (1/2)*2^3 -> 1 * 8/2 -> 4.0 - /// let f = x.frexp(); - /// let abs_difference_0 = (f.0 - 0.5).abs(); - /// let abs_difference_1 = (f.1 as f64 - 3.0).abs(); - /// - /// assert!(abs_difference_0 < 1e-10); - /// assert!(abs_difference_1 < 1e-10); - /// ``` - #[unstable(feature = "float_extras", - reason = "pending integer conventions", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - pub fn frexp(self) -> (f64, isize) { - unsafe { - let mut exp = 0; - let x = cmath::frexp(self, &mut exp); - (x, exp as isize) - } - } - - /// Returns the next representable floating-point value in the direction of - /// `other`. - /// - /// ``` - /// #![feature(float_extras)] - /// - /// let x = 1.0f64; - /// - /// let abs_diff = (x.next_after(2.0) - 1.0000000000000002220446049250313_f64).abs(); - /// - /// assert!(abs_diff < 1e-10); - /// ``` - #[unstable(feature = "float_extras", - reason = "unsure about its place in the world", - issue = "27752")] - #[rustc_deprecated(since = "1.11.0", - reason = "never really came to fruition and easily \ - implementable outside the standard library")] - #[inline] - pub fn next_after(self, other: f64) -> f64 { - unsafe { cmath::nextafter(self, other) } - } - /// Returns the maximum of the two numbers. /// /// ``` @@ -1353,23 +1243,6 @@ mod tests { assert_eq!(1e-308f64.classify(), Fp::Subnormal); } - #[test] - #[allow(deprecated)] - fn test_integer_decode() { - assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1)); - assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1)); - assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1)); - assert_eq!(0f64.integer_decode(), (0, -1075, 1)); - assert_eq!((-0f64).integer_decode(), (0, -1075, -1)); - assert_eq!(INFINITY.integer_decode(), (4503599627370496, 972, 1)); - assert_eq!(NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1)); - - // Ignore the "sign" (quiet / signalling flag) of NAN. - // It can vary between runtime operations and LLVM folding. - let (nan_m, nan_e, _nan_s) = NAN.integer_decode(); - assert_eq!((nan_m, nan_e), (6755399441055744, 972)); - } - #[test] fn test_floor() { assert_approx_eq!(1.0f64.floor(), 1.0f64); @@ -1681,58 +1554,6 @@ mod tests { assert_eq!(neg_inf.to_radians(), neg_inf); } - #[test] - #[allow(deprecated)] - fn test_ldexp() { - let f1 = 2.0f64.powi(-123); - let f2 = 2.0f64.powi(-111); - let f3 = 1.75 * 2.0f64.powi(-12); - assert_eq!(f64::ldexp(1f64, -123), f1); - assert_eq!(f64::ldexp(1f64, -111), f2); - assert_eq!(f64::ldexp(1.75f64, -12), f3); - - assert_eq!(f64::ldexp(0f64, -123), 0f64); - assert_eq!(f64::ldexp(-0f64, -123), -0f64); - - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; - assert_eq!(f64::ldexp(inf, -123), inf); - assert_eq!(f64::ldexp(neg_inf, -123), neg_inf); - assert!(f64::ldexp(nan, -123).is_nan()); - } - - #[test] - #[allow(deprecated)] - fn test_frexp() { - let f1 = 2.0f64.powi(-123); - let f2 = 2.0f64.powi(-111); - let f3 = 1.75 * 2.0f64.powi(-123); - let (x1, exp1) = f1.frexp(); - let (x2, exp2) = f2.frexp(); - let (x3, exp3) = f3.frexp(); - assert_eq!((x1, exp1), (0.5f64, -122)); - assert_eq!((x2, exp2), (0.5f64, -110)); - assert_eq!((x3, exp3), (0.875f64, -122)); - assert_eq!(f64::ldexp(x1, exp1), f1); - assert_eq!(f64::ldexp(x2, exp2), f2); - assert_eq!(f64::ldexp(x3, exp3), f3); - - assert_eq!(0f64.frexp(), (0f64, 0)); - assert_eq!((-0f64).frexp(), (-0f64, 0)); - } - - #[test] #[cfg_attr(windows, ignore)] // FIXME #8755 - #[allow(deprecated)] - fn test_frexp_nowin() { - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; - assert_eq!(match inf.frexp() { (x, _) => x }, inf); - assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf); - assert!(match nan.frexp() { (x, _) => x.is_nan() }) - } - #[test] fn test_asinh() { assert_eq!(0.0f64.asinh(), 0.0f64); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 28b94107c425a..70225da5f3355 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -262,7 +262,6 @@ #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] -#![feature(float_extras)] #![feature(float_from_str_radix)] #![feature(fn_traits)] #![feature(fnbox)] diff --git a/src/test/run-pass/union/union-transmute.rs b/src/test/run-pass/union/union-transmute.rs index 4eb66268ab8ea..7a0b4c6aaca49 100644 --- a/src/test/run-pass/union/union-transmute.rs +++ b/src/test/run-pass/union/union-transmute.rs @@ -8,12 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(core_float)] -#![feature(float_extras)] #![feature(untagged_unions)] extern crate core; -use core::num::Float; +use core::f32; union U { a: (u8, u8), @@ -33,8 +31,8 @@ fn main() { assert_eq!(u.a, (2, 2)); let mut w = W { a: 0b0_11111111_00000000000000000000000 }; - assert_eq!(w.b, f32::infinity()); - w.b = f32::neg_infinity(); + assert_eq!(w.b, f32::INFINITY); + w.b = f32::NEG_INFINITY; assert_eq!(w.a, 0b1_11111111_00000000000000000000000); } } From 13d2534fd3040520622a2b2a262ed9e7079c9fd8 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 22 Apr 2017 22:13:22 -0400 Subject: [PATCH 10/10] Remove unused import. --- src/libstd/f32.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 4ed0afcfc2357..4abad7e24f810 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -80,7 +80,7 @@ mod cmath { pub use self::shims::*; #[cfg(target_env = "msvc")] mod shims { - use libc::{c_float, c_int}; + use libc::c_float; #[inline] pub unsafe fn acosf(n: c_float) -> c_float {