Skip to content

Commit 2f16528

Browse files
committed
Auto merge of #40972 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests - Successful merges: #40703, #40728, #40763, #40871, #40935, #40947 - Failed merges:
2 parents 40feadb + 54b3f6a commit 2f16528

File tree

13 files changed

+137
-41
lines changed

13 files changed

+137
-41
lines changed

src/libcollections/str.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,15 @@ impl<S: Borrow<str>> SliceConcatExt<str> for [S] {
133133
}
134134
}
135135

136-
/// External iterator for a string's UTF-16 code units.
136+
/// An iterator of [`u16`] over the string encoded as UTF-16.
137137
///
138-
/// For use with the `std::iter` module.
138+
/// [`u16`]: ../../std/primitive.u16.html
139+
///
140+
/// This struct is created by the [`encode_utf16`] method on [`str`].
141+
/// See its documentation for more.
142+
///
143+
/// [`encode_utf16`]: ../../std/primitive.str.html#method.encode_utf16
144+
/// [`str`]: ../../std/primitive.str.html
139145
#[derive(Clone)]
140146
#[stable(feature = "encode_utf16", since = "1.8.0")]
141147
pub struct EncodeUtf16<'a> {

src/libcollectionstest/slice.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,11 @@ fn test_reverse() {
383383

384384
#[test]
385385
fn test_sort() {
386+
let mut rng = thread_rng();
387+
386388
for len in (2..25).chain(500..510) {
387389
for _ in 0..100 {
388-
let mut v: Vec<_> = thread_rng().gen_iter::<i32>().take(len).collect();
390+
let mut v: Vec<_> = rng.gen_iter::<i32>().take(len).collect();
389391
let mut v1 = v.clone();
390392

391393
v.sort();
@@ -399,6 +401,18 @@ fn test_sort() {
399401
}
400402
}
401403

404+
// Sort using a completely random comparison function.
405+
// This will reorder the elements *somehow*, but won't panic.
406+
let mut v = [0; 500];
407+
for i in 0..v.len() {
408+
v[i] = i as i32;
409+
}
410+
v.sort_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
411+
v.sort();
412+
for i in 0..v.len() {
413+
assert_eq!(v[i], i as i32);
414+
}
415+
402416
// Should not panic.
403417
[0i32; 0].sort();
404418
[(); 10].sort();

src/libcore/str/mod.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,15 @@ impl fmt::Display for Utf8Error {
369369
Section: Iterators
370370
*/
371371

372-
/// Iterator for the char (representing *Unicode Scalar Values*) of a string.
372+
/// An iterator over the [`char`]s of a string slice.
373373
///
374-
/// Created with the method [`chars`].
374+
/// [`char`]: ../../std/primitive.char.html
375+
///
376+
/// This struct is created by the [`chars`] method on [`str`].
377+
/// See its documentation for more.
375378
///
376379
/// [`chars`]: ../../std/primitive.str.html#method.chars
380+
/// [`str`]: ../../std/primitive.str.html
377381
#[derive(Clone, Debug)]
378382
#[stable(feature = "rust1", since = "1.0.0")]
379383
pub struct Chars<'a> {
@@ -553,7 +557,15 @@ impl<'a> Chars<'a> {
553557
}
554558
}
555559

556-
/// Iterator for a string's characters and their byte offsets.
560+
/// An iterator over the [`char`]s of a string slice, and their positions.
561+
///
562+
/// [`char`]: ../../std/primitive.char.html
563+
///
564+
/// This struct is created by the [`char_indices`] method on [`str`].
565+
/// See its documentation for more.
566+
///
567+
/// [`char_indices`]: ../../std/primitive.str.html#method.char_indices
568+
/// [`str`]: ../../std/primitive.str.html
557569
#[derive(Clone, Debug)]
558570
#[stable(feature = "rust1", since = "1.0.0")]
559571
pub struct CharIndices<'a> {
@@ -625,12 +637,13 @@ impl<'a> CharIndices<'a> {
625637
}
626638
}
627639

628-
/// External iterator for a string's bytes.
629-
/// Use with the `std::iter` module.
640+
/// An iterator over the bytes of a string slice.
630641
///
631-
/// Created with the method [`bytes`].
642+
/// This struct is created by the [`bytes`] method on [`str`].
643+
/// See its documentation for more.
632644
///
633645
/// [`bytes`]: ../../std/primitive.str.html#method.bytes
646+
/// [`str`]: ../../std/primitive.str.html
634647
#[stable(feature = "rust1", since = "1.0.0")]
635648
#[derive(Clone, Debug)]
636649
pub struct Bytes<'a>(Cloned<slice::Iter<'a, u8>>);
@@ -1161,9 +1174,13 @@ generate_pattern_iterators! {
11611174
delegate double ended;
11621175
}
11631176

1164-
/// Created with the method [`lines`].
1177+
/// An iterator over the lines of a string, as string slices.
1178+
///
1179+
/// This struct is created with the [`lines`] method on [`str`].
1180+
/// See its documentation for more.
11651181
///
11661182
/// [`lines`]: ../../std/primitive.str.html#method.lines
1183+
/// [`str`]: ../../std/primitive.str.html
11671184
#[stable(feature = "rust1", since = "1.0.0")]
11681185
#[derive(Clone, Debug)]
11691186
pub struct Lines<'a>(Map<SplitTerminator<'a, char>, LinesAnyMap>);

