Skip to content

Commit

Permalink
Auto merge of rust-lang#37657 - steveklabnik:rollup, r=steveklabnik
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Nov 9, 2016
2 parents 966c700 + 5c92c2c commit 02aa428
Show file tree
Hide file tree
Showing 9 changed files with 621 additions and 147 deletions.
111 changes: 12 additions & 99 deletions src/doc/book/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,112 +4,25 @@ This first chapter of the book will get us going with Rust and its tooling.
First, we’ll install Rust. Then, the classic ‘Hello World’ program. Finally,
we’ll talk about Cargo, Rust’s build system and package manager.

We’ll be showing off a number of commands using a terminal, and those lines all
start with `$`. You don't need to type in the `$`s, they are there to indicate
the start of each command. We’ll see many tutorials and examples around the web
that follow this convention: `$` for commands run as our regular user, and `#`
for commands we should be running as an administrator.

# Installing Rust

The first step to using Rust is to install it. Generally speaking, you’ll need
an Internet connection to run the commands in this section, as we’ll be
downloading Rust from the Internet.

We’ll be showing off a number of commands using a terminal, and those lines all
start with `$`. You don't need to type in the `$`s, they are there to indicate
the start of each command. We’ll see many tutorials and examples around the web
that follow this convention: `$` for commands run as our regular user, and `#`
for commands we should be running as an administrator.
The Rust compiler runs on, and compiles to, a great number of platforms, but is
best supported on Linux, Mac, and Windows, on the x86 and x86-64 CPU
architecture. There are official builds of the Rust compiler and standard
library for these platforms and more. [For full details on Rust platform support
see the website][platform-support].

## Platform support

The Rust compiler runs on, and compiles to, a great number of platforms, though
not all platforms are equally supported. Rust's support levels are organized
into three tiers, each with a different set of guarantees.

Platforms are identified by their "target triple" which is the string to inform
the compiler what kind of output should be produced. The columns below indicate
whether the corresponding component works on the specified platform.

### Tier 1

Tier 1 platforms can be thought of as "guaranteed to build and work".
Specifically they will each satisfy the following requirements:

* Automated testing is set up to run tests for the platform.
* Landing changes to the `rust-lang/rust` repository's master branch is gated on
tests passing.
* Official release artifacts are provided for the platform.
* Documentation for how to use and how to build the platform is available.

| Target | std |rustc|cargo| notes |
|-------------------------------|-----|-----|-----|----------------------------|
| `i686-apple-darwin` |||| 32-bit OSX (10.7+, Lion+) |
| `i686-pc-windows-gnu` |||| 32-bit MinGW (Windows 7+) |
| `i686-pc-windows-msvc` |||| 32-bit MSVC (Windows 7+) |
| `i686-unknown-linux-gnu` |||| 32-bit Linux (2.6.18+) |
| `x86_64-apple-darwin` |||| 64-bit OSX (10.7+, Lion+) |
| `x86_64-pc-windows-gnu` |||| 64-bit MinGW (Windows 7+) |
| `x86_64-pc-windows-msvc` |||| 64-bit MSVC (Windows 7+) |
| `x86_64-unknown-linux-gnu` |||| 64-bit Linux (2.6.18+) |

### Tier 2

Tier 2 platforms can be thought of as "guaranteed to build". Automated tests
are not run so it's not guaranteed to produce a working build, but platforms
often work to quite a good degree and patches are always welcome! Specifically,
these platforms are required to have each of the following:

* Automated building is set up, but may not be running tests.
* Landing changes to the `rust-lang/rust` repository's master branch is gated on
platforms **building**. Note that this means for some platforms only the
standard library is compiled, but for others the full bootstrap is run.
* Official release artifacts are provided for the platform.

