Skip to content

Commit 01d44ca

Browse files
committed
Auto merge of #31359 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30971, #31202, #31247, #31270, #31281, #31327, #31339, #31340, #31342, #31344, #31345, #31346, #31348 - Failed merges:
2 parents 508c21e + c3f6122 commit 01d44ca

File tree

20 files changed

+162
-67
lines changed

20 files changed

+162
-67
lines changed

Diff for: CONTRIBUTING.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ Some common make targets are:
131131
& everything builds in the correct manner.
132132
- `make check-stage1-std NO_REBUILD=1` - test the standard library without
133133
rebuilding the entire compiler
134-
- `make check TESTNAME=<path-to-test-file>.rs` - Run a single test file
135-
- `make check-stage1-rpass TESTNAME=<path-to-test-file>.rs` - Run a single
134+
- `make check TESTNAME=<substring-of-test-name>` - Run a matching set of tests.
135+
- `TESTNAME` should be a substring of the tests to match against e.g. it could
136+
be the fully qualified test name, or just a part of it.
137+
`TESTNAME=collections::hash::map::test_map::test_capacity_not_less_than_len`
138+
or `TESTNAME=test_capacity_not_less_than_len`.
139+
- `make check-stage1-rpass TESTNAME=<substring-of-test-name>` - Run a single
136140
rpass test with the stage1 compiler (this will be quicker than running the
137141
command above as we only build the stage1 compiler, not the entire thing).
138142
You can also leave off the `-rpass` to run all stage1 test types.

Diff for: src/doc/book/documentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ least. If your function has a non-trivial contract like this, that is
118118
detected/enforced by panics, documenting it is very important.
119119

120120
```rust
121-
/// # Failures
121+
/// # Errors
122122
# fn foo() {}
123123
```
124124

