Skip to content

Commit b7fb575

Browse files
committed
Auto merge of #24512 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #23782, #24455, #24490, #24493, #24494, #24496, #24498, #24499, #24501, #24502, #24506, #24507, #24508, #24509, #24510 - Failed merges: #24488
2 parents 7fbedc5 + a4be1ec commit b7fb575

19 files changed

+175
-62
lines changed

src/doc/complement-design-faq.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Types which are [`Sync`][sync] are thread-safe when multiple shared
5656
references to them are used concurrently. Types which are not `Sync` are not
5757
thread-safe, and thus when used in a global require unsafe code to use.
5858

59-
[sync]: core/kinds/trait.Sync.html
59+
[sync]: core/marker/trait.Sync.html
6060

6161
### If mutable static items that implement `Sync` are safe, why is taking &mut SHARABLE unsafe?
6262

@@ -139,7 +139,7 @@ and explicitly calling the `clone` method. Making user-defined copy operators
139139
explicit surfaces the underlying complexity, forcing the developer to opt-in
140140
to potentially expensive operations.
141141

142-
[copy]: core/kinds/trait.Copy.html
142+
[copy]: core/marker/trait.Copy.html
143143
[clone]: core/clone/trait.Clone.html
144144

145145
## No move constructors

src/doc/reference.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,14 @@ The following configurations must be defined by the implementation:
21772177
* `unix`. See `target_family`.
21782178
* `windows`. See `target_family`.
21792179

2180+
You can also set another attribute based on a `cfg` variable with `cfg_attr`:
2181+
2182+
```rust,ignore
2183+
#[cfg_attr(a, b)]
2184+
```
2185+
2186+
Will be the same as `#[b]` if `a` is set by `cfg`, and nothing otherwise.
2187+
21802188
### Lint check attributes
21812189

21822190
A lint check names a potentially undesirable coding pattern, such as
@@ -2368,7 +2376,7 @@ The currently implemented features of the reference compiler are:
23682376
removed entirely for something more wholesome.
23692377

23702378
* `custom_attribute` - Allows the usage of attributes unknown to the compiler
2371-
so that new attributes can be added in a bacwards compatible
2379+
so that new attributes can be added in a backwards compatible
23722380
manner (RFC 572).
23732381

23742382
* `custom_derive` - Allows the use of `#[derive(Foo,Bar)]` as sugar for
@@ -2397,7 +2405,7 @@ The currently implemented features of the reference compiler are:
23972405
nasty hack that will certainly be removed.
23982406

23992407
* `main` - Allows use of the `#[main]` attribute, which changes the entry point
2400-
into a Rust program. This capabiilty is subject to change.
2408+
into a Rust program. This capability is subject to change.
24012409

24022410
* `macro_reexport` - Allows macros to be re-exported from one crate after being imported
24032411
from another. This feature was originally designed with the sole
@@ -2444,7 +2452,9 @@ The currently implemented features of the reference compiler are:
24442452
* `simd_ffi` - Allows use of SIMD vectors in signatures for foreign functions.
24452453
The SIMD interface is subject to change.
24462454

2447-
* `staged_api` - Allows usage of stability markers and `#![staged_api]` in a crate
2455+
* `staged_api` - Allows usage of stability markers and `#![staged_api]` in a
2456+
crate. Stability markers are also attributes: `#[stable]`,
2457+
`#[unstable]`, and `#[deprecated]` are the three levels.
24482458

24492459
* `static_assert` - The `#[static_assert]` functionality is experimental and
24502460
unstable. The attribute can be attached to a `static` of
@@ -2453,7 +2463,7 @@ The currently implemented features of the reference compiler are:
24532463
is unintuitive and suboptimal.
24542464

24552465
* `start` - Allows use of the `#[start]` attribute, which changes the entry point
2456-
into a Rust program. This capabiilty, especially the signature for the
2466+
into a Rust program. This capability, especially the signature for the
24572467
annotated function, is subject to change.
24582468

24592469
* `struct_inherit` - Allows using struct inheritance, which is barely

src/doc/trpl/closures.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ you tons of control over what your code does, and closures are no different.
205205

206206
Rust's implementation of closures is a bit different than other languages. They
207207
are effectively syntax sugar for traits. You'll want to make sure to have read
208-
the [traits chapter][traits] before this one, as well as the chapter on [static
209-
and dynamic dispatch][dispatch], which talks about trait objects.
208+
the [traits chapter][traits] before this one, as well as the chapter on [trait
209+
objects][trait-objects].
210210

211211
[traits]: traits.html
212-
[dispatch]: static-and-dynamic-dispatch.html
212+
[trait-objects]: trait-objects.html
213213

214214
Got all that? Good.
215215

src/doc/trpl/concurrency.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ Here's the error:
176176
^~~~~~~~~~~~~
177177
```
178178

179-
You see, [`Mutex`](std/sync/struct.Mutex.html) has a
180-
[`lock`](http://doc.rust-lang.org/nightly/std/sync/struct.Mutex.html#method.lock)
179+
You see, [`Mutex`](../std/sync/struct.Mutex.html) has a
180+
[`lock`](../std/sync/struct.Mutex.html#method.lock)
181181
method which has this signature:
182182

183183
```ignore

