Skip to content

Rollup of 13 pull requests #31359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
25d068e
Showed the difference between `map` and `and_then` with an example.
sandeep-datta Jan 17, 2016
5f20143
Fixed line wrapping.
sandeep-datta Jan 20, 2016
5a5aaca
Document LTR vs RTL wrt trim_*
steveklabnik Jan 26, 2016
f841f06
Improve message for rustc --explain E0507
ruuda Jan 28, 2016
b5845c6
fix overflow due to multiline error span
oli-obk Jan 29, 2016
fe10914
Update emitter.rs
mitaa Jan 29, 2016
c511d36
Merge pull request #1 from mitaa/patch-1
oli-obk Jan 29, 2016
0922d7e
Ignoring demo code with compilation error.
sandeep-datta Jan 30, 2016
54927ac
off by one
oli-obk Jan 30, 2016
cee1695
Safety docs about `std::process::Child` going out of scope
dirk Jan 31, 2016
7683922
Minor corrections in docs for `std::process::Child`
dirk Jan 31, 2016
a58d330
Update docs about how to run specific tests
rthomas Feb 1, 2016
2043cd8
Fix typo in doc/book/getting-started.md
prayagverma Feb 1, 2016
7aa41a1
Comment fix
reeze Feb 1, 2016
7df3bf1
make this example more obvious
steveklabnik Feb 1, 2016
49fe519
book: Change "Failures" to "Errors" in doc special sections chapter
kamalmarhubi Feb 1, 2016
ed08701
Fix a documentation typo
alopatindev Feb 1, 2016
4289973
doc: bindings not needed for this example
tshepang Jan 27, 2016
0574b39
doc: Move 32-bit MSVC to a tier 1 platform
alexcrichton Jan 29, 2016
66eb588
Merge branch 'master' of https://github.com/rust-lang/rust into doc
rthomas Feb 1, 2016
a5e491f
Update TESTNAME matching description
rthomas Feb 1, 2016
df31868
Update TESTNAME description
rthomas Feb 1, 2016
129a623
docs: Standardize on 'Errors' header in std docs
kamalmarhubi Feb 2, 2016
c0ace5d
Add doctests for directionality
steveklabnik Feb 1, 2016
78afc78
Rollup merge of #30971 - SDX2000:docfixes, r=steveklabnik
steveklabnik Feb 2, 2016
7097d29
Rollup merge of #31202 - steveklabnik:gh30459, r=alexcrichton
steveklabnik Feb 2, 2016
e65f29a
Rollup merge of #31247 - tshepang:redundant-bindings, r=steveklabnik
steveklabnik Feb 2, 2016
674f71e
Rollup merge of #31270 - ruud-v-a:improve-e0507, r=steveklabnik
steveklabnik Feb 2, 2016
a9fbb05
Rollup merge of #31281 - oli-obk:patch-2, r=nikomatsakis
steveklabnik Feb 2, 2016
b2f3a51
Rollup merge of #31327 - dirk:dirk/process-child-safety-docs, r=alexc…
steveklabnik Feb 2, 2016
4118958
Rollup merge of #31339 - rthomas:doc, r=alexcrichton
steveklabnik Feb 2, 2016
0b8c713
Rollup merge of #31340 - pra85:patch-1, r=alexcrichton
steveklabnik Feb 2, 2016
d86c4fb
Rollup merge of #31342 - reeze:patch-1, r=steveklabnik
steveklabnik Feb 2, 2016
9eb417b
Rollup merge of #31344 - steveklabnik:gh31334, r=alexcrichton
steveklabnik Feb 2, 2016
5f0d8ea
Rollup merge of #31345 - kamalmarhubi:book-docs-special-section-error…
steveklabnik Feb 2, 2016
7f26bd8
Rollup merge of #31346 - alopatindev:fixes, r=aturon
steveklabnik Feb 2, 2016
c3f6122
Rollup merge of #31348 - alexcrichton:shuffle-tiers, r=steveklabnik
steveklabnik Feb 2, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ Some common make targets are:
& everything builds in the correct manner.
- `make check-stage1-std NO_REBUILD=1` - test the standard library without
rebuilding the entire compiler
- `make check TESTNAME=<path-to-test-file>.rs` - Run a single test file
- `make check-stage1-rpass TESTNAME=<path-to-test-file>.rs` - Run a single
- `make check TESTNAME=<substring-of-test-name>` - Run a matching set of tests.
- `TESTNAME` should be a substring of the tests to match against e.g. it could
be the fully qualified test name, or just a part of it.
`TESTNAME=collections::hash::map::test_map::test_capacity_not_less_than_len`
or `TESTNAME=test_capacity_not_less_than_len`.
- `make check-stage1-rpass TESTNAME=<substring-of-test-name>` - Run a single
rpass test with the stage1 compiler (this will be quicker than running the
command above as we only build the stage1 compiler, not the entire thing).
You can also leave off the `-rpass` to run all stage1 test types.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ least. If your function has a non-trivial contract like this, that is
detected/enforced by panics, documenting it is very important.

