Skip to content

Commit 7e5583b

Browse files
committed
Merge remote-tracking branch 'origin/master' into miri
2 parents 0f6b5b0 + 5f3bd73 commit 7e5583b

File tree

519 files changed

+11741
-3361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

519 files changed

+11741
-3361
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
src/etc/installer/gfx/* binary
88
*.woff binary
99
src/vendor/** -text
10+
Cargo.lock -merge

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ will run all the tests on every platform we support. If it all works out,
336336

337337
Speaking of tests, Rust has a comprehensive test suite. More information about
338338
it can be found
339-
[here](https://github.com/rust-lang/rust-wiki-backup/blob/master/Note-testsuite.md).
339+
[here](https://github.com/rust-lang/rust/blob/master/src/test/COMPILER_TESTS.md).
340340

341341
### External Dependencies
342342
[external-dependencies]: #external-dependencies

src/doc/not_found.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Some things that might be helpful to you though:
1313

1414
# Search
1515

16-
* <form action="https://duckduckgo.com/">
16+
<form action="https://duckduckgo.com/">
1717
<input type="text" id="site-search" name="q" size="80"></input>
18-
<input type="submit" value="Search DuckDuckGo">
19-
</form>
20-
* Rust doc search: <span id="core-search"></span>
18+
<input type="submit" value="Search DuckDuckGo"></form>
19+
20+
Rust doc search: <span id="core-search"></span>
2121

2222
# Reference
2323

24-
* [The Rust official site](https://www.rust-lang.org)
25-
* [The Rust reference](https://doc.rust-lang.org/reference/index.html)
24+
* [The Rust official site](https://www.rust-lang.org)
25+
* [The Rust reference](https://doc.rust-lang.org/reference/index.html)
2626

2727
# Docs
2828

29-
* [The standard library](https://doc.rust-lang.org/std/)
29+
[The standard library](https://doc.rust-lang.org/std/)
3030

3131
<script>
3232
function get_url_fragments() {

src/liballoc/allocator.rs

+9-37
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,8 @@ impl Layout {
217217
/// On arithmetic overflow, returns `None`.
218218
#[inline]
219219
pub fn repeat(&self, n: usize) -> Option<(Self, usize)> {
220-
let padded_size = match self.size.checked_add(self.padding_needed_for(self.align)) {
221-
None => return None,
222-
Some(padded_size) => padded_size,
223-
};
224-
let alloc_size = match padded_size.checked_mul(n) {
225-
None => return None,
226-
Some(alloc_size) => alloc_size,
227-
};
220+
let padded_size = self.size.checked_add(self.padding_needed_for(self.align))?;
221+
let alloc_size = padded_size.checked_mul(n)?;
228222

229223
// We can assume that `self.align` is a power-of-two that does
230224
// not exceed 2<sup>31</sup>. Furthermore, `alloc_size` has already been
@@ -246,26 +240,14 @@ impl Layout {
246240
/// On arithmetic overflow, returns `None`.
247241
pub fn extend(&self, next: Self) -> Option<(Self, usize)> {
248242
let new_align = cmp::max(self.align, next.align);
249-
let realigned = match Layout::from_size_align(self.size, new_align) {
250-
None => return None,
251-
Some(l) => l,
252-
};
243+
let realigned = Layout::from_size_align(self.size, new_align)?;
253244

254245
let pad = realigned.padding_needed_for(next.align);
255246

256-
let offset = match self.size.checked_add(pad) {
257-
None => return None,
258-
Some(offset) => offset,
259-
};
260-
let new_size = match offset.checked_add(next.size) {
261-
None => return None,
262-
Some(new_size) => new_size,
263-
};
247+
let offset = self.size.checked_add(pad)?;
248+
let new_size = offset.checked_add(next.size)?;
264249

265-
let layout = match Layout::from_size_align(new_size, new_align) {
266-
None => return None,
267-
Some(l) => l,
268-
};
250+
let layout = Layout::from_size_align(new_size, new_align)?;
269251
Some((layout, offset))
270252
}
271253

@@ -282,11 +264,7 @@ impl Layout {
282264
///
283265
/// On arithmetic overflow, returns `None`.
284266
pub fn repeat_packed(&self, n: usize) -> Option<Self> {
285-
let size = match self.size().checked_mul(n) {
286-
None => return None,
287-
Some(scaled) => scaled,
288-
};
289-
267+
let size = self.size().checked_mul(n)?;
290268
Layout::from_size_align(size, self.align)
291269
}
292270

@@ -306,14 +284,8 @@ impl Layout {
306284
///
307285
/// On arithmetic overflow, returns `None`.
308286
pub fn extend_packed(&self, next: Self) -> Option<(Self, usize)> {
309-
let new_size = match self.size().checked_add(next.size()) {
310-
None => return None,
311-
Some(new_size) => new_size,
312-
};
313-
let layout = match Layout::from_size_align(new_size, self.align) {
314-
None => return None,
315-
Some(l) => l,
316-
};
287+
let new_size = self.size().checked_add(next.size())?;
288+
let layout = Layout::from_size_align(new_size, self.align)?;
317289
Some((layout, self.size()))
318290
}
319291

src/liballoc/benches/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::iter::Iterator;
1313
use std::vec::Vec;
1414
use std::collections::BTreeMap;
15-
use std::__rand::{Rng, thread_rng};
15+
use rand::{Rng, thread_rng};
1616
use test::{Bencher, black_box};
1717

1818
macro_rules! map_insert_rand_bench {

src/liballoc/benches/slice.rs

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

11-
use std::__rand::{thread_rng};
11+
use rand::{thread_rng};
1212
use std::mem;
1313
use std::ptr;
1414

src/liballoc/btree/set.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1067,21 +1067,15 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
10671067

10681068
fn next(&mut self) -> Option<&'a T> {
10691069
loop {
1070-
let o_cmp = match (self.a.peek(), self.b.peek()) {
1071-
(None, _) => None,
1072-
(_, None) => None,
1073-
(Some(a1), Some(b1)) => Some(a1.cmp(b1)),
1074-
};
1075-
match o_cmp {
1076-
None => return None,
1077-
Some(Less) => {
1070+
match Ord::cmp(self.a.peek()?, self.b.peek()?) {
1071+
Less => {
10781072
self.a.next();
10791073
}
1080-
Some(Equal) => {
1074+
Equal => {
10811075
self.b.next();
10821076
return self.a.next();
10831077
}
1084-
Some(Greater) => {
1078+
Greater => {
10851079
self.b.next();
10861080
}
10871081
}

src/liballoc/linked_list.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,15 @@ impl<'a, T, F> Iterator for DrainFilter<'a, T, F>
10711071
}
10721072
}
10731073

1074+
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
1075+
impl<'a, T, F> Drop for DrainFilter<'a, T, F>
1076+
where F: FnMut(&mut T) -> bool,
1077+
{
1078+
fn drop(&mut self) {
1079+
for _ in self { }
1080+
}
1081+
}
1082+
10741083
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
10751084
impl<'a, T: 'a + fmt::Debug, F> fmt::Debug for DrainFilter<'a, T, F>
10761085
where F: FnMut(&mut T) -> bool

src/liballoc/string.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1044,10 +1044,7 @@ impl String {
10441044
#[inline]
10451045
#[stable(feature = "rust1", since = "1.0.0")]
10461046
pub fn pop(&mut self) -> Option<char> {
1047-
let ch = match self.chars().rev().next() {
1048-
Some(ch) => ch,
1049-
None => return None,
1050-
};
1047+
let ch = self.chars().rev().next()?;
10511048
let newlen = self.len() - ch.len_utf8();
10521049
unsafe {
10531050
self.vec.set_len(newlen);

src/liballoc/vec.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1423,10 +1423,7 @@ impl<T: PartialEq> Vec<T> {
14231423
/// ```
14241424
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
14251425
pub fn remove_item(&mut self, item: &T) -> Option<T> {
1426-
let pos = match self.iter().position(|x| *x == *item) {
1427-
Some(x) => x,
1428-
None => return None,
1429-
};
1426+
let pos = self.iter().position(|x| *x == *item)?;
14301427
Some(self.remove(pos))
14311428
}
14321429
}

src/libcore/cell.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,11 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
10841084
pub fn map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> RefMut<'b, U>
10851085
where F: FnOnce(&mut T) -> &mut U
10861086
{
1087+
// FIXME(nll-rfc#40): fix borrow-check
1088+
let RefMut { value, borrow } = orig;
10871089
RefMut {
1088-
value: f(orig.value),
1089-
borrow: orig.borrow,
1090+
value: f(value),
1091+
borrow: borrow,
10901092
}
10911093
}
10921094
}

src/libcore/iter/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1776,12 +1776,18 @@ impl<I: Iterator> Iterator for Peekable<I> {
17761776

17771777
#[inline]
17781778
fn nth(&mut self, n: usize) -> Option<I::Item> {
1779-
match self.peeked.take() {
1780-
// the .take() below is just to avoid "move into pattern guard"
1781-
Some(ref mut v) if n == 0 => v.take(),
1782-
Some(None) => None,
1783-
Some(Some(_)) => self.iter.nth(n - 1),
1784-
None => self.iter.nth(n),
1779+
// FIXME(#6393): merge these when borrow-checking gets better.
1780+
if n == 0 {
1781+
match self.peeked.take() {
1782+
Some(v) => v,
1783+
None => self.iter.nth(n),
1784+
}
1785+
} else {
1786+
match self.peeked.take() {
1787+
Some(None) => None,
1788+
Some(Some(_)) => self.iter.nth(n - 1),
1789+
None => self.iter.nth(n),
1790+
}
17851791
}
17861792
}
17871793

src/libcore/macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,9 @@ mod builtin {
596596

597597
/// Unconditionally causes compilation to fail with the given error message when encountered.
598598
///
599-
/// For more information, see the [RFC].
599+
/// For more information, see the documentation for [`std::compile_error!`].
600600
///
601-
/// [RFC]: https://github.com/rust-lang/rfcs/blob/master/text/1695-add-error-macro.md
601+
/// [`std::compile_error!`]: ../std/macro.compile_error.html
602602
#[stable(feature = "compile_error_macro", since = "1.20.0")]
603603
#[macro_export]
604604
#[cfg(dox)]
@@ -736,7 +736,7 @@ mod builtin {
736736
#[cfg(dox)]
737737
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
738738

739-
/// Boolean evaluation of configuration flags.
739+
/// Boolean evaluation of configuration flags, at compile-time.
740740
///
741741
/// For more information, see the documentation for [`std::cfg!`].
742742
///

src/libcore/option.rs

+17
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ impl<T> Option<T> {
338338

339339
/// Returns the contained value or a default.
340340
///
341+
/// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing
342+
/// the result of a function call, it is recommended to use [`unwrap_or_else`],
343+
/// which is lazily evaluated.
344+
///
345+
/// [`unwrap_or_else`]: #method.unwrap_or_else
346+
///
341347
/// # Examples
342348
///
343349
/// ```
@@ -451,11 +457,16 @@ impl<T> Option<T> {
451457
/// Transforms the `Option<T>` into a [`Result<T, E>`], mapping [`Some(v)`] to
452458
/// [`Ok(v)`] and [`None`] to [`Err(err)`].
453459
///
460+
/// Arguments passed to `ok_or` are eagerly evaluated; if you are passing the
461+
/// result of a function call, it is recommended to use [`ok_or_else`], which is
462+
/// lazily evaluated.
463+
///
454464
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
455465
/// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok
456466
/// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err
457467
/// [`None`]: #variant.None
458468
/// [`Some(v)`]: #variant.Some
469+
/// [`ok_or_else`]: #method.ok_or_else
459470
///
460471
/// # Examples
461472
///
@@ -644,6 +655,12 @@ impl<T> Option<T> {
644655

645656
/// Returns the option if it contains a value, otherwise returns `optb`.
646657
///
658+
/// Arguments passed to `or` are eagerly evaluated; if you are passing the
659+
/// result of a function call, it is recommended to use [`or_else`], which is
660+
/// lazily evaluated.
661+
///
662+
/// [`or_else`]: #method.or_else
663+
///
647664
/// # Examples
648665
///
649666
/// ```

src/libcore/ptr.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,53 @@ pub const fn null<T>() -> *const T { 0 as *const T }
9191
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
9292

9393
/// Swaps the values at two mutable locations of the same type, without
94-
/// deinitializing either. They may overlap, unlike `mem::swap` which is
95-
/// otherwise equivalent.
94+
/// deinitializing either.
95+
///
96+
/// The values pointed at by `x` and `y` may overlap, unlike `mem::swap` which
97+
/// is otherwise equivalent. If the values do overlap, then the overlapping
98+
/// region of memory from `x` will be used. This is demonstrated in the
99+
/// examples section below.
96100
///
97101
/// # Safety
98102
///
99103
/// This function copies the memory through the raw pointers passed to it
100104
/// as arguments.
101105
///
102106
/// Ensure that these pointers are valid before calling `swap`.
107+
///
108+
/// # Examples
109+
///
110+
/// Swapping two non-overlapping regions:
111+
///
112+
/// ```
113+
/// use std::ptr;
114+
///
115+
/// let mut array = [0, 1, 2, 3];
116+
///
117+
/// let x = array[0..].as_mut_ptr() as *mut [u32; 2];
118+
/// let y = array[2..].as_mut_ptr() as *mut [u32; 2];
119+
///
120+
/// unsafe {
121+
/// ptr::swap(x, y);
122+
/// assert_eq!([2, 3, 0, 1], array);
123+
/// }
124+
/// ```
125+
///
126+
/// Swapping two overlapping regions:
127+
///
128+
/// ```
129+
/// use std::ptr;
130+
///
131+
/// let mut array = [0, 1, 2, 3];
132+
///
133+
/// let x = array[0..].as_mut_ptr() as *mut [u32; 3];
134+
/// let y = array[1..].as_mut_ptr() as *mut [u32; 3];
135+
///
136+
/// unsafe {
137+
/// ptr::swap(x, y);
138+
/// assert_eq!([1, 0, 1, 2], array);
139+
/// }
140+
/// ```
103141
#[inline]
104142
#[stable(feature = "rust1", since = "1.0.0")]
105143
pub unsafe fn swap<T>(x: *mut T, y: *mut T) {

0 commit comments

Comments
 (0)