src/doc/trpl/documentation.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ $ rustdoc --test path/to/my/crate/root.rs
380380
$ cargo test
381381
```
382382

383-
That's right, `cargo test` tests embedded documentation too.
383+
That's right, `cargo test` tests embedded documentation too. However,
384+
`cargo test` will not test binary crates, only library ones. This is
385+
due to the way `rustdoc` works: it links against the library to be tested,
386+
but with a binary, there’s nothing to link to.
384387

385388
There are a few more annotations that are useful to help `rustdoc` do the right
386389
thing when testing your code:
@@ -560,3 +563,13 @@ This sets a few different options, with a logo, favicon, and a root URL.
560563
- `--html-before-content FILE`: includes the contents of FILE directly after
561564
`<body>`, before the rendered content (including the search bar).
562565
- `--html-after-content FILE`: includes the contents of FILE after all the rendered content.
566+
567+
## Security note
568+
569+
The Markdown in documentation comments is placed without processing into
570+
the final webpage. Be careful with literal HTML:
571+
572+
```rust
573+
/// <script>alert(document.cookie)</script>
574+
# fn foo() {}
575+
```

src/doc/trpl/error-handling.md

+19-16
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ panic. A *failure* is an error that can be recovered from in some way. A
2020
*panic* is an error that cannot be recovered from.
2121

2222
What do we mean by "recover"? Well, in most cases, the possibility of an error
23-
is expected. For example, consider the `from_str` function:
23+
is expected. For example, consider the `parse` function:
2424

25-
```{rust,ignore}
26-
from_str("5");
25+
```ignore
26+
"5".parse();
2727
```
2828

29-
This function takes a string argument and converts it into another type. But
30-
because it's a string, you can't be sure that the conversion actually works.
31-
For example, what should this convert to?
29+
This method converts a string into another type. But because it's a string, you
30+
can't be sure that the conversion actually works. For example, what should this
31+
convert to?
3232

33-
```{rust,ignore}
34-
from_str("hello5world");
33+
```ignore
34+
"hello5world".parse();
3535
```
3636

3737
This won't work. So we know that this function will only work properly for some
@@ -40,7 +40,8 @@ inputs. It's expected behavior. We call this kind of error a *failure*.
4040
On the other hand, sometimes, there are errors that are unexpected, or which
4141
we cannot recover from. A classic example is an `assert!`:
4242

43-
```{rust,ignore}
43+
```rust
44+
# let x = 5;
4445
assert!(x == 5);
4546
```
4647

@@ -119,17 +120,19 @@ Rust calls these sorts of errors *panics*.
119120
# Handling errors with `Option` and `Result`
120121

121122
The simplest way to indicate that a function may fail is to use the `Option<T>`
122-
type. Remember our `from_str()` example? Here's its type signature:
123+
type. For example, the `find` method on strings attempts to find a pattern
124+
in a string, and returns an `Option`:
123125

124-
```{rust,ignore}
125-
pub fn from_str<A: FromStr>(s: &str) -> Option<A>
126+
```rust
127+
let s = "foo";
128+
129+
assert_eq!(s.find('f'), Some(0));
130+
assert_eq!(s.find('z'), None);
126131
```
127132

128-
`from_str()` returns an `Option<A>`. If the conversion succeeds, it will return
129-
`Some(value)`, and if it fails, it will return `None`.
130133

131134
This is appropriate for the simplest of cases, but doesn't give us a lot of
132-
information in the failure case. What if we wanted to know _why_ the conversion
135+
information in the failure case. What if we wanted to know _why_ the function
133136
failed? For this, we can use the `Result<T, E>` type. It looks like this:
134137

135138
```rust
@@ -297,5 +300,5 @@ It's worth noting that you can only use `try!` from a function that returns a
297300
`Result`, which means that you cannot use `try!` inside of `main()`, because
298301
`main()` doesn't return anything.
299302

300-
`try!` makes use of [`From<Error>`](../std/convert/trait.From.hml) to determine
303+
`try!` makes use of [`From<Error>`](../std/convert/trait.From.html) to determine
301304
what to return in the error case.

src/doc/trpl/installing-rust.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ If not, there are a number of places where you can get help. The easiest is
9191
[Mibbit][mibbit]. Click that link, and you'll be chatting with other Rustaceans
9292
(a silly nickname we call ourselves), and we can help you out. Other great
9393
resources include [the user’s forum][users], and
94-
[Stack Overflow][stack overflow].
94+
[Stack Overflow][stackoverflow].
9595

9696
[irc]: irc://irc.mozilla.org/#rust
9797
[mibbit]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust
9898
[users]: http://users.rust-lang.org/
99-
[stack overflow]: http://stackoverflow.com/questions/tagged/rust
99+
[stackoverflow]: http://stackoverflow.com/questions/tagged/rust

