Auto merge of #40972 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests - Successful merges: #40703, #40728, #40763, #40871, #40935, #40947 - Failed merges:
This commit is contained in:
commit
2f1652870f
13 changed files with 137 additions and 41 deletions
|
@ -133,9 +133,15 @@ impl<S: Borrow<str>> SliceConcatExt<str> for [S] {
|
|||
}
|
||||
}
|
||||
|
||||
/// External iterator for a string's UTF-16 code units.
|
||||
/// An iterator of [`u16`] over the string encoded as UTF-16.
|
||||
///
|
||||
/// For use with the `std::iter` module.
|
||||
/// [`u16`]: ../../std/primitive.u16.html
|
||||
///
|
||||
/// This struct is created by the [`encode_utf16`] method on [`str`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`encode_utf16`]: ../../std/primitive.str.html#method.encode_utf16
|
||||
/// [`str`]: ../../std/primitive.str.html
|
||||
#[derive(Clone)]
|
||||
#[stable(feature = "encode_utf16", since = "1.8.0")]
|
||||
pub struct EncodeUtf16<'a> {
|
||||
|
|
|
@ -383,9 +383,11 @@ fn test_reverse() {
|
|||
|
||||
#[test]
|
||||
fn test_sort() {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
for len in (2..25).chain(500..510) {
|
||||
for _ in 0..100 {
|
||||
let mut v: Vec<_> = thread_rng().gen_iter::<i32>().take(len).collect();
|
||||
let mut v: Vec<_> = rng.gen_iter::<i32>().take(len).collect();
|
||||
let mut v1 = v.clone();
|
||||
|
||||
v.sort();
|
||||
|
@ -399,6 +401,18 @@ fn test_sort() {
|
|||
}
|
||||
}
|
||||
|
||||
// Sort using a completely random comparison function.
|
||||
// This will reorder the elements *somehow*, but won't panic.
|
||||
let mut v = [0; 500];
|
||||
for i in 0..v.len() {
|
||||
v[i] = i as i32;
|
||||
}
|
||||
v.sort_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
|
||||
v.sort();
|
||||
for i in 0..v.len() {
|
||||
assert_eq!(v[i], i as i32);
|
||||
}
|
||||
|
||||
// Should not panic.
|
||||
[0i32; 0].sort();
|
||||
[(); 10].sort();
|
||||
|
|
|
@ -369,11 +369,15 @@ impl fmt::Display for Utf8Error {
|
|||
Section: Iterators
|
||||
*/
|
||||
|
||||
/// Iterator for the char (representing *Unicode Scalar Values*) of a string.
|
||||
/// An iterator over the [`char`]s of a string slice.
|
||||
///
|
||||
/// Created with the method [`chars`].
|
||||
/// [`char`]: ../../std/primitive.char.html
|
||||
///
|
||||
/// This struct is created by the [`chars`] method on [`str`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`chars`]: ../../std/primitive.str.html#method.chars
|
||||
/// [`str`]: ../../std/primitive.str.html
|
||||
#[derive(Clone, Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Chars<'a> {
|
||||
|
@ -553,7 +557,15 @@ impl<'a> Chars<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Iterator for a string's characters and their byte offsets.
|
||||
/// An iterator over the [`char`]s of a string slice, and their positions.
|
||||
///
|
||||
/// [`char`]: ../../std/primitive.char.html
|
||||
///
|
||||
/// This struct is created by the [`char_indices`] method on [`str`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`char_indices`]: ../../std/primitive.str.html#method.char_indices
|
||||
/// [`str`]: ../../std/primitive.str.html
|
||||
#[derive(Clone, Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct CharIndices<'a> {
|
||||
|
@ -625,12 +637,13 @@ impl<'a> CharIndices<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// External iterator for a string's bytes.
|
||||
/// Use with the `std::iter` module.
|
||||
/// An iterator over the bytes of a string slice.
|
||||
///
|
||||
/// Created with the method [`bytes`].
|
||||
/// This struct is created by the [`bytes`] method on [`str`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`bytes`]: ../../std/primitive.str.html#method.bytes
|
||||
/// [`str`]: ../../std/primitive.str.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Bytes<'a>(Cloned<slice::Iter<'a, u8>>);
|
||||
|
@ -1161,9 +1174,13 @@ generate_pattern_iterators! {
|
|||
delegate double ended;
|
||||
}
|
||||
|
||||
/// Created with the method [`lines`].
|
||||
/// An iterator over the lines of a string, as string slices.
|
||||
///
|
||||
/// This struct is created with the [`lines`] method on [`str`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`lines`]: ../../std/primitive.str.html#method.lines
|
||||
/// [`str`]: ../../std/primitive.str.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Lines<'a>(Map<SplitTerminator<'a, char>, LinesAnyMap>);
|
||||
|
|
|
@ -15,27 +15,37 @@
|
|||
//! types.
|
||||
//!
|
||||
//! This module defines atomic versions of a select number of primitive
|
||||
//! types, including `AtomicBool`, `AtomicIsize`, and `AtomicUsize`.
|
||||
//! types, including [`AtomicBool`], [`AtomicIsize`], and [`AtomicUsize`].
|
||||
//! Atomic types present operations that, when used correctly, synchronize
|
||||
//! updates between threads.
|
||||
//!
|
||||
//! Each method takes an `Ordering` which represents the strength of
|
||||
//! [`AtomicBool`]: struct.AtomicBool.html
|
||||
//! [`AtomicIsize`]: struct.AtomicIsize.html
|
||||
//! [`AtomicUsize`]: struct.AtomicUsize.html
|
||||
//!
|
||||
//! Each method takes an [`Ordering`] which represents the strength of
|
||||
//! the memory barrier for that operation. These orderings are the
|
||||
//! same as [LLVM atomic orderings][1]. For more information see the [nomicon][2].
|
||||
//!
|
||||
//! [`Ordering`]: enum.Ordering.html
|
||||
//!
|
||||
//! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations
|
||||
//! [2]: ../../../nomicon/atomics.html
|
||||
//!
|
||||
//! Atomic variables are safe to share between threads (they implement `Sync`)
|
||||
//! Atomic variables are safe to share between threads (they implement [`Sync`])
|
||||
//! but they do not themselves provide the mechanism for sharing and follow the
|
||||
//! [threading model](../../../std/thread/index.html#the-threading-model) of rust.
|
||||
//! The most common way to share an atomic variable is to put it into an `Arc` (an
|
||||
//! The most common way to share an atomic variable is to put it into an [`Arc`][arc] (an
|
||||
//! atomically-reference-counted shared pointer).
|
||||
//!
|
||||
//! [`Sync`]: ../../marker/trait.Sync.html
|
||||
//! [arc]: ../../../std/sync/struct.Arc.html
|
||||
//!
|
||||
//! Most atomic types may be stored in static variables, initialized using
|
||||
//! the provided static initializers like `ATOMIC_BOOL_INIT`. Atomic statics
|
||||
//! the provided static initializers like [`ATOMIC_BOOL_INIT`]. Atomic statics
|
||||
//! are often used for lazy global initialization.
|
||||
//!
|
||||
//! [`ATOMIC_BOOL_INIT`]: constant.ATOMIC_BOOL_INIT.html
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
|
@ -148,22 +158,32 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Ordering {
|
||||
/// No ordering constraints, only atomic operations. Corresponds to LLVM's
|
||||
/// `Monotonic` ordering.
|
||||
/// No ordering constraints, only atomic operations.
|
||||
///
|
||||
/// Corresponds to LLVM's [`Monotonic`] ordering.
|
||||
///
|
||||
/// [`Monotonic`]: http://llvm.org/docs/Atomics.html#monotonic
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Relaxed,
|
||||
/// When coupled with a store, all previous writes become visible
|
||||
/// to the other threads that perform a load with `Acquire` ordering
|
||||
/// to the other threads that perform a load with [`Acquire`] ordering
|
||||
/// on the same value.
|
||||
///
|
||||
/// [`Acquire`]: http://llvm.org/docs/Atomics.html#acquire
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Release,
|
||||
/// When coupled with a load, all subsequent loads will see data
|
||||
/// written before a store with `Release` ordering on the same value
|
||||
/// written before a store with [`Release`] ordering on the same value
|
||||
/// in other threads.
|
||||
///
|
||||
/// [`Release`]: http://llvm.org/docs/Atomics.html#release
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Acquire,
|
||||
/// When coupled with a load, uses `Acquire` ordering, and with a store
|
||||
/// `Release` ordering.
|
||||
/// When coupled with a load, uses [`Acquire`] ordering, and with a store
|
||||
/// [`Release`] ordering.
|
||||
///
|
||||
/// [`Acquire`]: http://llvm.org/docs/Atomics.html#acquire
|
||||
/// [`Release`]: http://llvm.org/docs/Atomics.html#release
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
AcqRel,
|
||||
/// Like `AcqRel` with the additional guarantee that all threads see all
|
||||
|
@ -176,7 +196,9 @@ pub enum Ordering {
|
|||
__Nonexhaustive,
|
||||
}
|
||||
|
||||
/// An `AtomicBool` initialized to `false`.
|
||||
/// An [`AtomicBool`] initialized to `false`.
|
||||
///
|
||||
/// [`AtomicBool`]: struct.AtomicBool.html
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const ATOMIC_BOOL_INIT: AtomicBool = AtomicBool::new(false);
|
||||
|
@ -250,7 +272,7 @@ impl AtomicBool {
|
|||
///
|
||||
/// [`Ordering`]: enum.Ordering.html
|
||||
/// [`Release`]: enum.Ordering.html#variant.Release
|
||||
/// [`AcqRel`]: enum.Ordering.html#variant.Release
|
||||
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -287,7 +309,10 @@ impl AtomicBool {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `order` is `Acquire` or `AcqRel`.
|
||||
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
|
||||
///
|
||||
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
|
||||
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn store(&self, val: bool, order: Ordering) {
|
||||
|
@ -404,7 +429,7 @@ impl AtomicBool {
|
|||
|
||||
/// Stores a value into the `bool` if the current value is the same as the `current` value.
|
||||
///
|
||||
/// Unlike `compare_exchange`, this function is allowed to spuriously fail even when the
|
||||
/// Unlike [`compare_exchange`], this function is allowed to spuriously fail even when the
|
||||
/// comparison succeeds, which can result in more efficient code on some platforms. The
|
||||
/// return value is a result indicating whether the new value was written and containing the
|
||||
/// previous value.
|
||||
|
@ -415,6 +440,7 @@ impl AtomicBool {
|
|||
/// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or
|
||||
/// weaker than the success ordering.
|
||||
///
|
||||
/// [`compare_exchange`]: #method.compare_exchange
|
||||
/// [`Ordering`]: enum.Ordering.html
|
||||
/// [`Release`]: enum.Ordering.html#variant.Release
|
||||
/// [`AcqRel`]: enum.Ordering.html#variant.Release
|
||||
|
@ -694,7 +720,10 @@ impl<T> AtomicPtr<T> {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `order` is `Acquire` or `AcqRel`.
|
||||
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
|
||||
///
|
||||
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
|
||||
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn store(&self, ptr: *mut T, order: Ordering) {
|
||||
|
@ -1008,7 +1037,10 @@ macro_rules! atomic_int {
|
|||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `order` is `Acquire` or `AcqRel`.
|
||||
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
|
||||
///
|
||||
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
|
||||
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
|
||||
#[inline]
|
||||
#[$stable]
|
||||
pub fn store(&self, val: $int_type, order: Ordering) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::cmp::Ordering::{Equal, Greater, Less};
|
||||
use core::slice::heapsort;
|
||||
use core::result::Result::{Ok, Err};
|
||||
use rand::{Rng, XorShiftRng};
|
||||
|
@ -268,6 +269,17 @@ fn sort_unstable() {
|
|||
}
|
||||
}
|
||||
|
||||
// Sort using a completely random comparison function.
|
||||
// This will reorder the elements *somehow*, but won't panic.
|
||||
for i in 0..v.len() {
|
||||
v[i] = i as i32;
|
||||
}
|
||||
v.sort_unstable_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
|
||||
v.sort_unstable();
|
||||
for i in 0..v.len() {
|
||||
assert_eq!(v[i], i as i32);
|
||||
}
|
||||
|
||||
// Should not panic.
|
||||
[0i32; 0].sort_unstable();
|
||||
[(); 10].sort_unstable();
|
||||
|
|
|
@ -196,10 +196,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
|||
id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
|
||||
reference: "issue #36888 <https://github.com/rust-lang/rust/issues/36888>",
|
||||
},
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
|
||||
reference: "issue #36889 <https://github.com/rust-lang/rust/issues/36889>",
|
||||
},
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
|
||||
reference: "issue #36890 <https://github.com/rust-lang/rust/issues/36890>",
|
||||
|
@ -263,4 +259,5 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
|||
store.register_removed("drop_with_repr_extern", "drop flags have been removed");
|
||||
store.register_removed("transmute_from_fn_item_types",
|
||||
"always cast functions before transmuting them");
|
||||
store.register_removed("overlapping_inherent_impls", "converted into hard error, see #36889");
|
||||
}
|
||||
|
|
|
@ -322,4 +322,3 @@ impl<'a, 'tcx> InherentCollect<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4212,4 +4212,5 @@ register_diagnostics! {
|
|||
// but `{}` was found in the type `{}`
|
||||
E0567, // auto traits can not have type parameters
|
||||
E0568, // auto-traits can not have predicates,
|
||||
E0592, // duplicate definitions with name `{}`
|
||||
}
|
||||
|
|
|
@ -145,6 +145,18 @@
|
|||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! Note that you cannot use the `?` operator in functions that do not return
|
||||
//! a `Result<T, E>` (e.g. `main`). Instead, you can call `.unwrap()` or `match`
|
||||
//! on the return value to catch any possible errors:
|
||||
//!
|
||||
//! ```
|
||||
//! use std::io;
|
||||
//!
|
||||
//! let mut input = String::new();
|
||||
//!
|
||||
//! io::stdin().read_line(&mut input).unwrap();
|
||||
//! ```
|
||||
//!
|
||||
//! And a very common source of output is standard output:
|
||||
//!
|
||||
//! ```
|
||||
|
|
|
@ -183,9 +183,9 @@ mod prim_unit { }
|
|||
/// Working with raw pointers in Rust is uncommon,
|
||||
/// typically limited to a few patterns.
|
||||
///
|
||||
/// Use the `null` function to create null pointers, and the `is_null` method
|
||||
/// Use the [`null`] function to create null pointers, and the [`is_null`] method
|
||||
/// of the `*const T` type to check for null. The `*const T` type also defines
|
||||
/// the `offset` method, for pointer math.
|
||||
/// the [`offset`] method, for pointer math.
|
||||
///
|
||||
/// # Common ways to create raw pointers
|
||||
///
|
||||
|
@ -213,7 +213,7 @@ mod prim_unit { }
|
|||
///
|
||||
/// ## 2. Consume a box (`Box<T>`).
|
||||
///
|
||||
/// The `into_raw` function consumes a box and returns
|
||||
/// The [`into_raw`] function consumes a box and returns
|
||||
/// the raw pointer. It doesn't destroy `T` or deallocate any memory.
|
||||
///
|
||||
/// ```
|
||||
|
@ -227,7 +227,7 @@ mod prim_unit { }
|
|||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Note that here the call to `drop` is for clarity - it indicates
|
||||
/// Note that here the call to [`drop`] is for clarity - it indicates
|
||||
/// that we are done with the given value and it should be destroyed.
|
||||
///
|
||||
/// ## 3. Get it from C.
|
||||
|
@ -255,6 +255,11 @@ mod prim_unit { }
|
|||
///
|
||||
/// *[See also the `std::ptr` module](ptr/index.html).*
|
||||
///
|
||||
/// [`null`]: ../std/ptr/fn.null.html
|
||||
/// [`is_null`]: ../std/primitive.pointer.html#method.is_null
|
||||
/// [`offset`]: ../std/primitive.pointer.html#method.offset
|
||||
/// [`into_raw`]: ../std/boxed/struct.Box.html#method.into_raw
|
||||
/// [`drop`]: ../std/mem/fn.drop.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
mod prim_pointer { }
|
||||
|
||||
|
|
|
@ -19,6 +19,12 @@ use core::str::Split;
|
|||
|
||||
/// An iterator over the non-whitespace substrings of a string,
|
||||
/// separated by any amount of whitespace.
|
||||
///
|
||||
/// This struct is created by the [`split_whitespace`] method on [`str`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`split_whitespace`]: ../../std/primitive.str.html#method.split_whitespace
|
||||
/// [`str`]: ../../std/primitive.str.html
|
||||
#[stable(feature = "split_whitespace", since = "1.1.0")]
|
||||
pub struct SplitWhitespace<'a> {
|
||||
inner: Filter<Split<'a, fn(char) -> bool>, fn(&&str) -> bool>,
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![deny(overlapping_inherent_impls)]
|
||||
|
||||
trait C {}
|
||||
impl C { fn f() {} } //~ ERROR duplicate definitions with name `f`
|
||||
//~^ WARN: this was previously accepted
|
||||
impl C { fn f() {} }
|
||||
fn main() { }
|
||||
|
|
|
@ -17,7 +17,6 @@ struct Foo;
|
|||
|
||||
impl Foo {
|
||||
fn id() {} //~ ERROR duplicate definitions
|
||||
//~^ WARN previously accepted
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
|
@ -28,7 +27,6 @@ struct Bar<T>(T);
|
|||
|
||||
impl<T> Bar<T> {
|
||||
fn bar(&self) {} //~ ERROR duplicate definitions
|
||||
//~^ WARN previously accepted
|
||||
}
|
||||
|
||||
impl Bar<u32> {
|
||||
|
@ -39,7 +37,6 @@ struct Baz<T>(T);
|
|||
|
||||
impl<T: Copy> Baz<T> {
|
||||
fn baz(&self) {} //~ ERROR duplicate definitions
|
||||
//~^ WARN previously accepted
|
||||
}
|
||||
|
||||
impl<T> Baz<Vec<T>> {
|
||||
|
|
Loading…
Add table
Reference in a new issue