src/libcore/sync/atomic.rs

+49-17
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,37 @@
1515
//! types.
1616
//!
1717
//! This module defines atomic versions of a select number of primitive
18-
//! types, including `AtomicBool`, `AtomicIsize`, and `AtomicUsize`.
18+
//! types, including [`AtomicBool`], [`AtomicIsize`], and [`AtomicUsize`].
1919
//! Atomic types present operations that, when used correctly, synchronize
2020
//! updates between threads.
2121
//!
22-
//! Each method takes an `Ordering` which represents the strength of
22+
//! [`AtomicBool`]: struct.AtomicBool.html
23+
//! [`AtomicIsize`]: struct.AtomicIsize.html
24+
//! [`AtomicUsize`]: struct.AtomicUsize.html
25+
//!
26+
//! Each method takes an [`Ordering`] which represents the strength of
2327
//! the memory barrier for that operation. These orderings are the
2428
//! same as [LLVM atomic orderings][1]. For more information see the [nomicon][2].
2529
//!
30+
//! [`Ordering`]: enum.Ordering.html
31+
//!
2632
//! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations
2733
//! [2]: ../../../nomicon/atomics.html
2834
//!
29-
//! Atomic variables are safe to share between threads (they implement `Sync`)
35+
//! Atomic variables are safe to share between threads (they implement [`Sync`])
3036
//! but they do not themselves provide the mechanism for sharing and follow the
3137
//! [threading model](../../../std/thread/index.html#the-threading-model) of rust.
32-
//! The most common way to share an atomic variable is to put it into an `Arc` (an
38+
//! The most common way to share an atomic variable is to put it into an [`Arc`][arc] (an
3339
//! atomically-reference-counted shared pointer).
3440
//!
41+
//! [`Sync`]: ../../marker/trait.Sync.html
42+
//! [arc]: ../../../std/sync/struct.Arc.html
43+
//!
3544
//! Most atomic types may be stored in static variables, initialized using
36-
//! the provided static initializers like `ATOMIC_BOOL_INIT`. Atomic statics
45+
//! the provided static initializers like [`ATOMIC_BOOL_INIT`]. Atomic statics
3746
//! are often used for lazy global initialization.
3847
//!
48+
//! [`ATOMIC_BOOL_INIT`]: constant.ATOMIC_BOOL_INIT.html
3949
//!
4050
//! # Examples
4151
//!
@@ -148,22 +158,32 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
148158
#[stable(feature = "rust1", since = "1.0.0")]
149159
#[derive(Copy, Clone, Debug)]
150160
pub enum Ordering {
151-
/// No ordering constraints, only atomic operations. Corresponds to LLVM's
152-
/// `Monotonic` ordering.
161+
/// No ordering constraints, only atomic operations.
162+
///
163+
/// Corresponds to LLVM's [`Monotonic`] ordering.
164+
///
165+
/// [`Monotonic`]: http://llvm.org/docs/Atomics.html#monotonic
153166
#[stable(feature = "rust1", since = "1.0.0")]
154167
Relaxed,
155168
/// When coupled with a store, all previous writes become visible
156-
/// to the other threads that perform a load with `Acquire` ordering
169+
/// to the other threads that perform a load with [`Acquire`] ordering
157170
/// on the same value.
171+
///
172+
/// [`Acquire`]: http://llvm.org/docs/Atomics.html#acquire
158173
#[stable(feature = "rust1", since = "1.0.0")]
159174
Release,
160175
/// When coupled with a load, all subsequent loads will see data
161-
/// written before a store with `Release` ordering on the same value
176+
/// written before a store with [`Release`] ordering on the same value
162177
/// in other threads.
178+
///
179+
/// [`Release`]: http://llvm.org/docs/Atomics.html#release
163180
#[stable(feature = "rust1", since = "1.0.0")]
164181
Acquire,
165-
/// When coupled with a load, uses `Acquire` ordering, and with a store
166-
/// `Release` ordering.
182+
/// When coupled with a load, uses [`Acquire`] ordering, and with a store
183+
/// [`Release`] ordering.
184+
///
185+
/// [`Acquire`]: http://llvm.org/docs/Atomics.html#acquire
186+
/// [`Release`]: http://llvm.org/docs/Atomics.html#release
167187
#[stable(feature = "rust1", since = "1.0.0")]
168188
AcqRel,
169189
/// Like `AcqRel` with the additional guarantee that all threads see all
@@ -176,7 +196,9 @@ pub enum Ordering {
176196
__Nonexhaustive,
177197
}
178198

179-
/// An `AtomicBool` initialized to `false`.
199+
/// An [`AtomicBool`] initialized to `false`.
200+
///
201+
/// [`AtomicBool`]: struct.AtomicBool.html
180202
#[cfg(target_has_atomic = "8")]
181203
#[stable(feature = "rust1", since = "1.0.0")]
182204
pub const ATOMIC_BOOL_INIT: AtomicBool = AtomicBool::new(false);
@@ -250,7 +272,7 @@ impl AtomicBool {
250272
///
251273
/// [`Ordering`]: enum.Ordering.html
252274
/// [`Release`]: enum.Ordering.html#variant.Release
253-
/// [`AcqRel`]: enum.Ordering.html#variant.Release
275+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
254276
///
255277
/// # Examples
256278
///
@@ -287,7 +309,10 @@ impl AtomicBool {
287309
///
288310
/// # Panics
289311
///
290-
/// Panics if `order` is `Acquire` or `AcqRel`.
312+
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
313+
///
314+
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
315+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
291316
#[inline]
292317
#[stable(feature = "rust1", since = "1.0.0")]
293318
pub fn store(&self, val: bool, order: Ordering) {
@@ -404,7 +429,7 @@ impl AtomicBool {
404429

405430
/// Stores a value into the `bool` if the current value is the same as the `current` value.
406431
///
407-
/// Unlike `compare_exchange`, this function is allowed to spuriously fail even when the
432+
/// Unlike [`compare_exchange`], this function is allowed to spuriously fail even when the
408433
/// comparison succeeds, which can result in more efficient code on some platforms. The
409434
/// return value is a result indicating whether the new value was written and containing the
410435
/// previous value.
@@ -415,6 +440,7 @@ impl AtomicBool {
415440
/// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or
416441
/// weaker than the success ordering.
417442
///
443+
/// [`compare_exchange`]: #method.compare_exchange
418444
/// [`Ordering`]: enum.Ordering.html
419445
/// [`Release`]: enum.Ordering.html#variant.Release
420446
/// [`AcqRel`]: enum.Ordering.html#variant.Release
@@ -694,7 +720,10 @@ impl<T> AtomicPtr<T> {
694720
///
695721
/// # Panics
696722
///
697-
/// Panics if `order` is `Acquire` or `AcqRel`.
723+
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
724+
///
725+
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
726+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
698727
#[inline]
699728
#[stable(feature = "rust1", since = "1.0.0")]
700729
pub fn store(&self, ptr: *mut T, order: Ordering) {
@@ -1008,7 +1037,10 @@ macro_rules! atomic_int {
10081037
///
10091038
/// # Panics
10101039
///
1011-
/// Panics if `order` is `Acquire` or `AcqRel`.
1040+
/// Panics if `order` is [`Acquire`] or [`AcqRel`].
1041+
///
1042+
/// [`Acquire`]: enum.Ordering.html#variant.Acquire
1043+
/// [`AcqRel`]: enum.Ordering.html#variant.AcqRel
10121044
#[inline]
10131045
#[$stable]
10141046
pub fn store(&self, val: $int_type, order: Ordering) {

src/libcoretest/slice.rs

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use core::cmp::Ordering::{Equal, Greater, Less};
1112
use core::slice::heapsort;
1213
use core::result::Result::{Ok, Err};
1314
use rand::{Rng, XorShiftRng};
@@ -268,6 +269,17 @@ fn sort_unstable() {
268269
}
269270
}
270271

272+
// Sort using a completely random comparison function.
273+
// This will reorder the elements *somehow*, but won't panic.
274+
for i in 0..v.len() {
275+
v[i] = i as i32;
276+
}
277+
v.sort_unstable_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
278+
v.sort_unstable();
279+
for i in 0..v.len() {
280+
assert_eq!(v[i], i as i32);
281+
}
282+
271283
// Should not panic.
272284
[0i32; 0].sort_unstable();
273285
[(); 10].sort_unstable();

src/librustc_lint/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
196196
id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
197197
reference: "issue #36888 <https://github.com/rust-lang/rust/issues/36888>",
198198
},
199-
FutureIncompatibleInfo {
200-
id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
201-
reference: "issue #36889 <https://github.com/rust-lang/rust/issues/36889>",
202-
},
203199
FutureIncompatibleInfo {
204200
id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
205201
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>) {
263259
store.register_removed("drop_with_repr_extern", "drop flags have been removed");
264260
store.register_removed("transmute_from_fn_item_types",
265261
"always cast functions before transmuting them");
262+
store.register_removed("overlapping_inherent_impls", "converted into hard error, see #36889");
266263
}

src/librustc_typeck/coherence/inherent_impls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,3 @@ impl<'a, 'tcx> InherentCollect<'a, 'tcx> {
322322
}
323323
}
324324
}
325-

src/librustc_typeck/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4212,4 +4212,5 @@ register_diagnostics! {
42124212
// but `{}` was found in the type `{}`
42134213
E0567, // auto traits can not have type parameters
42144214
E0568, // auto-traits can not have predicates,
4215+
E0592, // duplicate definitions with name `{}`
42154216
}

src/libstd/io/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@
145145
//! # }
146146
//! ```
147147
//!
148+
//! Note that you cannot use the `?` operator in functions that do not return
149+
//! a `Result<T, E>` (e.g. `main`). Instead, you can call `.unwrap()` or `match`
150+
//! on the return value to catch any possible errors:
151+
//!
152+
//! ```
153+
//! use std::io;
154+
//!
155+
//! let mut input = String::new();
156+
//!
157+
//! io::stdin().read_line(&mut input).unwrap();
158+
//! ```
159+
//!
148160
//! And a very common source of output is standard output:
149161
//!
150162
//! ```

src/libstd/primitive_docs.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ mod prim_unit { }
183183
/// Working with raw pointers in Rust is uncommon,
184184
/// typically limited to a few patterns.
185185
///
186-
/// Use the `null` function to create null pointers, and the `is_null` method
186+
/// Use the [`null`] function to create null pointers, and the [`is_null`] method
187187
/// of the `*const T` type to check for null. The `*const T` type also defines
188-
/// the `offset` method, for pointer math.
188+
/// the [`offset`] method, for pointer math.
189189
///
190190
/// # Common ways to create raw pointers
191191
///
@@ -213,7 +213,7 @@ mod prim_unit { }
213213
///
214214
/// ## 2. Consume a box (`Box<T>`).
215215
///
216-
/// The `into_raw` function consumes a box and returns
216+
/// The [`into_raw`] function consumes a box and returns
217217
/// the raw pointer. It doesn't destroy `T` or deallocate any memory.
218218
///
219219
/// ```
@@ -227,7 +227,7 @@ mod prim_unit { }
227227
/// }
228228
/// ```
229229
///
230-
/// Note that here the call to `drop` is for clarity - it indicates
230+
/// Note that here the call to [`drop`] is for clarity - it indicates
231231
/// that we are done with the given value and it should be destroyed.
232232
///
233233
/// ## 3. Get it from C.
@@ -255,6 +255,11 @@ mod prim_unit { }
255255
///
256256
/// *[See also the `std::ptr` module](ptr/index.html).*
257257
///
258+
/// [`null`]: ../std/ptr/fn.null.html
259+
/// [`is_null`]: ../std/primitive.pointer.html#method.is_null
260+
/// [`offset`]: ../std/primitive.pointer.html#method.offset
261+
/// [`into_raw`]: ../std/boxed/struct.Box.html#method.into_raw
262+
/// [`drop`]: ../std/mem/fn.drop.html
258263
#[stable(feature = "rust1", since = "1.0.0")]
259264
mod prim_pointer { }
260265

src/libstd_unicode/u_str.rs

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ use core::str::Split;
1919

2020
/// An iterator over the non-whitespace substrings of a string,
2121
/// separated by any amount of whitespace.
22+
///
23+
/// This struct is created by the [`split_whitespace`] method on [`str`].
24+
/// See its documentation for more.
25+
///
26+
/// [`split_whitespace`]: ../../std/primitive.str.html#method.split_whitespace
27+
/// [`str`]: ../../std/primitive.str.html
2228
#[stable(feature = "split_whitespace", since = "1.1.0")]
2329
pub struct SplitWhitespace<'a> {
2430
inner: Filter<Split<'a, fn(char) -> bool>, fn(&&str) -> bool>,

0 commit comments

Comments
 (0)