src/doc/trpl/macros.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mind.
3333
You may have seen the `vec!` macro, used to initialize a [vector][] with any
3434
number of elements.
3535

36-
[vector]: arrays-vectors-and-slices.html
36+
[vector]: vectors.html
3737

3838
```rust
3939
let x: Vec<u32> = vec![1, 2, 3];

src/doc/trpl/primitive-types.md

+24-8
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ In systems programming languages, strings are a bit more complex than in other
216216
languages. For now, just read `&str` as a *string slice*, and we’ll learn more
217217
soon.
218218

219+
You can assign one tuple into another, if they have the same contained types
220+
and [arity]. Tuples have the same arity when they have the same length.
221+
222+
[arity]: glossary.html#arity
223+
224+
```rust
225+
let mut x = (1, 2); // x: (i32, i32)
226+
let y = (2, 3); // y: (i32, i32)
227+
228+
x = y;
229+
```
230+
219231
You can access the fields in a tuple through a *destructuring let*. Here’s
220232
an example:
221233

@@ -235,20 +247,24 @@ or "breaks up," the tuple, and assigns the bits to three bindings.
235247

236248
This pattern is very powerful, and we’ll see it repeated more later.
237249

238-
There are also a few things you can do with a tuple as a whole, without
239-
destructuring. You can assign one tuple into another, if they have the same
240-
contained types and [arity]. Tuples have the same arity when they have the same
241-
length.
250+
## Tuple Indexing
251+
252+
You can also access fields of a tuple with indexing syntax:
242253

243-
[arity]: glossary.html#arity
244254

245255
```rust
246-
let mut x = (1, 2); // x: (i32, i32)
247-
let y = (2, 3); // y: (i32, i32)
256+
let tuple = (1, 2, 3);
248257

249-
x = y;
258+
let x = tuple.0;
259+
let y = tuple.1;
260+
let z = tuple.2;
261+
262+
println!("x is {}", x);
250263
```
251264

265+
Like array indexing, it starts at zero, but unlike array indexing, it uses a
266+
`.`, rather than `[]`s.
267+
252268
You can find more documentation for tuples [in the standard library
253269
documentation][tuple].
254270

src/libcore/iter.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ pub trait Iterator {
179179

180180
/// Creates an iterator that iterates over both this and the specified
181181
/// iterators simultaneously, yielding the two elements as pairs. When
182-
/// either iterator returns None, all further invocations of next() will
183-
/// return None.
182+
/// either iterator returns `None`, all further invocations of next() will
183+
/// return `None`.
184184
///
185185
/// # Examples
186186
///
@@ -254,7 +254,7 @@ pub trait Iterator {
254254
}
255255

256256
/// Creates an iterator that both filters and maps elements.
257-
/// If the specified function returns None, the element is skipped.
257+
/// If the specified function returns `None`, the element is skipped.
258258
/// Otherwise the option is unwrapped and the new value is yielded.
259259
///
260260
/// # Examples
@@ -403,7 +403,7 @@ pub trait Iterator {
403403
/// Creates a new iterator that behaves in a similar fashion to fold.
404404
/// There is a state which is passed between each iteration and can be
405405
/// mutated as necessary. The yielded values from the closure are yielded
406-
/// from the Scan instance when not None.
406+
/// from the Scan instance when not `None`.
407407
///
408408
/// # Examples
409409
///
@@ -701,7 +701,7 @@ pub trait Iterator {
701701

702702
/// Returns the index of the last element satisfying the specified predicate
703703
///
704-
/// If no element matches, None is returned.
704+
/// If no element matches, `None` is returned.
705705
///
706706
/// Does not consume the iterator *before* the first found element.
707707
///

src/libcore/raw.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ impl<T> Clone for Slice<T> {
7171
/// The representation of a trait object like `&SomeTrait`.
7272
///
7373
/// This struct has the same layout as types like `&SomeTrait` and
74-
/// `Box<AnotherTrait>`. The [Static and Dynamic Dispatch chapter of the
74+
/// `Box<AnotherTrait>`. The [Trait Objects chapter of the
7575
/// Book][moreinfo] contains more details about the precise nature of
7676
/// these internals.
7777
///
78-
/// [moreinfo]: ../../book/static-and-dynamic-dispatch.html#representation
78+
/// [moreinfo]: ../../book/trait-objects.html#representation
7979
///
8080
/// `TraitObject` is guaranteed to match layouts, but it is not the
8181
/// type of trait objects (e.g. the fields are not directly accessible

src/libcore/result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@
8686
//! useful value.
8787
//!
8888
//! Consider the `write_all` method defined for I/O types
89-
//! by the [`Write`](../io/trait.Write.html) trait:
89+
//! by the [`Write`](../../std/io/trait.Write.html) trait:
9090
//!
9191
//! ```
9292
//! use std::io;
9393
//!
94-
//! trait Writer {
94+
//! trait Write {
9595
//! fn write_all(&mut self, bytes: &[u8]) -> Result<(), io::Error>;
9696
//! }
9797
//! ```

0 commit comments

Comments
 (0)