| Target | std |rustc|cargo| notes |
|-------------------------------|-----|-----|-----|----------------------------|
| `aarch64-apple-ios` || | | ARM64 iOS |
| `aarch64-unknown-linux-gnu` |||| ARM64 Linux (2.6.18+) |
| `arm-linux-androideabi` || | | ARM Android |
| `arm-unknown-linux-gnueabi` |||| ARM Linux (2.6.18+) |
| `arm-unknown-linux-gnueabihf` |||| ARM Linux (2.6.18+) |
| `armv7-apple-ios` || | | ARM iOS |
|`armv7-unknown-linux-gnueabihf`|||| ARMv7 Linux (2.6.18+) |
| `armv7s-apple-ios` || | | ARM iOS |
| `i386-apple-ios` || | | 32-bit x86 iOS |
| `i586-pc-windows-msvc` || | | 32-bit Windows w/o SSE |
| `mips-unknown-linux-gnu` || | | MIPS Linux (2.6.18+) |
| `mips-unknown-linux-musl` || | | MIPS Linux with MUSL |
| `mipsel-unknown-linux-gnu` || | | MIPS (LE) Linux (2.6.18+) |
| `mipsel-unknown-linux-musl` || | | MIPS (LE) Linux with MUSL |
| `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+) |
| `x86_64-apple-ios` || | | 64-bit x86 iOS |
| `x86_64-rumprun-netbsd` || | | 64-bit NetBSD Rump Kernel |
| `x86_64-unknown-freebsd` |||| 64-bit FreeBSD |
| `x86_64-unknown-linux-musl` || | | 64-bit Linux with MUSL |
| `x86_64-unknown-netbsd` |||| 64-bit NetBSD |

### Tier 3

Tier 3 platforms are those which Rust has support for, but landing changes is
not gated on the platform either building or passing tests. Working builds for
these platforms may be spotty as their reliability is often defined in terms of
community contributions. Additionally, release artifacts and installers are not
provided, but there may be community infrastructure producing these in
unofficial locations.

| Target | std |rustc|cargo| notes |
|-------------------------------|-----|-----|-----|----------------------------|
| `aarch64-linux-android` || | | ARM64 Android |
| `armv7-linux-androideabi` || | | ARM-v7a Android |
| `i686-linux-android` || | | 32-bit x86 Android |
| `i686-pc-windows-msvc` (XP) || | | Windows XP support |
| `i686-unknown-freebsd` |||| 32-bit FreeBSD |
| `x86_64-pc-windows-msvc` (XP) || | | Windows XP support |
| `x86_64-sun-solaris` ||| | 64-bit Solaris/SunOS |
| `x86_64-unknown-bitrig` ||| | 64-bit Bitrig |
| `x86_64-unknown-dragonfly` ||| | 64-bit DragonFlyBSD |
| `x86_64-unknown-openbsd` ||| | 64-bit OpenBSD |

Note that this table can be expanded over time, this isn't the exhaustive set of
tier 3 platforms that will ever be!
[platform-support]: https://forge.rust-lang.org/platform-support.html

## Installing on Linux or Mac

Expand Down
66 changes: 43 additions & 23 deletions src/doc/book/guessing-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ has a command that does that for us. Let’s give it a shot:
```bash
$ cd ~/projects
$ cargo new guessing_game --bin
Created binary (application) `guessing_game` project
$ cd guessing_game
```

Expand Down Expand Up @@ -51,6 +52,7 @@ Let’s try compiling what Cargo gave us:
```{bash}
$ cargo build
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.53 secs
```

Excellent! Open up your `src/main.rs` again. We’ll be writing all of
Expand All @@ -61,6 +63,7 @@ Remember the `run` command from last chapter? Try it out again here:
```bash
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/guessing_game`
Hello, world!
```
Expand Down Expand Up @@ -282,10 +285,13 @@ we’ll get a warning:
```bash
$ cargo build
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
src/main.rs:10:5: 10:39 warning: unused result which must be used,
#[warn(unused_must_use)] on by default
src/main.rs:10 io::stdin().read_line(&mut guess);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: unused result which must be used, #[warn(unused_must_use)] on by default
--> src/main.rs:10:5
|
10 | io::stdin().read_line(&mut guess);
| ^

Finished debug [unoptimized + debuginfo] target(s) in 0.42 secs
```