Diff for: src/doc/book/error-handling.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,28 @@ fn file_name(file_path: &str) -> Option<&str> {
356356
```
357357

358358
You might think that we could use the `map` combinator to reduce the case
359-
analysis, but its type doesn't quite fit. Namely, `map` takes a function that
360-
does something only with the inner value. The result of that function is then
361-
*always* [rewrapped with `Some`](#code-option-map). Instead, we need something
362-
like `map`, but which allows the caller to return another `Option`. Its generic
363-
implementation is even simpler than `map`:
359+
analysis, but its type doesn't quite fit...
360+
361+
```rust,ignore
362+
fn file_path_ext(file_path: &str) -> Option<&str> {
363+
file_name(file_path).map(|x| extension(x)) //Compilation error
364+
}
365+
```
366+
367+
The `map` function here wraps the value returned by the `extension` function
368+
inside an `Option<_>` and since the `extension` function itself returns an
369+
`Option<&str>` the expression `file_name(file_path).map(|x| extension(x))`
370+
actually returns an `Option<Option<&str>>`.
371+
372+
But since `file_path_ext` just returns `Option<&str>` (and not
373+
`Option<Option<&str>>`) we get a compilation error.
374+
375+
The result of the function taken by map as input is *always* [rewrapped with
376+
`Some`](#code-option-map). Instead, we need something like `map`, but which
377+
allows the caller to return a `Option<_>` directly without wrapping it in
378+
another `Option<_>`.
379+
380+
Its generic implementation is even simpler than `map`:
364381

365382
```rust
366383
fn and_then<F, T, A>(option: Option<T>, f: F) -> Option<A>
@@ -382,6 +399,10 @@ fn file_path_ext(file_path: &str) -> Option<&str> {
382399
}
383400
```
384401

402+
Side note: Since `and_then` essentially works like `map` but returns an
403+
`Option<_>` instead of an `Option<Option<_>>` it is known as `flatmap` in some
404+
other languages.
405+
385406
The `Option` type has many other combinators [defined in the standard
386407
library][5]. It is a good idea to skim this list and familiarize
387408
yourself with what's available—they can often reduce case analysis

Diff for: src/doc/book/getting-started.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Specifically they will each satisfy the following requirements:
3939

4040
| Target | std |rustc|cargo| notes |
4141
|-------------------------------|-----|-----|-----|----------------------------|
42+
| `i686-pc-windows-msvc` |||| 32-bit MSVC (Windows 7+) |
4243
| `x86_64-pc-windows-msvc` |||| 64-bit MSVC (Windows 7+) |
4344
| `i686-pc-windows-gnu` |||| 32-bit MinGW (Windows 7+) |
4445
| `x86_64-pc-windows-gnu` |||| 64-bit MinGW (Windows 7+) |
@@ -62,7 +63,6 @@ these platforms are required to have each of the following:
6263

6364
| Target | std |rustc|cargo| notes |
6465
|-------------------------------|-----|-----|-----|----------------------------|
65-
| `i686-pc-windows-msvc` |||| 32-bit MSVC (Windows 7+) |
6666
| `x86_64-unknown-linux-musl` || | | 64-bit Linux with MUSL |
6767
| `arm-linux-androideabi` || | | ARM Android |
6868
| `arm-unknown-linux-gnueabi` ||| | ARM Linux (2.6.18+) |
@@ -85,6 +85,9 @@ unofficial locations.
8585
| `i686-linux-android` || | | 32-bit x86 Android |
8686
| `aarch64-linux-android` || | | ARM64 Android |
8787
| `powerpc-unknown-linux-gnu` || | | PowerPC Linux (2.6.18+) |
88+
| `powerpc64-unknown-linux-gnu` || | | PPC64 Linux (2.6.18+) |
89+
|`powerpc64le-unknown-linux-gnu`|| | | PPC64LE Linux (2.6.18+) |
90+
|`armv7-unknown-linux-gnueabihf`|| | | ARMv7 Linux (2.6.18+) |
8891
| `i386-apple-ios` || | | 32-bit x86 iOS |
8992
| `x86_64-apple-ios` || | | 64-bit x86 iOS |
9093
| `armv7-apple-ios` || | | ARM iOS |
@@ -97,6 +100,7 @@ unofficial locations.
97100
| `x86_64-unknown-bitrig` ||| | 64-bit Bitrig |
98101
| `x86_64-unknown-dragonfly` ||| | 64-bit DragonFlyBSD |
99102
| `x86_64-rumprun-netbsd` || | | 64-bit NetBSD Rump Kernel |
103+
| `x86_64-sun-solaris` ||| | 64-bit Solaris/SunOS |
100104
| `i686-pc-windows-msvc` (XP) || | | Windows XP support |
101105
| `x86_64-pc-windows-msvc` (XP) || | | Windows XP support |
102106

@@ -569,7 +573,7 @@ executable application, as opposed to a library. Executables are often called
569573
*binaries* (as in `/usr/bin`, if you’re on a Unix system).
570574

571575
Cargo has generated two files and one directory for us: a `Cargo.toml` and a
572-
*src* directory with a *main.rs* file inside. These should look familliar,
576+
*src* directory with a *main.rs* file inside. These should look familiar,
573577
they’re exactly what we created by hand, above.
574578

575579
This output is all you need to get started. First, open `Cargo.toml`. It should

Diff for: src/doc/book/loops.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ Don't forget to add the parentheses around the range.
125125
#### On iterators:
126126

127127
```rust
128-
# let lines = "hello\nworld".lines();
128+
let lines = "hello\nworld".lines();
129+
129130
for (linenumber, line) in lines.enumerate() {
130131
println!("{}: {}", linenumber, line);
131132
}
@@ -134,10 +135,8 @@ for (linenumber, line) in lines.enumerate() {
134135
Outputs:
135136

136137
```text
137-
0: Content of line one
138-
1: Content of line two
139-
2: Content of line three
140-
3: Content of line four
138+
0: hello
139+
1: world
141140
```
142141

143142
## Ending iteration early

Diff for: src/libcollections/str.rs

+49-1
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,13 @@ impl str {
15111511
/// 'Whitespace' is defined according to the terms of the Unicode Derived
15121512
/// Core Property `White_Space`.
15131513
///
1514+
/// # Text directionality
1515+
///
1516+
/// A string is a sequence of bytes. 'Left' in this context means the first
1517+
/// position of that byte string; for a language like Arabic or Hebrew
1518+
/// which are 'right to left' rather than 'left to right', this will be
1519+
/// the _right_ side, not the left.
1520+
///
15141521
/// # Examples
15151522
///
15161523
/// Basic usage:
@@ -1520,6 +1527,16 @@ impl str {
15201527
///
15211528
/// assert_eq!("Hello\tworld\t", s.trim_left());
15221529
/// ```
1530+
///
1531+
/// Directionality:
1532+
///
1533+
/// ```
1534+
/// let s = " English";
1535+
/// assert!(Some('E') == s.trim_left().chars().next());
1536+
///
1537+
/// let s = " עברית";
1538+
/// assert!(Some('ע') == s.trim_left().chars().next());
1539+
/// ```
15231540
#[stable(feature = "rust1", since = "1.0.0")]
15241541
pub fn trim_left(&self) -> &str {
15251542
UnicodeStr::trim_left(self)
@@ -1530,6 +1547,13 @@ impl str {
15301547
/// 'Whitespace' is defined according to the terms of the Unicode Derived
15311548
/// Core Property `White_Space`.
15321549
///
1550+
/// # Text directionality
1551+
///
1552+
/// A string is a sequence of bytes. 'Right' in this context means the last
1553+
/// position of that byte string; for a language like Arabic or Hebrew
1554+
/// which are 'right to left' rather than 'left to right', this will be
1555+
/// the _left_ side, not the right.
1556+
///
15331557
/// # Examples
15341558
///
15351559
/// Basic usage:
@@ -1539,6 +1563,16 @@ impl str {
15391563
///
15401564
/// assert_eq!(" Hello\tworld", s.trim_right());
15411565
/// ```
1566+
///
1567+
/// Directionality:
1568+
///
1569+
/// ```
1570+
/// let s = "English ";
1571+
/// assert!(Some('h') == s.trim_right().chars().rev().next());
1572+
///
1573+
/// let s = "עברית ";
1574+
/// assert!(Some('ת') == s.trim_right().chars().rev().next());
1575+
/// ```
15421576
#[stable(feature = "rust1", since = "1.0.0")]
15431577
pub fn trim_right(&self) -> &str {
15441578
UnicodeStr::trim_right(self)
@@ -1584,6 +1618,13 @@ impl str {
15841618
///
15851619
/// [`char`]: primitive.char.html
15861620
///
1621+
/// # Text directionality
1622+
///
1623+
/// A string is a sequence of bytes. 'Left' in this context means the first
1624+
/// position of that byte string; for a language like Arabic or Hebrew
1625+
/// which are 'right to left' rather than 'left to right', this will be
1626+
/// the _right_ side, not the left.
1627+
///
15871628
/// # Examples
15881629
///
15891630
/// Basic usage:
@@ -1608,6 +1649,13 @@ impl str {
16081649
///
16091650
/// [`char`]: primitive.char.html
16101651
///
1652+
/// # Text directionality
1653+
///
1654+
/// A string is a sequence of bytes. 'Right' in this context means the last
1655+
/// position of that byte string; for a language like Arabic or Hebrew
1656+
/// which are 'right to left' rather than 'left to right', this will be
1657+
/// the _left_ side, not the right.
1658+
///
16111659
/// # Examples
16121660
///
16131661
/// Simple patterns:
@@ -1644,7 +1692,7 @@ impl str {
16441692
///
16451693
/// [`FromStr`]: str/trait.FromStr.html
16461694
///
1647-
/// # Failure
1695+
/// # Errors
16481696
///
16491697
/// Will return `Err` if it's not possible to parse this string slice into
16501698
/// the desired type.

Diff for: src/libcollections/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl String {
433433
///
434434
/// [`str::from_utf8()`]: ../str/fn.from_utf8.html
435435
///
436-
/// # Failure
436+
/// # Errors
437437
///
438438
/// Returns `Err` if the slice is not UTF-8 with a description as to why the
439439
/// provided bytes are not UTF-8. The vector you moved in is also included.

Diff for: src/libcore/iter.rs

+10-28
Original file line numberDiff line numberDiff line change
@@ -2756,20 +2756,11 @@ pub trait Extend<A> {
27562756
///
27572757
/// let mut iter = numbers.iter();
27582758
///
2759-
/// let n = iter.next();
2760-
/// assert_eq!(Some(&1), n);
2761-
///
2762-
/// let n = iter.next_back();
2763-
/// assert_eq!(Some(&3), n);
2764-
///
2765-
/// let n = iter.next_back();
2766-
/// assert_eq!(Some(&2), n);
2767-
///
2768-
/// let n = iter.next();
2769-
/// assert_eq!(None, n);
2770-
///
2771-
/// let n = iter.next_back();
2772-
/// assert_eq!(None, n);
2759+
/// assert_eq!(Some(&1), iter.next());
2760+
/// assert_eq!(Some(&3), iter.next_back());
2761+
/// assert_eq!(Some(&2), iter.next_back());
2762+
/// assert_eq!(None, iter.next());
2763+
/// assert_eq!(None, iter.next_back());
27732764
/// ```
27742765
#[stable(feature = "rust1", since = "1.0.0")]
27752766
pub trait DoubleEndedIterator: Iterator {
@@ -2789,20 +2780,11 @@ pub trait DoubleEndedIterator: Iterator {
27892780
///
27902781
/// let mut iter = numbers.iter();
27912782
///
2792-
/// let n = iter.next();
2793-
/// assert_eq!(Some(&1), n);
2794-
///
2795-
/// let n = iter.next_back();
2796-
/// assert_eq!(Some(&3), n);
2797-
///
2798-
/// let n = iter.next_back();
2799-
/// assert_eq!(Some(&2), n);
2800-
///
2801-
/// let n = iter.next();
2802-
/// assert_eq!(None, n);
2803-
///
2804-
/// let n = iter.next_back();
2805-
/// assert_eq!(None, n);
2783+
/// assert_eq!(Some(&1), iter.next());
2784+
/// assert_eq!(Some(&3), iter.next_back());
2785+
/// assert_eq!(Some(&2), iter.next_back());
2786+
/// assert_eq!(None, iter.next());
2787+
/// assert_eq!(None, iter.next_back());
28062788
/// ```
28072789
#[stable(feature = "rust1", since = "1.0.0")]
28082790
fn next_back(&mut self) -> Option<Self::Item>;

Diff for: src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Utf8Error {
188188
/// it, this function is one way to have a stack-allocated string. There is
189189
/// an example of this in the examples section below.
190190
///
191-
/// # Failure
191+
/// # Errors
192192
///
193193
/// Returns `Err` if the slice is not UTF-8 with a description as to why the
194194
/// provided slice is not UTF-8.

Diff for: src/libcore/sync/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl AtomicUsize {
711711
/// ```
712712
/// use std::sync::atomic::{AtomicUsize, Ordering};
713713
///
714-
/// let some_usize= AtomicUsize::new(5);
714+
/// let some_usize = AtomicUsize::new(5);
715715
///
716716
/// assert_eq!(some_usize.swap(10, Ordering::Relaxed), 5);
717717
/// assert_eq!(some_usize.load(Ordering::Relaxed), 10);

Diff for: src/librustc_borrowck/diagnostics.rs

+27
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,33 @@ fn main() {
377377
}
378378
```
379379
380+
Moving out of a member of a mutably borrowed struct is fine if you put something
381+
back. `mem::replace` can be used for that:
382+
383+
```
384+
struct TheDarkKnight;
385+
386+
impl TheDarkKnight {
387+
fn nothing_is_true(self) {}
388+
}
389+
390+
struct Batcave {
391+
knight: TheDarkKnight
392+
}
393+
394+
fn main() {
395+
use std::mem;
396+
397+
let mut cave = Batcave {
398+
knight: TheDarkKnight
399+
};
400+
let borrowed = &mut cave;
401+
402+
borrowed.knight.nothing_is_true(); // E0507
403+
mem::replace(&mut borrowed.knight, TheDarkKnight).nothing_is_true(); // ok!
404+
}
405+
```
406+
380407
You can find more information about borrowing in the rust-book:
381408
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
382409
"##,

Diff for: src/librustc_unicode/char.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl char {
194194
/// * `a-z`
195195
/// * `A-Z`
196196
///
197-
/// # Failure
197+
/// # Errors
198198
///
199199
/// Returns `None` if the `char` does not refer to a digit in the given radix.
200200
///

Diff for: src/libstd/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct Metadata(fs_imp::FileAttr);
7070
/// information like the entry's path and possibly other metadata can be
7171
/// learned.
7272
///
73-
/// # Failure
73+
/// # Errors
7474
///
7575
/// This `io::Result` will be an `Err` if there's some sort of intermittent
7676
/// IO error during iteration.

Diff for: src/libstd/process.rs

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ use thread::{self, JoinHandle};
4747
///
4848
/// assert!(ecode.success());
4949
/// ```
50+
///
51+
/// # Note
52+
///
53+
/// Take note that there is no implementation of
54+
/// [`Drop`](../../core/ops/trait.Drop.html) for child processes, so if you
55+
/// do not ensure the `Child` has exited then it will continue to run, even
56+
/// after the `Child` handle to the child process has gone out of scope.
57+
///
58+
/// Calling `wait` (or other functions that wrap around it) will make the
59+
/// parent process wait until the child has actually exited before continuing.
5060
#[stable(feature = "process", since = "1.0.0")]
5161
pub struct Child {
5262
handle: imp::Process,

Diff for: src/libstd/sync/condvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl Condvar {
129129
/// the predicate must always be checked each time this function returns to
130130
/// protect against spurious wakeups.
131131
///
132-
/// # Failure
132+
/// # Errors
133133
///
134134
/// This function will return an error if the mutex being waited on is
135135
/// poisoned when this thread re-acquires the lock. For more information,

0 commit comments

Comments
 (0)