diff options
| author | Matthias Einwag <matthias.einwag@live.com> | 2019-02-12 22:46:14 -0800 |
|---|---|---|
| committer | Matthias Einwag <matthias.einwag@live.com> | 2019-02-12 22:46:14 -0800 |
| commit | 871338c3aed87cb84f02ebd7fd9b447966d5b05d (patch) | |
| tree | a2e1315d7d17d0b9f3463686ed2fbf36f3238ec4 /src/liballoc | |
| parent | 1ef34a5a39641846e824b6450a705d6031002beb (diff) | |
| parent | 0f949c2fcc696d0260a99196d5e5400c59a26a54 (diff) | |
| download | rust-871338c3aed87cb84f02ebd7fd9b447966d5b05d.tar.gz rust-871338c3aed87cb84f02ebd7fd9b447966d5b05d.zip | |
Merging master
Diffstat (limited to 'src/liballoc')
27 files changed, 134 insertions, 128 deletions
diff --git a/src/liballoc/borrow.rs b/src/liballoc/borrow.rs index 270f48e8083..40c71f12cd8 100644 --- a/src/liballoc/borrow.rs +++ b/src/liballoc/borrow.rs @@ -137,11 +137,11 @@ impl<T> ToOwned for T /// ``` /// use std::borrow::{Cow, ToOwned}; /// -/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned=Vec<X>> { +/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned = Vec<X>> { /// values: Cow<'a, [X]>, /// } /// -/// impl<'a, X: Clone + 'a> Items<'a, X> where [X]: ToOwned<Owned=Vec<X>> { +/// impl<'a, X: Clone + 'a> Items<'a, X> where [X]: ToOwned<Owned = Vec<X>> { /// fn new(v: Cow<'a, [X]>) -> Self { /// Items { values: v } /// } diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index f97522140a8..3b94379b58f 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -248,14 +248,18 @@ impl<T: Ord> Drop for PeekMut<'_, T> { impl<T: Ord> Deref for PeekMut<'_, T> { type Target = T; fn deref(&self) -> &T { - &self.heap.data[0] + debug_assert!(!self.heap.is_empty()); + // SAFE: PeekMut is only instantiated for non-empty heaps + unsafe { self.heap.data.get_unchecked(0) } } } #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] impl<T: Ord> DerefMut for PeekMut<'_, T> { fn deref_mut(&mut self) -> &mut T { - &mut self.heap.data[0] + debug_assert!(!self.heap.is_empty()); + // SAFE: PeekMut is only instantiated for non-empty heaps + unsafe { self.heap.data.get_unchecked_mut(0) } } } @@ -859,13 +863,14 @@ struct Hole<'a, T: 'a> { } impl<'a, T> Hole<'a, T> { - /// Create a new Hole at index `pos`. + /// Create a new `Hole` at index `pos`. /// /// Unsafe because pos must be within the data slice. #[inline] unsafe fn new(data: &'a mut [T], pos: usize) -> Self { debug_assert!(pos < data.len()); - let elt = ptr::read(&data[pos]); + // SAFE: pos should be inside the slice + let elt = ptr::read(data.get_unchecked(pos)); Hole { data, elt: ManuallyDrop::new(elt), diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index aaaa419dcb8..5ec5064b735 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -2368,7 +2368,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> { /// Gets a mutable reference to the value in the entry. /// - /// If you need a reference to the `OccupiedEntry` which may outlive the + /// If you need a reference to the `OccupiedEntry` that may outlive the /// destruction of the `Entry` value, see [`into_mut`]. /// /// [`into_mut`]: #method.into_mut diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index c4f39430533..eb0667228d1 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -50,11 +50,11 @@ pub const CAPACITY: usize = 2 * B - 1; /// /// We have a separate type for the header and rely on it matching the prefix of `LeafNode`, in /// order to statically allocate a single dummy node to avoid allocations. This struct is -/// `repr(C)` to prevent them from being reordered. `LeafNode` does not just contain a +/// `repr(C)` to prevent them from being reordered. `LeafNode` does not just contain a /// `NodeHeader` because we do not want unnecessary padding between `len` and the keys. -/// Crucially, `NodeHeader` can be safely transmuted to different K and V. (This is exploited +/// Crucially, `NodeHeader` can be safely transmuted to different K and V. (This is exploited /// by `as_header`.) -/// See `into_key_slice` for an explanation of K2. K2 cannot be safely transmuted around +/// See `into_key_slice` for an explanation of K2. K2 cannot be safely transmuted around /// because the size of `NodeHeader` depends on its alignment! #[repr(C)] struct NodeHeader<K, V, K2 = ()> { @@ -1295,7 +1295,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: } } - /// Returns whether it is valid to call `.merge()`, i.e., whether there is enough room in + /// Returns `true` if it is valid to call `.merge()`, i.e., whether there is enough room in /// a node to hold the combination of the nodes to the left and right of this handle along /// with the key/value pair at this handle. pub fn can_merge(&self) -> bool { @@ -1573,7 +1573,7 @@ unsafe fn move_edges<K, V>( impl<BorrowType, K, V, HandleType> Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, HandleType> { - /// Check whether the underlying node is an `Internal` node or a `Leaf` node. + /// Checks whether the underlying node is an `Internal` node or a `Leaf` node. pub fn force(self) -> ForceResult< Handle<NodeRef<BorrowType, K, V, marker::Leaf>, HandleType>, Handle<NodeRef<BorrowType, K, V, marker::Internal>, HandleType> diff --git a/src/liballoc/collections/btree/set.rs b/src/liballoc/collections/btree/set.rs index 78cd21dd411..870e3e47692 100644 --- a/src/liballoc/collections/btree/set.rs +++ b/src/liballoc/collections/btree/set.rs @@ -556,7 +556,7 @@ impl<T: Ord> BTreeSet<T> { Recover::replace(&mut self.map, value) } - /// Removes a value from the set. Returns `true` if the value was + /// Removes a value from the set. Returns whether the value was /// present in the set. /// /// The value may be any borrowed form of the set's value type, @@ -988,7 +988,7 @@ impl<'a, T> DoubleEndedIterator for Range<'a, T> { #[stable(feature = "fused", since = "1.26.0")] impl<T> FusedIterator for Range<'_, T> {} -/// Compare `x` and `y`, but return `short` if x is None and `long` if y is None +/// Compares `x` and `y`, but return `short` if x is None and `long` if y is None fn cmp_opt<T: Ord>(x: Option<&T>, y: Option<&T>, short: Ordering, long: Ordering) -> Ordering { match (x, y) { (None, _) => short, diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 99fa54acb08..b6fdaa89992 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -124,7 +124,7 @@ impl<T> VecDeque<T> { ptr::write(self.ptr().add(off), value); } - /// Returns `true` if and only if the buffer is at full capacity. + /// Returns `true` if the buffer is at full capacity. #[inline] fn is_full(&self) -> bool { self.cap() - self.len() == 1 @@ -560,7 +560,7 @@ impl<T> VecDeque<T> { /// Does nothing if the capacity is already sufficient. /// /// Note that the allocator may give the collection more space than it - /// requests. Therefore capacity can not be relied upon to be precisely + /// requests. Therefore, capacity can not be relied upon to be precisely /// minimal. Prefer `reserve` if future insertions are expected. /// /// # Errors @@ -924,7 +924,7 @@ impl<T> VecDeque<T> { self.tail == self.head } - /// Create a draining iterator that removes the specified range in the + /// Creates a draining iterator that removes the specified range in the /// `VecDeque` and yields the removed items. /// /// Note 1: The element range is removed even if the iterator is not @@ -932,7 +932,7 @@ impl<T> VecDeque<T> { /// /// Note 2: It is unspecified how many elements are removed from the deque, /// if the `Drain` value is not dropped, but the borrow it holds expires - /// (eg. due to mem::forget). + /// (e.g., due to `mem::forget`). /// /// # Panics /// @@ -1922,7 +1922,7 @@ impl<T> VecDeque<T> { /// /// # Panics /// - /// If `mid` is greater than `len()`. Note that `mid == len()` + /// If `mid` is greater than `len()`. Note that `mid == len()` /// does _not_ panic and is a no-op rotation. /// /// # Complexity @@ -1967,7 +1967,7 @@ impl<T> VecDeque<T> { /// /// # Panics /// - /// If `k` is greater than `len()`. Note that `k == len()` + /// If `k` is greater than `len()`. Note that `k == len()` /// does _not_ panic and is a no-op rotation. /// /// # Complexity diff --git a/src/liballoc/fmt.rs b/src/liballoc/fmt.rs index 9bda7034a62..d2ba9b00191 100644 --- a/src/liballoc/fmt.rs +++ b/src/liballoc/fmt.rs @@ -27,7 +27,7 @@ //! will then parse the format string and determine if the list of arguments //! provided is suitable to pass to this format string. //! -//! To convert a single value to a string, use the [`to_string`] method. This +//! To convert a single value to a string, use the [`to_string`] method. This //! will use the [`Display`] formatting trait. //! //! ## Positional parameters @@ -102,7 +102,7 @@ //! When requesting that an argument be formatted with a particular type, you //! are actually requesting that an argument ascribes to a particular trait. //! This allows multiple actual types to be formatted via `{:x}` (like [`i8`] as -//! well as [`isize`]). The current mapping of types to traits is: +//! well as [`isize`]). The current mapping of types to traits is: //! //! * *nothing* ⇒ [`Display`] //! * `?` ⇒ [`Debug`] @@ -427,7 +427,7 @@ //! 3. An asterisk `.*`: //! //! `.*` means that this `{...}` is associated with *two* format inputs rather than one: the -//! first input holds the `usize` precision, and the second holds the value to print. Note that +//! first input holds the `usize` precision, and the second holds the value to print. Note that //! in this case, if one uses the format string `{<arg>:<spec>.*}`, then the `<arg>` part refers //! to the *value* to print, and the `precision` must come in the input preceding `<arg>`. //! diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index cc73e282b6f..95b9dacf856 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -55,9 +55,7 @@ reason = "this library is unlikely to be stabilized in its current \ form or name", issue = "27783")] -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/", +#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![no_std] @@ -70,7 +68,6 @@ #![warn(intra_doc_link_resolution_failure)] #![warn(missing_debug_implementations)] -#![cfg_attr(not(test), feature(fn_traits))] #![cfg_attr(not(test), feature(generator_trait))] #![cfg_attr(test, feature(test))] @@ -88,6 +85,7 @@ #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] #![feature(fmt_internals)] +#![feature(fn_traits)] #![feature(fundamental)] #![feature(futures_api)] #![feature(lang_items)] @@ -102,6 +100,7 @@ #![feature(receiver_trait)] #![feature(specialization)] #![feature(staged_api)] +#![feature(std_internals)] #![feature(str_internals)] #![feature(trusted_len)] #![feature(try_reserve)] diff --git a/src/liballoc/macros.rs b/src/liballoc/macros.rs index db91b07fa71..eb341007851 100644 --- a/src/liballoc/macros.rs +++ b/src/liballoc/macros.rs @@ -34,7 +34,8 @@ #[cfg(not(test))] #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] -#[allow_internal_unstable] +#[cfg_attr(not(stage0), allow_internal_unstable(box_syntax))] +#[cfg_attr(stage0, allow_internal_unstable)] macro_rules! vec { ($elem:expr; $n:expr) => ( $crate::vec::from_elem($elem, $n) @@ -62,18 +63,18 @@ macro_rules! vec { /// Creates a `String` using interpolation of runtime expressions. /// -/// The first argument `format!` receives is a format string. This must be a string -/// literal. The power of the formatting string is in the `{}`s contained. +/// The first argument `format!` receives is a format string. This must be a string +/// literal. The power of the formatting string is in the `{}`s contained. /// /// Additional parameters passed to `format!` replace the `{}`s within the /// formatting string in the order given unless named or positional parameters -/// are used, see [`std::fmt`][fmt] for more information. +/// are used; see [`std::fmt`][fmt] for more information. /// /// A common use for `format!` is concatenation and interpolation of strings. /// The same convention is used with [`print!`] and [`write!`] macros, /// depending on the intended destination of the string. /// -/// To convert a single value to a string, use the [`to_string`] method. This +/// To convert a single value to a string, use the [`to_string`] method. This /// will use the [`Display`] formatting trait. /// /// [fmt]: ../std/fmt/index.html diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index dcecf9bc76d..fe28fe5095c 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -335,7 +335,7 @@ impl<T, A: Alloc> RawVec<T, A> { /// enough to want to do that it's easiest to just have a dedicated method. Slightly /// more efficient logic can be provided for this than the general case. /// - /// Returns true if the reallocation attempt has succeeded, or false otherwise. + /// Returns `true` if the reallocation attempt has succeeded. /// /// # Panics /// @@ -504,7 +504,7 @@ impl<T, A: Alloc> RawVec<T, A> { /// the requested space. This is not really unsafe, but the unsafe /// code *you* write that relies on the behavior of this function may break. /// - /// Returns true if the reallocation attempt has succeeded, or false otherwise. + /// Returns `true` if the reallocation attempt has succeeded. /// /// # Panics /// diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index d78869270d5..12f75d84211 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -512,7 +512,7 @@ impl<T: ?Sized> Rc<T> { this.strong() } - /// Returns true if there are no other `Rc` or [`Weak`][weak] pointers to + /// Returns `true` if there are no other `Rc` or [`Weak`][weak] pointers to /// this inner value. /// /// [weak]: struct.Weak.html @@ -561,7 +561,7 @@ impl<T: ?Sized> Rc<T> { #[inline] #[stable(feature = "ptr_eq", since = "1.17.0")] - /// Returns true if the two `Rc`s point to the same value (not + /// Returns `true` if the two `Rc`s point to the same value (not /// just values that compare as equal). /// /// # Examples @@ -1334,8 +1334,8 @@ impl<T: ?Sized> Weak<T> { }) } - /// Return `None` when the pointer is dangling and there is no allocated `RcBox`, - /// i.e., this `Weak` was created by `Weak::new` + /// Returns `None` when the pointer is dangling and there is no allocated `RcBox` + /// (i.e., when this `Weak` was created by `Weak::new`). #[inline] fn inner(&self) -> Option<&RcBox<T>> { if is_dangling(self.ptr) { @@ -1345,7 +1345,7 @@ impl<T: ?Sized> Weak<T> { } } - /// Returns true if the two `Weak`s point to the same value (not just values + /// Returns `true` if the two `Weak`s point to the same value (not just values /// that compare as equal). /// /// # Notes diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 479959deeb1..c4f4a80a017 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -205,10 +205,10 @@ impl<T> [T] { /// /// The comparator function must define a total ordering for the elements in the slice. If /// the ordering is not total, the order of the elements is unspecified. An order is a - /// total order if it is (for all a, b and c): + /// total order if it is (for all `a`, `b` and `c`): /// - /// * total and antisymmetric: exactly one of a < b, a == b or a > b is true; and - /// * transitive, a < b and b < c implies a < c. The same must hold for both == and >. + /// * total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true, and + /// * transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// For example, while [`f64`] doesn't implement [`Ord`] because `NaN != NaN`, we can use /// `partial_cmp` as our sort function when we know the slice doesn't contain a `NaN`. diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 1fd4c9978a6..a36804bddff 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -29,8 +29,6 @@ #![allow(unused_imports)] use core::borrow::Borrow; -use core::fmt; -use core::str as core_str; use core::str::pattern::{Pattern, Searcher, ReverseSearcher, DoubleEndedSearcher}; use core::mem; use core::ptr; @@ -443,45 +441,6 @@ impl str { return s; } - /// Escapes each char in `s` with [`char::escape_debug`]. - /// - /// Note: only extended grapheme codepoints that begin the string will be - /// escaped. - /// - /// [`char::escape_debug`]: primitive.char.html#method.escape_debug - #[unstable(feature = "str_escape", - reason = "return type may change to be an iterator", - issue = "27791")] - pub fn escape_debug(&self) -> String { - let mut string = String::with_capacity(self.len()); - let mut chars = self.chars(); - if let Some(first) = chars.next() { - string.extend(first.escape_debug_ext(true)) - } - string.extend(chars.flat_map(|c| c.escape_debug_ext(false))); - string - } - - /// Escapes each char in `s` with [`char::escape_default`]. - /// - /// [`char::escape_default`]: primitive.char.html#method.escape_default - #[unstable(feature = "str_escape", - reason = "return type may change to be an iterator", - issue = "27791")] - pub fn escape_default(&self) -> String { - self.chars().flat_map(|c| c.escape_default()).collect() - } - - /// Escapes each char in `s` with [`char::escape_unicode`]. - /// - /// [`char::escape_unicode`]: primitive.char.html#method.escape_unicode - #[unstable(feature = "str_escape", - reason = "return type may change to be an iterator", - issue = "27791")] - pub fn escape_unicode(&self) -> String { - self.chars().flat_map(|c| c.escape_unicode()).collect() - } - /// Converts a [`Box<str>`] into a [`String`] without copying or allocating. /// /// [`String`]: string/struct.String.html @@ -612,3 +571,4 @@ impl str { pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> { Box::from_raw(Box::into_raw(v) as *mut str) } + diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 73f67e98f36..84c35c6f1bd 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -963,7 +963,7 @@ impl String { /// Does nothing if the capacity is already sufficient. /// /// Note that the allocator may give the collection more space than it - /// requests. Therefore capacity can not be relied upon to be precisely + /// requests. Therefore, capacity can not be relied upon to be precisely /// minimal. Prefer `reserve` if future insertions are expected. /// /// # Errors @@ -1377,9 +1377,7 @@ impl String { self.vec.len() } - /// Returns `true` if this `String` has a length of zero. - /// - /// Returns `false` otherwise. + /// Returns `true` if this `String` has a length of zero, and `false` otherwise. /// /// # Examples /// diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 5bdb3616ed2..b7d7995b540 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -560,7 +560,7 @@ impl<T: ?Sized> Arc<T> { #[inline] #[stable(feature = "ptr_eq", since = "1.17.0")] - /// Returns true if the two `Arc`s point to the same value (not + /// Returns `true` if the two `Arc`s point to the same value (not /// just values that compare as equal). /// /// # Examples @@ -1191,8 +1191,8 @@ impl<T: ?Sized> Weak<T> { }) } - /// Return `None` when the pointer is dangling and there is no allocated `ArcInner`, - /// i.e., this `Weak` was created by `Weak::new` + /// Returns `None` when the pointer is dangling and there is no allocated `ArcInner`, + /// (i.e., when this `Weak` was created by `Weak::new`). #[inline] fn inner(&self) -> Option<&ArcInner<T>> { if is_dangling(self.ptr) { @@ -1202,7 +1202,7 @@ impl<T: ?Sized> Weak<T> { } } - /// Returns true if the two `Weak`s point to the same value (not just values + /// Returns `true` if the two `Weak`s point to the same value (not just values /// that compare as equal). /// /// # Notes diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index 2759b1b1cac..7c5a8926126 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::any::Any; use std::sync::{Arc, Weak}; use std::cell::RefCell; diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs index 94ae43237d1..c1a1c5d8878 100644 --- a/src/liballoc/tests/binary_heap.rs +++ b/src/liballoc/tests/binary_heap.rs @@ -282,6 +282,7 @@ fn assert_covariance() { // // Destructors must be called exactly once per element. #[test] +#[cfg(not(miri))] fn panic_safe() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); diff --git a/src/liballoc/tests/btree/mod.rs b/src/liballoc/tests/btree/mod.rs index 4c704d0f8c2..653b3f5bcb4 100644 --- a/src/liballoc/tests/btree/mod.rs +++ b/src/liballoc/tests/btree/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + mod map; mod set; diff --git a/src/liballoc/tests/heap.rs b/src/liballoc/tests/heap.rs index 24eea1d2949..7bc1aac7c8b 100644 --- a/src/liballoc/tests/heap.rs +++ b/src/liballoc/tests/heap.rs @@ -1,6 +1,8 @@ +#![cfg(not(miri))] + use std::alloc::{Global, Alloc, Layout, System}; -/// https://github.com/rust-lang/rust/issues/45955 +/// Issue #45955. #[test] fn alloc_system_overaligned_request() { check_overalign_requests(System) diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index a76fd87a1a9..2b63ac5c7d2 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -5,7 +5,6 @@ #![feature(pattern)] #![feature(repeat_generic_slice)] #![feature(slice_sort_by_cached_key)] -#![feature(str_escape)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(vecdeque_rotate)] diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index 18f82e80410..1be01d1a7ce 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::any::Any; use std::rc::{Rc, Weak}; use std::cell::RefCell; diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 334466dfb25..2a9fdfa9324 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::cell::Cell; use std::cmp::Ordering::{self, Equal, Greater, Less}; use std::mem; diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index 1bc1bd8d78c..a1dc763f6d8 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -31,6 +31,7 @@ fn test_rfind() { } #[test] +#[cfg(not(miri))] fn test_collect() { let empty = ""; let s: String = empty.chars().collect(); @@ -118,6 +119,7 @@ fn test_concat_for_different_types() { #[test] fn test_concat_for_different_lengths() { let empty: &[&str] = &[]; + #[cfg(not(miri))] test_concat!("", empty); test_concat!("a", ["a"]); test_concat!("ab", ["a", "b"]); @@ -146,6 +148,7 @@ fn test_join_for_different_types() { #[test] fn test_join_for_different_lengths() { let empty: &[&str] = &[]; + #[cfg(not(miri))] test_join!("", empty, "-"); test_join!("a", ["a"], "-"); test_join!("a-b", ["a", "b"], "-"); @@ -159,6 +162,7 @@ fn test_join_for_different_lengths_with_long_separator() { assert_eq!("~~~~~".len(), 15); let empty: &[&str] = &[]; + #[cfg(not(miri))] test_join!("", empty, "~~~~~"); test_join!("a", ["a"], "~~~~~"); test_join!("a~~~~~b", ["a", "b"], "~~~~~"); @@ -166,6 +170,7 @@ fn test_join_for_different_lengths_with_long_separator() { } #[test] +#[cfg(not(miri))] fn test_unsafe_slice() { assert_eq!("ab", unsafe {"abc".get_unchecked(0..2)}); assert_eq!("bc", unsafe {"abc".get_unchecked(1..3)}); @@ -238,6 +243,7 @@ fn test_replacen() { #[test] fn test_replace() { let a = "a"; + #[cfg(not(miri))] assert_eq!("".replace(a, "b"), ""); assert_eq!("a".replace(a, "b"), "b"); assert_eq!("ab".replace(a, "b"), "bb"); @@ -297,6 +303,7 @@ fn test_replace_pattern() { // The current implementation of SliceIndex fails to handle methods // orthogonally from range types; therefore, it is worth testing // all of the indexing operations on each input. +#[cfg(not(miri))] mod slice_index { // Test a slicing operation **that should succeed,** // testing it on all of the indexing methods. @@ -679,6 +686,7 @@ fn test_str_slice_rangetoinclusive_ok() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_str_slice_rangetoinclusive_notok() { let s = "abcαβγ"; &s[..=3]; @@ -694,6 +702,7 @@ fn test_str_slicemut_rangetoinclusive_ok() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_str_slicemut_rangetoinclusive_notok() { let mut s = "abcαβγ".to_owned(); let s: &mut str = &mut s; @@ -883,6 +892,7 @@ fn test_as_bytes() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_as_bytes_fail() { // Don't double free. (I'm not sure if this exercises the // original problem code path anymore.) @@ -972,6 +982,7 @@ fn test_split_at_mut() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_split_at_boundscheck() { let s = "ศไทย中华Việt Nam"; s.split_at(1); @@ -979,15 +990,15 @@ fn test_split_at_boundscheck() { #[test] fn test_escape_unicode() { - assert_eq!("abc".escape_unicode(), "\\u{61}\\u{62}\\u{63}"); - assert_eq!("a c".escape_unicode(), "\\u{61}\\u{20}\\u{63}"); - assert_eq!("\r\n\t".escape_unicode(), "\\u{d}\\u{a}\\u{9}"); - assert_eq!("'\"\\".escape_unicode(), "\\u{27}\\u{22}\\u{5c}"); - assert_eq!("\x00\x01\u{fe}\u{ff}".escape_unicode(), "\\u{0}\\u{1}\\u{fe}\\u{ff}"); - assert_eq!("\u{100}\u{ffff}".escape_unicode(), "\\u{100}\\u{ffff}"); - assert_eq!("\u{10000}\u{10ffff}".escape_unicode(), "\\u{10000}\\u{10ffff}"); - assert_eq!("ab\u{fb00}".escape_unicode(), "\\u{61}\\u{62}\\u{fb00}"); - assert_eq!("\u{1d4ea}\r".escape_unicode(), "\\u{1d4ea}\\u{d}"); + assert_eq!("abc".escape_unicode().to_string(), "\\u{61}\\u{62}\\u{63}"); + assert_eq!("a c".escape_unicode().to_string(), "\\u{61}\\u{20}\\u{63}"); + assert_eq!("\r\n\t".escape_unicode().to_string(), "\\u{d}\\u{a}\\u{9}"); + assert_eq!("'\"\\".escape_unicode().to_string(), "\\u{27}\\u{22}\\u{5c}"); + assert_eq!("\x00\x01\u{fe}\u{ff}".escape_unicode().to_string(), "\\u{0}\\u{1}\\u{fe}\\u{ff}"); + assert_eq!("\u{100}\u{ffff}".escape_unicode().to_string(), "\\u{100}\\u{ffff}"); + assert_eq!("\u{10000}\u{10ffff}".escape_unicode().to_string(), "\\u{10000}\\u{10ffff}"); + assert_eq!("ab\u{fb00}".escape_unicode().to_string(), "\\u{61}\\u{62}\\u{fb00}"); + assert_eq!("\u{1d4ea}\r".escape_unicode().to_string(), "\\u{1d4ea}\\u{d}"); } #[test] @@ -998,31 +1009,32 @@ fn test_escape_debug() { // they are escaped. However, when the character is unescaped (e.g., for // printable characters), only a single backslash appears (as the character // itself appears in the debug string). - assert_eq!("abc".escape_debug(), "abc"); - assert_eq!("a c".escape_debug(), "a c"); - assert_eq!("éèê".escape_debug(), "éèê"); - assert_eq!("\r\n\t".escape_debug(), "\\r\\n\\t"); - assert_eq!("'\"\\".escape_debug(), "\\'\\\"\\\\"); - assert_eq!("\u{7f}\u{ff}".escape_debug(), "\\u{7f}\u{ff}"); - assert_eq!("\u{100}\u{ffff}".escape_debug(), "\u{100}\\u{ffff}"); - assert_eq!("\u{10000}\u{10ffff}".escape_debug(), "\u{10000}\\u{10ffff}"); - assert_eq!("ab\u{200b}".escape_debug(), "ab\\u{200b}"); - assert_eq!("\u{10d4ea}\r".escape_debug(), "\\u{10d4ea}\\r"); - assert_eq!("\u{301}a\u{301}bé\u{e000}".escape_debug(), "\\u{301}a\u{301}bé\\u{e000}"); + assert_eq!("abc".escape_debug().to_string(), "abc"); + assert_eq!("a c".escape_debug().to_string(), "a c"); + assert_eq!("éèê".escape_debug().to_string(), "éèê"); + assert_eq!("\r\n\t".escape_debug().to_string(), "\\r\\n\\t"); + assert_eq!("'\"\\".escape_debug().to_string(), "\\'\\\"\\\\"); + assert_eq!("\u{7f}\u{ff}".escape_debug().to_string(), "\\u{7f}\u{ff}"); + assert_eq!("\u{100}\u{ffff}".escape_debug().to_string(), "\u{100}\\u{ffff}"); + assert_eq!("\u{10000}\u{10ffff}".escape_debug().to_string(), "\u{10000}\\u{10ffff}"); + assert_eq!("ab\u{200b}".escape_debug().to_string(), "ab\\u{200b}"); + assert_eq!("\u{10d4ea}\r".escape_debug().to_string(), "\\u{10d4ea}\\r"); + assert_eq!("\u{301}a\u{301}bé\u{e000}".escape_debug().to_string(), + "\\u{301}a\u{301}bé\\u{e000}"); } #[test] fn test_escape_default() { - assert_eq!("abc".escape_default(), "abc"); - assert_eq!("a c".escape_default(), "a c"); - assert_eq!("éèê".escape_default(), "\\u{e9}\\u{e8}\\u{ea}"); - assert_eq!("\r\n\t".escape_default(), "\\r\\n\\t"); - assert_eq!("'\"\\".escape_default(), "\\'\\\"\\\\"); - assert_eq!("\u{7f}\u{ff}".escape_default(), "\\u{7f}\\u{ff}"); - assert_eq!("\u{100}\u{ffff}".escape_default(), "\\u{100}\\u{ffff}"); - assert_eq!("\u{10000}\u{10ffff}".escape_default(), "\\u{10000}\\u{10ffff}"); - assert_eq!("ab\u{200b}".escape_default(), "ab\\u{200b}"); - assert_eq!("\u{10d4ea}\r".escape_default(), "\\u{10d4ea}\\r"); + assert_eq!("abc".escape_default().to_string(), "abc"); + assert_eq!("a c".escape_default().to_string(), "a c"); + assert_eq!("éèê".escape_default().to_string(), "\\u{e9}\\u{e8}\\u{ea}"); + assert_eq!("\r\n\t".escape_default().to_string(), "\\r\\n\\t"); + assert_eq!("'\"\\".escape_default().to_string(), "\\'\\\"\\\\"); + assert_eq!("\u{7f}\u{ff}".escape_default().to_string(), "\\u{7f}\\u{ff}"); + assert_eq!("\u{100}\u{ffff}".escape_default().to_string(), "\\u{100}\\u{ffff}"); + assert_eq!("\u{10000}\u{10ffff}".escape_default().to_string(), "\\u{10000}\\u{10ffff}"); + assert_eq!("ab\u{200b}".escape_default().to_string(), "ab\\u{200b}"); + assert_eq!("\u{10d4ea}\r".escape_default().to_string(), "\\u{10d4ea}\\r"); } #[test] @@ -1066,6 +1078,7 @@ fn test_rev_iterator() { } #[test] +#[cfg(not(miri))] fn test_chars_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1077,6 +1090,7 @@ fn test_chars_decoding() { } #[test] +#[cfg(not(miri))] fn test_chars_rev_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1306,6 +1320,7 @@ fn test_splitator() { } #[test] +#[cfg(not(miri))] fn test_str_default() { use std::default::Default; @@ -1365,6 +1380,7 @@ fn test_bool_from_str() { assert_eq!("not even a boolean".parse::<bool>().ok(), None); } +#[cfg(not(miri))] fn check_contains_all_substrings(s: &str) { assert!(s.contains("")); for i in 0..s.len() { @@ -1375,6 +1391,7 @@ fn check_contains_all_substrings(s: &str) { } #[test] +#[cfg(not(miri))] fn strslice_issue_16589() { assert!("bananas".contains("nana")); @@ -1384,6 +1401,7 @@ fn strslice_issue_16589() { } #[test] +#[cfg(not(miri))] fn strslice_issue_16878() { assert!(!"1234567ah012345678901ah".contains("hah")); assert!(!"00abc01234567890123456789abc".contains("bcabc")); @@ -1391,6 +1409,7 @@ fn strslice_issue_16878() { #[test] +#[cfg(not(miri))] fn test_strslice_contains() { let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'"; check_contains_all_substrings(x); @@ -1528,6 +1547,7 @@ fn trim_ws() { #[test] fn to_lowercase() { + #[cfg(not(miri))] assert_eq!("".to_lowercase(), ""); assert_eq!("AÉDžaé ".to_lowercase(), "aédžaé "); @@ -1561,6 +1581,7 @@ fn to_lowercase() { #[test] fn to_uppercase() { + #[cfg(not(miri))] assert_eq!("".to_uppercase(), ""); assert_eq!("aéDžßfiᾀ".to_uppercase(), "AÉDŽSSFIἈΙ"); } @@ -1592,6 +1613,7 @@ fn test_cow_from() { } #[test] +#[cfg(not(miri))] fn test_repeat() { assert_eq!("".repeat(3), ""); assert_eq!("abc".repeat(0), ""); diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index e5ce51a36ee..e6ca54c4088 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::borrow::Cow; use std::collections::CollectionAllocErr::*; use std::mem::size_of; diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 89f2e0a046d..545332bcd6a 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::borrow::Cow; use std::mem::size_of; use std::{usize, isize}; diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index aa49bdb0090..b47e7c867e6 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -108,6 +108,7 @@ fn test_index() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_index_out_of_bounds() { let mut deq = VecDeque::new(); for i in 1..4 { @@ -906,20 +907,24 @@ fn test_append() { // normal append a.append(&mut b); assert_eq!(a.iter().cloned().collect::<Vec<_>>(), [1, 2, 3, 4, 5, 6]); + #[cfg(not(miri))] assert_eq!(b.iter().cloned().collect::<Vec<_>>(), []); // append nothing to something a.append(&mut b); assert_eq!(a.iter().cloned().collect::<Vec<_>>(), [1, 2, 3, 4, 5, 6]); + #[cfg(not(miri))] assert_eq!(b.iter().cloned().collect::<Vec<_>>(), []); // append something to nothing b.append(&mut a); assert_eq!(b.iter().cloned().collect::<Vec<_>>(), [1, 2, 3, 4, 5, 6]); + #[cfg(not(miri))] assert_eq!(a.iter().cloned().collect::<Vec<_>>(), []); } #[test] +#[cfg(not(miri))] fn test_append_permutations() { fn construct_vec_deque( push_back: usize, @@ -1120,6 +1125,7 @@ fn test_reserve_exact_2() { } #[test] +#[cfg(not(miri))] fn test_try_reserve() { // These are the interesting cases: @@ -1221,6 +1227,7 @@ fn test_try_reserve() { } #[test] +#[cfg(not(miri))] fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 57e10498b92..57723e4d212 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -463,7 +463,7 @@ impl<T> Vec<T> { /// Does nothing if the capacity is already sufficient. /// /// Note that the allocator may give the collection more space than it - /// requests. Therefore capacity can not be relied upon to be precisely + /// requests. Therefore, capacity can not be relied upon to be precisely /// minimal. Prefer `reserve` if future insertions are expected. /// /// # Panics @@ -525,7 +525,7 @@ impl<T> Vec<T> { /// Does nothing if the capacity is already sufficient. /// /// Note that the allocator may give the collection more space than it - /// requests. Therefore capacity can not be relied upon to be precisely + /// requests. Therefore, capacity can not be relied upon to be precisely /// minimal. Prefer `reserve` if future insertions are expected. /// /// # Errors @@ -738,7 +738,7 @@ impl<T> Vec<T> { /// Forces the length of the vector to `new_len`. /// /// This is a low-level operation that maintains none of the normal - /// invariants of the type. Normally changing the length of a vector + /// invariants of the type. Normally changing the length of a vector /// is done using one of the safe operations instead, such as /// [`truncate`], [`resize`], [`extend`], or [`clear`]. /// @@ -2608,7 +2608,7 @@ impl<T> Drain<'_, T> { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. /// Fill that range as much as possible with new elements from the `replace_with` iterator. - /// Return whether we filled the entire range. (`replace_with.next()` didn’t return `None`.) + /// Returns `true` if we filled the entire range. (`replace_with.next()` didn’t return `None`.) unsafe fn fill<I: Iterator<Item=T>>(&mut self, replace_with: &mut I) -> bool { let vec = self.vec.as_mut(); let range_start = vec.len; @@ -2628,7 +2628,7 @@ impl<T> Drain<'_, T> { true } - /// Make room for inserting more elements before the tail. + /// Makes room for inserting more elements before the tail. unsafe fn move_tail(&mut self, extra_capacity: usize) { let vec = self.vec.as_mut(); let used_capacity = self.tail_start + self.tail_len; |
