Skip to content

Commit

Permalink
Auto merge of #28769 - steveklabnik:rollup, r=steveklabnik
Browse files Browse the repository at this point in the history
- Successful merges: #28743, #28744, #28745, #28749, #28754, #28755, #28757, #28759, #28761, #28762, #28763, #28765
- Failed merges:
  • Loading branch information
bors committed Sep 30, 2015
2 parents dcb167e + 15ee0e9 commit 1c788d0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/doc/trpl/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Rust keeps track of these comments, and uses them when generating
documentation. This is important when documenting things like enums:

```rust
/// The `Option` type. See [the module level documentation](../) for more.
/// The `Option` type. See [the module level documentation](index.html) for more.
enum Option<T> {
/// No value
None,
Expand All @@ -57,7 +57,7 @@ enum Option<T> {
The above works, but this does not:

```rust,ignore
/// The `Option` type. See [the module level documentation](../) for more.
/// The `Option` type. See [the module level documentation](index.html) for more.
enum Option<T> {
None, /// No value
Some(T), /// Some value `T`
Expand Down
4 changes: 2 additions & 2 deletions src/doc/trpl/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ analysis is the only way to get at the value stored inside an `Option<T>`. This
means that you, as the programmer, must handle the case when an `Option<T>` is
`None` instead of `Some(t)`.

But wait, what about `unwrap` used in [`unwrap-double`](#code-unwrap-double)?
But wait, what about `unwrap`,which we used [`previously`](#code-unwrap-double)?
There was no case analysis there! Instead, the case analysis was put inside the
`unwrap` method for you. You could define it yourself if you want:

Expand Down Expand Up @@ -211,7 +211,7 @@ that makes `unwrap` ergonomic to use. Unfortunately, that `panic!` means that

### Composing `Option<T>` values

In [`option-ex-string-find`](#code-option-ex-string-find)
In an [example from before](#code-option-ex-string-find),
we saw how to use `find` to discover the extension in a file name. Of course,
not all file names have a `.` in them, so it's possible that the file name has
no extension. This *possibility of absence* is encoded into the types using
Expand Down
5 changes: 4 additions & 1 deletion src/doc/trpl/guessing-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ use std::io;
We’ll need to take user input, and then print the result as output. As such, we
need the `io` library from the standard library. Rust only imports a few things
by default into every program, [the ‘prelude’][prelude]. If it’s not in the
prelude, you’ll have to `use` it directly.
prelude, you’ll have to `use` it directly. There is also a second ‘prelude’, the
[`io` prelude][ioprelude], which serves a similar function: you import it, and it
imports a number of useful, `io`-related things.

[prelude]: ../std/prelude/index.html
[ioprelude]: ../std/io/prelude/index.html

```rust,ignore
fn main() {
Expand Down
11 changes: 8 additions & 3 deletions src/doc/trpl/primitive-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,18 @@ A ‘slice’ is a reference to (or “view” into) another data structure. The
useful for allowing safe, efficient access to a portion of an array without
copying. For example, you might want to reference just one line of a file read
into memory. By nature, a slice is not created directly, but from an existing
variable. Slices have a length, can be mutable or not, and in many ways behave
like arrays:
variable binding. Slices have a defined length, can be mutable or immutable.

## Slicing syntax

You can use a combo of `&` and `[]` to create a slice from various things. The
`&` indicates that slices are similar to references, and the `[]`s, with a
range, let you define the length of the slice:

```rust
let a = [0, 1, 2, 3, 4];
let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
let complete = &a[..]; // A slice containing all of the elements in a
let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
```

Slices have type `&[T]`. We’ll talk about that `T` when we cover
Expand Down
2 changes: 2 additions & 0 deletions src/doc/trpl/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,5 @@ documentation tests: the `_0` is generated for the module test, and `add_two_0`
for the function test. These will auto increment with names like `add_two_1` as
you add more examples.

We haven’t covered all of the details with writing documentation tests. For more,
please see the [Documentation chapter](documentation.html)
29 changes: 29 additions & 0 deletions src/doc/trpl/vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@ println!("The third element of v is {}", v[2]);

The indices count from `0`, so the third element is `v[2]`.

It’s also important to note that you must index with the `usize` type:

```ignore
let v = vec![1, 2, 3, 4, 5];
let i: usize = 0;
let j: i32 = 0;
// works
v[i];
// doesn’t
v[j];
```

Indexing with a non-`usize` type gives an error that looks like this:

```text
error: the trait `core::ops::Index<i32>` is not implemented for the type
`collections::vec::Vec<_>` [E0277]
v[j];
^~~~
note: the type `collections::vec::Vec<_>` cannot be indexed by `i32`
error: aborting due to previous error
```

There’s a lot of punctuation in that message, but the core of it makes sense:
you cannot index with an `i32`.

## Iterating

Once you have a vector, you can iterate through its elements with `for`. There
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ impl<T> [T] {
/// the index `mid` itself) and the second will contain all
/// indices from `[mid, len)` (excluding the index `len` itself).
///
/// # Panics
///
/// Panics if `mid > len`.
///
/// # Examples
Expand Down
18 changes: 9 additions & 9 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'a> Display for Arguments<'a> {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -393,7 +393,7 @@ pub trait Debug {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -435,7 +435,7 @@ pub trait Display {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -482,7 +482,7 @@ pub trait Octal {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -530,7 +530,7 @@ pub trait Binary {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -578,7 +578,7 @@ pub trait LowerHex {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -624,7 +624,7 @@ pub trait UpperHex {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -668,7 +668,7 @@ pub trait Pointer {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down Expand Up @@ -711,7 +711,7 @@ pub trait LowerExp {
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../index.html
/// [module]: ../../std/fmt/index.html
///
/// # Examples
///
Expand Down
7 changes: 7 additions & 0 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
/// throughout `std::io` take and provide types which implement the `Read`
/// trait.
///
/// Please note that each call to `read` may involve a system call, and
/// therefore, using something that implements [`BufRead`][bufread], such as
/// [`BufReader`][bufreader], will be more efficient.
///
/// [bufread]: trait.BufRead.html
/// [bufreader]: struct.BufReader.html
///
/// # Examples
///
/// [`File`][file]s implement `Read`:
Expand Down

0 comments on commit 1c788d0

Please sign in to comment.