```rust
/// # Failures
/// # Errors
# fn foo() {}
```

Expand Down
31 changes: 26 additions & 5 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,28 @@ fn file_name(file_path: &str) -> Option<&str> {
```

You might think that we could use the `map` combinator to reduce the case
analysis, but its type doesn't quite fit. Namely, `map` takes a function that
does something only with the inner value. The result of that function is then
*always* [rewrapped with `Some`](#code-option-map). Instead, we need something
like `map`, but which allows the caller to return another `Option`. Its generic
implementation is even simpler than `map`:
analysis, but its type doesn't quite fit...

```rust,ignore
fn file_path_ext(file_path: &str) -> Option<&str> {
file_name(file_path).map(|x| extension(x)) //Compilation error
}
```

The `map` function here wraps the value returned by the `extension` function
inside an `Option<_>` and since the `extension` function itself returns an
`Option<&str>` the expression `file_name(file_path).map(|x| extension(x))`
actually returns an `Option<Option<&str>>`.

But since `file_path_ext` just returns `Option<&str>` (and not
`Option<Option<&str>>`) we get a compilation error.

The result of the function taken by map as input is *always* [rewrapped with
`Some`](#code-option-map). Instead, we need something like `map`, but which
allows the caller to return a `Option<_>` directly without wrapping it in
another `Option<_>`.

Its generic implementation is even simpler than `map`:

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

Side note: Since `and_then` essentially works like `map` but returns an
`Option<_>` instead of an `Option<Option<_>>` it is known as `flatmap` in some
other languages.

The `Option` type has many other combinators [defined in the standard
library][5]. It is a good idea to skim this list and familiarize
yourself with what's available—they can often reduce case analysis
Expand Down
8 changes: 6 additions & 2 deletions src/doc/book/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Specifically they will each satisfy the following requirements:

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

| Target | std |rustc|cargo| notes |
|-------------------------------|-----|-----|-----|----------------------------|
| `i686-pc-windows-msvc` | ✓ | ✓ | ✓ | 32-bit MSVC (Windows 7+) |
| `x86_64-unknown-linux-musl` | ✓ | | | 64-bit Linux with MUSL |
| `arm-linux-androideabi` | ✓ | | | ARM Android |
| `arm-unknown-linux-gnueabi` | ✓ | ✓ | | ARM Linux (2.6.18+) |
Expand All @@ -85,6 +85,9 @@ unofficial locations.
| `i686-linux-android` | ✓ | | | 32-bit x86 Android |
| `aarch64-linux-android` | ✓ | | | ARM64 Android |
| `powerpc-unknown-linux-gnu` | ✓ | | | PowerPC Linux (2.6.18+) |
| `powerpc64-unknown-linux-gnu` | ✓ | | | PPC64 Linux (2.6.18+) |
|`powerpc64le-unknown-linux-gnu`| ✓ | | | PPC64LE Linux (2.6.18+) |
|`armv7-unknown-linux-gnueabihf`| ✓ | | | ARMv7 Linux (2.6.18+) |
| `i386-apple-ios` | ✓ | | | 32-bit x86 iOS |
| `x86_64-apple-ios` | ✓ | | | 64-bit x86 iOS |
| `armv7-apple-ios` | ✓ | | | ARM iOS |
Expand All @@ -97,6 +100,7 @@ unofficial locations.
| `x86_64-unknown-bitrig` | ✓ | ✓ | | 64-bit Bitrig |
| `x86_64-unknown-dragonfly` | ✓ | ✓ | | 64-bit DragonFlyBSD |
| `x86_64-rumprun-netbsd` | ✓ | | | 64-bit NetBSD Rump Kernel |
| `x86_64-sun-solaris` | ✓ | ✓ | | 64-bit Solaris/SunOS |
| `i686-pc-windows-msvc` (XP) | ✓ | | | Windows XP support |
| `x86_64-pc-windows-msvc` (XP) | ✓ | | | Windows XP support |

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

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

This output is all you need to get started. First, open `Cargo.toml`. It should
Expand Down
9 changes: 4 additions & 5 deletions src/doc/book/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ Don't forget to add the parentheses around the range.
#### On iterators:

```rust
# let lines = "hello\nworld".lines();
let lines = "hello\nworld".lines();

for (linenumber, line) in lines.enumerate() {
println!("{}: {}", linenumber, line);
}
Expand All @@ -134,10 +135,8 @@ for (linenumber, line) in lines.enumerate() {
Outputs:

```text
0: Content of line one
1: Content of line two
2: Content of line three
3: Content of line four
0: hello
1: world
```

## Ending iteration early
Expand Down
50 changes: 49 additions & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,13 @@ impl str {
/// 'Whitespace' is defined according to the terms of the Unicode Derived
/// Core Property `White_Space`.
///
/// # Text directionality
///
/// A string is a sequence of bytes. 'Left' in this context means the first
/// position of that byte string; for a language like Arabic or Hebrew
/// which are 'right to left' rather than 'left to right', this will be
/// the _right_ side, not the left.
///
/// # Examples
///
/// Basic usage:
Expand All @@ -1520,6 +1527,16 @@ impl str {
///
/// assert_eq!("Hello\tworld\t", s.trim_left());
/// ```
///
/// Directionality:
///
/// ```
/// let s = " English";
/// assert!(Some('E') == s.trim_left().chars().next());
///
/// let s = " עברית";
/// assert!(Some('ע') == s.trim_left().chars().next());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn trim_left(&self) -> &str {
UnicodeStr::trim_left(self)
Expand All @@ -1530,6 +1547,13 @@ impl str {
/// 'Whitespace' is defined according to the terms of the Unicode Derived
/// Core Property `White_Space`.
///
/// # Text directionality
///
/// A string is a sequence of bytes. 'Right' in this context means the last
/// position of that byte string; for a language like Arabic or Hebrew
/// which are 'right to left' rather than 'left to right', this will be
/// the _left_ side, not the right.
///
/// # Examples
///
/// Basic usage:
Expand All @@ -1539,6 +1563,16 @@ impl str {
///
/// assert_eq!(" Hello\tworld", s.trim_right());
/// ```
///
/// Directionality:
///
/// ```
/// let s = "English ";
/// assert!(Some('h') == s.trim_right().chars().rev().next());
///
/// let s = "עברית ";
/// assert!(Some('ת') == s.trim_right().chars().rev().next());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn trim_right(&self) -> &str {
UnicodeStr::trim_right(self)
Expand Down Expand Up @@ -1584,6 +1618,13 @@ impl str {
///
/// [`char`]: primitive.char.html
///
/// # Text directionality
///
/// A string is a sequence of bytes. 'Left' in this context means the first
/// position of that byte string; for a language like Arabic or Hebrew
/// which are 'right to left' rather than 'left to right', this will be
/// the _right_ side, not the left.
///
/// # Examples
///
/// Basic usage:
Expand All @@ -1608,6 +1649,13 @@ impl str {
///
/// [`char`]: primitive.char.html
///
/// # Text directionality
///
/// A string is a sequence of bytes. 'Right' in this context means the last
/// position of that byte string; for a language like Arabic or Hebrew
/// which are 'right to left' rather than 'left to right', this will be
/// the _left_ side, not the right.
///
/// # Examples
///
/// Simple patterns:
Expand Down Expand Up @@ -1644,7 +1692,7 @@ impl str {
///
/// [`FromStr`]: str/trait.FromStr.html
///
/// # Failure
/// # Errors
///
/// Will return `Err` if it's not possible to parse this string slice into
/// the desired type.
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl String {
///
/// [`str::from_utf8()`]: ../str/fn.from_utf8.html
///
/// # Failure
/// # Errors
///
/// Returns `Err` if the slice is not UTF-8 with a description as to why the
/// provided bytes are not UTF-8. The vector you moved in is also included.
Expand Down
38 changes: 10 additions & 28 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2756,20 +2756,11 @@ pub trait Extend<A> {
///
/// let mut iter = numbers.iter();
///
/// let n = iter.next();
/// assert_eq!(Some(&1), n);
///
/// let n = iter.next_back();
/// assert_eq!(Some(&3), n);
///
/// let n = iter.next_back();
/// assert_eq!(Some(&2), n);
///
/// let n = iter.next();
/// assert_eq!(None, n);
///
/// let n = iter.next_back();
/// assert_eq!(None, n);
/// assert_eq!(Some(&1), iter.next());
/// assert_eq!(Some(&3), iter.next_back());
/// assert_eq!(Some(&2), iter.next_back());
/// assert_eq!(None, iter.next());
/// assert_eq!(None, iter.next_back());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub trait DoubleEndedIterator: Iterator {
Expand All @@ -2789,20 +2780,11 @@ pub trait DoubleEndedIterator: Iterator {
///
/// let mut iter = numbers.iter();
///
/// let n = iter.next();
/// assert_eq!(Some(&1), n);
///
/// let n = iter.next_back();
/// assert_eq!(Some(&3), n);
///
/// let n = iter.next_back();
/// assert_eq!(Some(&2), n);
///
/// let n = iter.next();
/// assert_eq!(None, n);
///
/// let n = iter.next_back();
/// assert_eq!(None, n);
/// assert_eq!(Some(&1), iter.next());
/// assert_eq!(Some(&3), iter.next_back());
/// assert_eq!(Some(&2), iter.next_back());
/// assert_eq!(None, iter.next());
/// assert_eq!(None, iter.next_back());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn next_back(&mut self) -> Option<Self::Item>;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl Utf8Error {
/// it, this function is one way to have a stack-allocated string. There is
/// an example of this in the examples section below.
///
/// # Failure
/// # Errors
///
/// Returns `Err` if the slice is not UTF-8 with a description as to why the
/// provided slice is not UTF-8.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ impl AtomicUsize {
/// ```
/// use std::sync::atomic::{AtomicUsize, Ordering};
///
/// let some_usize= AtomicUsize::new(5);
/// let some_usize = AtomicUsize::new(5);
///
/// assert_eq!(some_usize.swap(10, Ordering::Relaxed), 5);
/// assert_eq!(some_usize.load(Ordering::Relaxed), 10);
Expand Down
27 changes: 27 additions & 0 deletions src/librustc_borrowck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,33 @@ fn main() {
}
```

Moving out of a member of a mutably borrowed struct is fine if you put something
back. `mem::replace` can be used for that:

```
struct TheDarkKnight;

impl TheDarkKnight {
fn nothing_is_true(self) {}
}

struct Batcave {
knight: TheDarkKnight
}

fn main() {
use std::mem;

let mut cave = Batcave {
knight: TheDarkKnight
};
let borrowed = &mut cave;

borrowed.knight.nothing_is_true(); // E0507
mem::replace(&mut borrowed.knight, TheDarkKnight).nothing_is_true(); // ok!
}
```

You can find more information about borrowing in the rust-book:
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
"##,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl char {
/// * `a-z`
/// * `A-Z`
///
/// # Failure
/// # Errors
///
/// Returns `None` if the `char` does not refer to a digit in the given radix.
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct Metadata(fs_imp::FileAttr);
/// information like the entry's path and possibly other metadata can be
/// learned.
///
/// # Failure
/// # Errors
///
/// This `io::Result` will be an `Err` if there's some sort of intermittent
/// IO error during iteration.
Expand Down
10 changes: 10 additions & 0 deletions src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ use thread::{self, JoinHandle};
///
/// assert!(ecode.success());
/// ```
///
/// # Note
///
/// Take note that there is no implementation of
/// [`Drop`](../../core/ops/trait.Drop.html) for child processes, so if you
/// do not ensure the `Child` has exited then it will continue to run, even
/// after the `Child` handle to the child process has gone out of scope.
///
/// Calling `wait` (or other functions that wrap around it) will make the
/// parent process wait until the child has actually exited before continuing.
#[stable(feature = "process", since = "1.0.0")]
pub struct Child {
handle: imp::Process,
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Condvar {
/// the predicate must always be checked each time this function returns to
/// protect against spurious wakeups.
///
/// # Failure
/// # Errors
///
/// This function will return an error if the mutex being waited on is
/// poisoned when this thread re-acquires the lock. For more information,
Expand Down
Loading