Skip to content

Commit 1c788d0

Browse files
committed
Auto merge of #28769 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #28743, #28744, #28745, #28749, #28754, #28755, #28757, #28759, #28761, #28762, #28763, #28765 - Failed merges:
2 parents dcb167e + 15ee0e9 commit 1c788d0

File tree

9 files changed

+65
-17
lines changed

9 files changed

+65
-17
lines changed

src/doc/trpl/documentation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Rust keeps track of these comments, and uses them when generating
4545
documentation. This is important when documenting things like enums:
4646

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

5959
```rust,ignore
60-
/// The `Option` type. See [the module level documentation](../) for more.
60+
/// The `Option` type. See [the module level documentation](index.html) for more.
6161
enum Option<T> {
6262
None, /// No value
6363
Some(T), /// Some value `T`

src/doc/trpl/error-handling.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ analysis is the only way to get at the value stored inside an `Option<T>`. This
182182
means that you, as the programmer, must handle the case when an `Option<T>` is
183183
`None` instead of `Some(t)`.
184184

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

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

212212
### Composing `Option<T>` values
213213

214-
In [`option-ex-string-find`](#code-option-ex-string-find)
214+
In an [example from before](#code-option-ex-string-find),
215215
we saw how to use `find` to discover the extension in a file name. Of course,
216216
not all file names have a `.` in them, so it's possible that the file name has
217217
no extension. This *possibility of absence* is encoded into the types using

src/doc/trpl/guessing-game.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ use std::io;
9999
We’ll need to take user input, and then print the result as output. As such, we
100100
need the `io` library from the standard library. Rust only imports a few things
101101
by default into every program, [the ‘prelude’][prelude]. If it’s not in the
102-
prelude, you’ll have to `use` it directly.
102+
prelude, you’ll have to `use` it directly. There is also a second ‘prelude’, the
103+
[`io` prelude][ioprelude], which serves a similar function: you import it, and it
104+
imports a number of useful, `io`-related things.
103105

104106
[prelude]: ../std/prelude/index.html
107+
[ioprelude]: ../std/io/prelude/index.html
105108

106109
```rust,ignore
107110
fn main() {

src/doc/trpl/primitive-types.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,18 @@ A ‘slice’ is a reference to (or “view” into) another data structure. The
162162
useful for allowing safe, efficient access to a portion of an array without
163163
copying. For example, you might want to reference just one line of a file read
164164
into memory. By nature, a slice is not created directly, but from an existing
165-
variable. Slices have a length, can be mutable or not, and in many ways behave
166-
like arrays:
165+
variable binding. Slices have a defined length, can be mutable or immutable.
166+
167+
## Slicing syntax
168+
169+
You can use a combo of `&` and `[]` to create a slice from various things. The
170+
`&` indicates that slices are similar to references, and the `[]`s, with a
171+
range, let you define the length of the slice:
167172

168173
```rust
169174
let a = [0, 1, 2, 3, 4];
170-
let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
171175
let complete = &a[..]; // A slice containing all of the elements in a
176+
let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
172177
```
173178

174179
Slices have type `&[T]`. We’ll talk about that `T` when we cover

src/doc/trpl/testing.md

+2
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,5 @@ documentation tests: the `_0` is generated for the module test, and `add_two_0`
502502
for the function test. These will auto increment with names like `add_two_1` as
503503
you add more examples.
504504

505+
We haven’t covered all of the details with writing documentation tests. For more,
506+
please see the [Documentation chapter](documentation.html)

src/doc/trpl/vectors.md

+29
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@ println!("The third element of v is {}", v[2]);
3232

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

35+
It’s also important to note that you must index with the `usize` type:
36+
37+
```ignore
38+
let v = vec![1, 2, 3, 4, 5];
39+
40+
let i: usize = 0;
41+
let j: i32 = 0;
42+
43+
// works
44+
v[i];
45+
46+
// doesn’t
47+
v[j];
48+
```
49+
50+
Indexing with a non-`usize` type gives an error that looks like this:
51+
52+
```text
53+
error: the trait `core::ops::Index<i32>` is not implemented for the type
54+
`collections::vec::Vec<_>` [E0277]
55+
v[j];
56+
^~~~
57+
note: the type `collections::vec::Vec<_>` cannot be indexed by `i32`
58+
error: aborting due to previous error
59+
```
60+
61+
There’s a lot of punctuation in that message, but the core of it makes sense:
62+
you cannot index with an `i32`.
63+
3564
## Iterating
3665

3766
Once you have a vector, you can iterate through its elements with `for`. There

src/libcollections/slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ impl<T> [T] {
455455
/// the index `mid` itself) and the second will contain all
456456
/// indices from `[mid, len)` (excluding the index `len` itself).
457457
///
458+
/// # Panics
459+
///
458460
/// Panics if `mid > len`.
459461
///
460462
/// # Examples

src/libcore/fmt/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'a> Display for Arguments<'a> {
298298
///
299299
/// For more information on formatters, see [the module-level documentation][module].
300300
///
301-
/// [module]: ../index.html
301+
/// [module]: ../../std/fmt/index.html
302302
///
303303
/// # Examples
304304
///
@@ -393,7 +393,7 @@ pub trait Debug {
393393
///
394394
/// For more information on formatters, see [the module-level documentation][module].
395395
///
396-
/// [module]: ../index.html
396+
/// [module]: ../../std/fmt/index.html
397397
///
398398
/// # Examples
399399
///
@@ -435,7 +435,7 @@ pub trait Display {
435435
///
436436
/// For more information on formatters, see [the module-level documentation][module].
437437
///
438-
/// [module]: ../index.html
438+
/// [module]: ../../std/fmt/index.html
439439
///
440440
/// # Examples
441441
///
@@ -482,7 +482,7 @@ pub trait Octal {
482482
///
483483
/// For more information on formatters, see [the module-level documentation][module].
484484
///
485-
/// [module]: ../index.html
485+
/// [module]: ../../std/fmt/index.html
486486
///
487487
/// # Examples
488488
///
@@ -530,7 +530,7 @@ pub trait Binary {
530530
///
531531
/// For more information on formatters, see [the module-level documentation][module].
532532
///
533-
/// [module]: ../index.html
533+
/// [module]: ../../std/fmt/index.html
534534
///
535535
/// # Examples
536536
///
@@ -578,7 +578,7 @@ pub trait LowerHex {
578578
///
579579
/// For more information on formatters, see [the module-level documentation][module].
580580
///
581-
/// [module]: ../index.html
581+
/// [module]: ../../std/fmt/index.html
582582
///
583583
/// # Examples
584584
///
@@ -624,7 +624,7 @@ pub trait UpperHex {
624624
///
625625
/// For more information on formatters, see [the module-level documentation][module].
626626
///
627-
/// [module]: ../index.html
627+
/// [module]: ../../std/fmt/index.html
628628
///
629629
/// # Examples
630630
///
@@ -668,7 +668,7 @@ pub trait Pointer {
668668
///
669669
/// For more information on formatters, see [the module-level documentation][module].
670670
///
671-
/// [module]: ../index.html
671+
/// [module]: ../../std/fmt/index.html
672672
///
673673
/// # Examples
674674
///
@@ -711,7 +711,7 @@ pub trait LowerExp {
711711
///
712712
/// For more information on formatters, see [the module-level documentation][module].
713713
///
714-
/// [module]: ../index.html
714+
/// [module]: ../../std/fmt/index.html
715715
///
716716
/// # Examples
717717
///

src/libstd/io/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
370370
/// throughout `std::io` take and provide types which implement the `Read`
371371
/// trait.
372372
///
373+
/// Please note that each call to `read` may involve a system call, and
374+
/// therefore, using something that implements [`BufRead`][bufread], such as
375+
/// [`BufReader`][bufreader], will be more efficient.
376+
///
377+
/// [bufread]: trait.BufRead.html
378+
/// [bufreader]: struct.BufReader.html
379+
///
373380
/// # Examples
374381
///
375382
/// [`File`][file]s implement `Read`:

0 commit comments

Comments
 (0)