Rust warns us that we haven’t used the `Result` value. This warning comes from
Expand Down Expand Up @@ -321,6 +327,7 @@ Anyway, that’s the tour. We can run what we have with `cargo run`:
```bash
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.44 secs
Running `target/debug/guessing_game`
Guess the number!
Please input your guess.
Expand Down Expand Up @@ -373,11 +380,12 @@ Now, without changing any of our code, let’s build our project:
```bash
$ cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
Downloading rand v0.3.8
Downloading libc v0.1.6
Compiling libc v0.1.6
Compiling rand v0.3.8
Downloading rand v0.3.14
Downloading libc v0.2.17
Compiling libc v0.2.17
Compiling rand v0.3.14
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 5.88 secs
```

(You may see different versions, of course.)
Expand All @@ -399,22 +407,24 @@ If we run `cargo build` again, we’ll get different output:

```bash
$ cargo build
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
```

That’s right, no output! Cargo knows that our project has been built, and that
That’s right, nothing was done! Cargo knows that our project has been built, and that
all of its dependencies are built, and so there’s no reason to do all that
stuff. With nothing to do, it simply exits. If we open up `src/main.rs` again,
make a trivial change, and then save it again, we’ll only see one line:
make a trivial change, and then save it again, we’ll only see two lines:

```bash
$ cargo build
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.45 secs
```

So, we told Cargo we wanted any `0.3.x` version of `rand`, and so it fetched the latest
version at the time this was written, `v0.3.8`. But what happens when next
week, version `v0.3.9` comes out, with an important bugfix? While getting
bugfixes is important, what if `0.3.9` contains a regression that breaks our
version at the time this was written, `v0.3.14`. But what happens when next
week, version `v0.3.15` comes out, with an important bugfix? While getting
bugfixes is important, what if `0.3.15` contains a regression that breaks our
code?

The answer to this problem is the `Cargo.lock` file you’ll now find in your
Expand All @@ -423,11 +433,11 @@ figures out all of the versions that fit your criteria, and then writes them
to the `Cargo.lock` file. When you build your project in the future, Cargo
will see that the `Cargo.lock` file exists, and then use that specific version
rather than do all the work of figuring out versions again. This lets you
have a repeatable build automatically. In other words, we’ll stay at `0.3.8`
have a repeatable build automatically. In other words, we’ll stay at `0.3.14`
until we explicitly upgrade, and so will anyone who we share our code with,
thanks to the lock file.

What about when we _do_ want to use `v0.3.9`? Cargo has another command,
What about when we _do_ want to use `v0.3.15`? Cargo has another command,
`update`, which says ‘ignore the lock, figure out all the latest versions that
fit what we’ve specified. If that works, write those versions out to the lock
file’. But, by default, Cargo will only look for versions larger than `0.3.0`
Expand Down Expand Up @@ -510,13 +520,15 @@ Try running our new program a few times:
```bash
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.55 secs
Running `target/debug/guessing_game`
Guess the number!
The secret number is: 7
Please input your guess.
4
You guessed: 4
$ cargo run
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/guessing_game`
Guess the number!
The secret number is: 83
Expand Down Expand Up @@ -618,15 +630,20 @@ I did mention that this won’t quite compile yet, though. Let’s try it:
```bash
$ cargo build
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
src/main.rs:28:21: 28:35 error: mismatched types:
expected `&collections::string::String`,
found `&_`
(expected struct `collections::string::String`,
found integral variable) [E0308]
src/main.rs:28 match guess.cmp(&secret_number) {
^~~~~~~~~~~~~~
error[E0308]: mismatched types
--> src/main.rs:23:21
|
23 | match guess.cmp(&secret_number) {
| ^^^^^^^^^^^^^^ expected struct `std::string::String`, found integral variable
|
= note: expected type `&std::string::String`
= note: found type `&{integer}`

error: aborting due to previous error
Could not compile `guessing_game`.

error: Could not compile `guessing_game`.

To learn more, run the command again with --verbose.
```
Whew! This is a big error. The core of it is that we have ‘mismatched types’.
Expand Down Expand Up @@ -722,6 +739,7 @@ Let’s try our program out!
```bash
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.57 secs
Running `target/guessing_game`
Guess the number!
The secret number is: 58
Expand Down Expand Up @@ -785,6 +803,7 @@ and quit. Observe:
```bash
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.58 secs
Running `target/guessing_game`
Guess the number!
The secret number is: 59
Expand Down Expand Up @@ -919,6 +938,7 @@ Now we should be good! Let’s try:
```bash
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Finished debug [unoptimized + debuginfo] target(s) in 0.57 secs
Running `target/guessing_game`
Guess the number!
The secret number is: 61
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write something like this:

```rust,ignore
struct Point {
mut x: i32,
mut x: i32, // This causes an error.
y: i32,
}
```
Expand Down
5 changes: 5 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ separately by extracting documentation attributes from their source code. Many
of the features that one might expect to be language features are library
features in Rust, so what you're looking for may be there, not here.

Finally, this document is not normative. It may include details that are
specific to `rustc` itself, and should not be taken as a specification for
the Rust language. We intend to produce such a document someday, but this
is what we have for now.

You may also be interested in the [grammar].

[book]: book/index.html
Expand Down
16 changes: 11 additions & 5 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,14 @@ impl<T: ?Sized> Arc<T> {

/// Gets the number of [`Weak`][weak] pointers to this value.
///
/// Be careful how you use this information, because another thread
/// may change the weak count at any time.
///
/// [weak]: struct.Weak.html
///
/// # Safety
///
/// This method by itself is safe, but using it correctly requires extra care.
/// Another thread can change the weak count at any time,
/// including potentially between calling this method and acting on the result.
///
/// # Examples
///
/// ```
Expand All @@ -409,8 +412,11 @@ impl<T: ?Sized> Arc<T> {

/// Gets the number of strong (`Arc`) pointers to this value.
///
/// Be careful how you use this information, because another thread
/// may change the strong count at any time.
/// # Safety
///
/// This method by itself is safe, but using it correctly requires extra care.
/// Another thread can change the strong count at any time,
/// including potentially between calling this method and acting on the result.
///
/// # Examples
///
Expand Down
24 changes: 16 additions & 8 deletions src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,14 @@ impl<'a, I: ExactSizeIterator + ?Sized> ExactSizeIterator for &'a mut I {}

/// Trait to represent types that can be created by summing up an iterator.
///
/// This trait is used to implement the `sum` method on iterators. Types which
/// implement the trait can be generated by the `sum` method. Like
/// `FromIterator` this trait should rarely be called directly and instead
/// interacted with through `Iterator::sum`.
/// This trait is used to implement the [`sum()`] method on iterators. Types which
/// implement the trait can be generated by the [`sum()`] method. Like
/// [`FromIterator`] this trait should rarely be called directly and instead
/// interacted with through [`Iterator::sum()`].
///
/// [`sum()`]: ../../std/iter/trait.Sum.html#tymethod.sum
/// [`FromIterator`]: ../../std/iter/trait.FromIterator.html
/// [`Iterator::sum()`]: ../../std/iter/trait.Iterator.html#method.sum
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
pub trait Sum<A = Self>: Sized {
/// Method which takes an iterator and generates `Self` from the elements by
Expand All @@ -571,10 +575,14 @@ pub trait Sum<A = Self>: Sized {
/// Trait to represent types that can be created by multiplying elements of an
/// iterator.
///
/// This trait is used to implement the `product` method on iterators. Types
/// which implement the trait can be generated by the `product` method. Like
/// `FromIterator` this trait should rarely be called directly and instead
/// interacted with through `Iterator::product`.
/// This trait is used to implement the [`product()`] method on iterators. Types
/// which implement the trait can be generated by the [`product()`] method. Like
/// [`FromIterator`] this trait should rarely be called directly and instead
/// interacted with through [`Iterator::product()`].
///
/// [`product()`]: ../../std/iter/trait.Product.html#tymethod.product
/// [`FromIterator`]: ../../std/iter/trait.FromIterator.html
/// [`Iterator::product()`]: ../../std/iter/trait.Iterator.html#method.product
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
pub trait Product<A = Self>: Sized {
/// Method which takes an iterator and generates `Self` from the elements by
Expand Down
Loading

0 comments on commit 02aa428

Please sign in to comment.