Skip to content

Commit c0eb938

Browse files
committed
Auto merge of #24674 - alexcrichton:rollup, r=alexcrichton
2 parents 2baf348 + 5815064 commit c0eb938

File tree

315 files changed

+2574
-8309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+2574
-8309
lines changed

mk/main.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
######################################################################
1414

1515
# The version number
16-
CFG_RELEASE_NUM=1.0.0
16+
CFG_RELEASE_NUM=1.1.0
1717

1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release
2020
# versions (section 9)
21-
CFG_PRERELEASE_VERSION=.3
21+
CFG_PRERELEASE_VERSION=.1
2222

2323
CFG_FILENAME_EXTRA=4e7c5e5c
2424

src/doc/trpl/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ is the first. After this:
2424
* [Syntax and Semantics][ss] - Each bit of Rust, broken down into small chunks.
2525
* [Nightly Rust][nr] - Cutting-edge features that aren’t in stable builds yet.
2626
* [Glossary][gl] - A reference of terms used in the book.
27+
* [Academic Research][ar] - Literature that influenced Rust.
2728

2829
[gs]: getting-started.html
2930
[lr]: learn-rust.html
3031
[er]: effective-rust.html
3132
[ss]: syntax-and-semantics.html
3233
[nr]: nightly-rust.html
3334
[gl]: glossary.html
35+
[ar]: academic-research.html
3436

3537
After reading this introduction, you’ll want to dive into either ‘Learn Rust’
3638
or ‘Syntax and Semantics’, depending on your preference: ‘Learn Rust’ if you

src/doc/trpl/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
* [Deref coercions](deref-coercions.md)
5656
* [Macros](macros.md)
5757
* [Raw Pointers](raw-pointers.md)
58+
* [`unsafe`](unsafe.md)
5859
* [Nightly Rust](nightly-rust.md)
5960
* [Compiler Plugins](compiler-plugins.md)
6061
* [Inline Assembly](inline-assembly.md)

src/doc/trpl/associated-types.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
% Associated Types
22

3-
Associated types are a powerful part of Rust's type system. They're related to
4-
the idea of a 'type family', in other words, grouping multiple types together. That
5-
description is a bit abstract, so let's dive right into an example. If you want
3+
Associated types are a powerful part of Rusts type system. Theyre related to
4+
the idea of a type family, in other words, grouping multiple types together. That
5+
description is a bit abstract, so lets dive right into an example. If you want
66
to write a `Graph` trait, you have two types to be generic over: the node type
77
and the edge type. So you might write a trait, `Graph<N, E>`, that looks like
88
this:
@@ -48,11 +48,11 @@ fn distance<G: Graph>(graph: &G, start: &G::N, end: &G::N) -> uint { ... }
4848

4949
No need to deal with the `E`dge type here!
5050

51-
Let's go over all this in more detail.
51+
Lets go over all this in more detail.
5252

5353
## Defining associated types
5454

55-
Let's build that `Graph` trait. Here's the definition:
55+
Lets build that `Graph` trait. Heres the definition:
5656

5757
```rust
5858
trait Graph {
@@ -86,7 +86,7 @@ trait Graph {
8686
## Implementing associated types
8787

8888
Just like any trait, traits that use associated types use the `impl` keyword to
89-
provide implementations. Here's a simple implementation of Graph:
89+
provide implementations. Heres a simple implementation of Graph:
9090

9191
```rust
9292
# trait Graph {
@@ -118,13 +118,13 @@ impl Graph for MyGraph {
118118
This silly implementation always returns `true` and an empty `Vec<Edge>`, but it
119119
gives you an idea of how to implement this kind of thing. We first need three
120120
`struct`s, one for the graph, one for the node, and one for the edge. If it made
121-
more sense to use a different type, that would work as well, we're just going to
121+
more sense to use a different type, that would work as well, were just going to
122122
use `struct`s for all three here.
123123

124124
Next is the `impl` line, which is just like implementing any other trait.
125125

126126
From here, we use `=` to define our associated types. The name the trait uses
127-
goes on the left of the `=`, and the concrete type we're `impl`ementing this
127+
goes on the left of the `=`, and the concrete type were `impl`ementing this
128128
for goes on the right. Finally, we use the concrete types in our function
129129
declarations.
130130

src/doc/trpl/casting-between-types.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let b = a as u32; // four eights makes 32
3333

3434
It’s a ‘non-scalar cast’ because we have multiple values here: the four
3535
elements of the array. These kinds of casts are very dangerous, because they
36-
make assumptions about the way that multiple underlying strucutres are
36+
make assumptions about the way that multiple underlying structures are
3737
implemented. For this, we need something more dangerous.
3838

3939
# `transmute`
@@ -59,7 +59,7 @@ unsafe {
5959
}
6060
```
6161

62-
We have to wrap the operation in an `unsafe` block, but this will compile
62+
We have to wrap the operation in an `unsafe` block for this to compile
6363
successfully. Technically, only the `mem::transmute` call itself needs to be in
6464
the block, but it's nice in this case to enclose everything related, so you
6565
know where to look. In this case, the details about `a` are also important, and

src/doc/trpl/closures.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
% Closures
22

33
Rust not only has named functions, but anonymous functions as well. Anonymous
4-
functions that have an associated environment are called 'closures', because they
4+
functions that have an associated environment are called closures, because they
55
close over an environment. Rust has a really great implementation of them, as
6-
we'll see.
6+
well see.
77

88
# Syntax
99

@@ -15,7 +15,7 @@ let plus_one = |x: i32| x + 1;
1515
assert_eq!(2, plus_one(1));
1616
```
1717

18-
We create a binding, `plus_one`, and assign it to a closure. The closure's
18+
We create a binding, `plus_one`, and assign it to a closure. The closures
1919
arguments go between the pipes (`|`), and the body is an expression, in this
2020
case, `x + 1`. Remember that `{ }` is an expression, so we can have multi-line
2121
closures too:
@@ -33,7 +33,7 @@ let plus_two = |x| {
3333
assert_eq!(4, plus_two(2));
3434
```
3535

36-
You'll notice a few things about closures that are a bit different than regular
36+
Youll notice a few things about closures that are a bit different than regular
3737
functions defined with `fn`. The first of which is that we did not need to
3838
annotate the types of arguments the closure takes or the values it returns. We
3939
can:
@@ -44,13 +44,13 @@ let plus_one = |x: i32| -> i32 { x + 1 };
4444
assert_eq!(2, plus_one(1));
4545
```
4646

47-
But we don't have to. Why is this? Basically, it was chosen for ergonomic reasons.
47+
But we dont have to. Why is this? Basically, it was chosen for ergonomic reasons.
4848
While specifying the full type for named functions is helpful with things like
4949
documentation and type inference, the types of closures are rarely documented
5050
since they’re anonymous, and they don’t cause the kinds of error-at-a-distance
5151
that inferring named function types can.
5252

53-
The second is that the syntax is similar, but a bit different. I've added spaces
53+
The second is that the syntax is similar, but a bit different. Ive added spaces
5454
here to make them look a little closer:
5555

5656
```rust
@@ -59,11 +59,11 @@ let plus_one_v2 = |x: i32 | -> i32 { x + 1 };
5959
let plus_one_v3 = |x: i32 | x + 1 ;
6060
```
6161

62-
Small differences, but they're similar in ways.
62+
Small differences, but theyre similar in ways.
6363

6464
# Closures and their environment
6565

66-
Closures are called such because they 'close over their environment.' It
66+
Closures are called such because they close over their environment’. It
6767
looks like this:
6868

6969
```rust
@@ -105,7 +105,7 @@ fn main() {
105105
^
106106
```
107107

108-
A verbose yet helpful error message! As it says, we can't take a mutable borrow
108+
A verbose yet helpful error message! As it says, we cant take a mutable borrow
109109
on `num` because the closure is already borrowing it. If we let the closure go
110110
out of scope, we can:
111111

@@ -140,7 +140,7 @@ let takes_nums = || nums;
140140
```
141141

142142
`Vec<T>` has ownership over its contents, and therefore, when we refer to it
143-
in our closure, we have to take ownership of `nums`. It's the same as if we'd
143+
in our closure, we have to take ownership of `nums`. Its the same as if wed
144144
passed `nums` to a function that took ownership of it.
145145

146146
## `move` closures
@@ -156,7 +156,7 @@ let owns_num = move |x: i32| x + num;
156156

157157
Now, even though the keyword is `move`, the variables follow normal move semantics.
158158
In this case, `5` implements `Copy`, and so `owns_num` takes ownership of a copy
159-
of `num`. So what's the difference?
159+
of `num`. So whats the difference?
160160

161161
```rust
162162
let mut num = 5;
@@ -171,11 +171,11 @@ assert_eq!(10, num);
171171
```
172172

173173
So in this case, our closure took a mutable reference to `num`, and then when
174-
we called `add_num`, it mutated the underlying value, as we'd expect. We also
174+
we called `add_num`, it mutated the underlying value, as wed expect. We also
175175
needed to declare `add_num` as `mut` too, because we’re mutating its
176176
environment.
177177

178-
If we change to a `move` closure, it's different:
178+
If we change to a `move` closure, its different:
179179

180180
```rust
181181
let mut num = 5;
@@ -203,8 +203,8 @@ you tons of control over what your code does, and closures are no different.
203203

204204
# Closure implementation
205205

206-
Rust's implementation of closures is a bit different than other languages. They
207-
are effectively syntax sugar for traits. You'll want to make sure to have read
206+
Rusts implementation of closures is a bit different than other languages. They
207+
are effectively syntax sugar for traits. Youll want to make sure to have read
208208
the [traits chapter][traits] before this one, as well as the chapter on [trait
209209
objects][trait-objects].
210210

@@ -237,9 +237,9 @@ pub trait FnOnce<Args> {
237237
# }
238238
```
239239

240-
You'll notice a few differences between these traits, but a big one is `self`:
240+
Youll notice a few differences between these traits, but a big one is `self`:
241241
`Fn` takes `&self`, `FnMut` takes `&mut self`, and `FnOnce` takes `self`. This
242-
covers all three kinds of `self` via the usual method call syntax. But we've
242+
covers all three kinds of `self` via the usual method call syntax. But weve
243243
split them up into three traits, rather than having a single one. This gives us
244244
a large amount of control over what kind of closures we can take.
245245

@@ -253,7 +253,7 @@ Now that we know that closures are traits, we already know how to accept and
253253
return closures: just like any other trait!
254254

255255
This also means that we can choose static vs dynamic dispatch as well. First,
256-
let's write a function which takes something callable, calls it, and returns
256+
lets write a function which takes something callable, calls it, and returns
257257
the result:
258258

259259
```rust
@@ -271,7 +271,7 @@ assert_eq!(3, answer);
271271
We pass our closure, `|x| x + 2`, to `call_with_one`. It just does what it
272272
suggests: it calls the closure, giving it `1` as an argument.
273273

274-
Let's examine the signature of `call_with_one` in more depth:
274+
Lets examine the signature of `call_with_one` in more depth:
275275

276276
```rust
277277
fn call_with_one<F>(some_closure: F) -> i32
@@ -280,7 +280,7 @@ fn call_with_one<F>(some_closure: F) -> i32
280280
```
281281

282282
We take one parameter, and it has the type `F`. We also return a `i32`. This part
283-
isn't interesting. The next part is:
283+
isnt interesting. The next part is:
284284

285285
```rust
286286
# fn call_with_one<F>(some_closure: F) -> i32
@@ -292,9 +292,9 @@ Because `Fn` is a trait, we can bound our generic with it. In this case, our clo
292292
takes a `i32` as an argument and returns an `i32`, and so the generic bound we use
293293
is `Fn(i32) -> i32`.
294294

295-
There's one other key point here: because we're bounding a generic with a
296-
trait, this will get monomorphized, and therefore, we'll be doing static
297-
dispatch into the closure. That's pretty neat. In many langauges, closures are
295+
Theres one other key point here: because were bounding a generic with a
296+
trait, this will get monomorphized, and therefore, well be doing static
297+
dispatch into the closure. Thats pretty neat. In many langauges, closures are
298298
inherently heap allocated, and will always involve dynamic dispatch. In Rust,
299299
we can stack allocate our closure environment, and statically dispatch the
300300
call. This happens quite often with iterators and their adapters, which often
@@ -320,7 +320,7 @@ to our closure when we pass it to `call_with_one`, so we use `&||`.
320320

321321
It’s very common for functional-style code to return closures in various
322322
situations. If you try to return a closure, you may run into an error. At
323-
first, it may seem strange, but we'll figure it out. Here's how you'd probably
323+
first, it may seem strange, but well figure it out. Heres how youd probably
324324
try to return a closure from a function:
325325

326326
```rust,ignore
@@ -361,7 +361,7 @@ In order to return something from a function, Rust needs to know what
361361
size the return type is. But since `Fn` is a trait, it could be various
362362
things of various sizes: many different types can implement `Fn`. An easy
363363
way to give something a size is to take a reference to it, as references
364-
have a known size. So we'd write this:
364+
have a known size. So wed write this:
365365

366366
```rust,ignore
367367
fn factory() -> &(Fn(i32) -> Vec<i32>) {
@@ -385,7 +385,7 @@ fn factory() -> &(Fn(i32) -> i32) {
385385
```
386386

387387
Right. Because we have a reference, we need to give it a lifetime. But
388-
our `factory()` function takes no arguments, so elision doesn't kick in
388+
our `factory()` function takes no arguments, so elision doesnt kick in
389389
here. What lifetime can we choose? `'static`:
390390

391391
```rust,ignore
@@ -414,15 +414,15 @@ error: mismatched types:
414414
415415
```
416416

417-
This error is letting us know that we don't have a `&'static Fn(i32) -> i32`,
417+
This error is letting us know that we dont have a `&'static Fn(i32) -> i32`,
418418
we have a `[closure <anon>:7:9: 7:20]`. Wait, what?
419419

420420
Because each closure generates its own environment `struct` and implementation
421421
of `Fn` and friends, these types are anonymous. They exist just solely for
422422
this closure. So Rust shows them as `closure <anon>`, rather than some
423423
autogenerated name.
424424

425-
But why doesn't our closure implement `&'static Fn`? Well, as we discussed before,
425+
But why doesnt our closure implement `&'static Fn`? Well, as we discussed before,
426426
closures borrow their environment. And in this case, our environment is based
427427
on a stack-allocated `5`, the `num` variable binding. So the borrow has a lifetime
428428
of the stack frame. So if we returned this closure, the function call would be
@@ -445,7 +445,7 @@ assert_eq!(6, answer);
445445
# }
446446
```
447447

448-
We use a trait object, by `Box`ing up the `Fn`. There's just one last problem:
448+
We use a trait object, by `Box`ing up the `Fn`. Theres just one last problem:
449449

450450
```text
451451
error: `num` does not live long enough
@@ -471,5 +471,5 @@ assert_eq!(6, answer);
471471
```
472472

473473
By making the inner closure a `move Fn`, we create a new stack frame for our
474-
closure. By `Box`ing it up, we've given it a known size, and allowing it to
474+
closure. By `Box`ing it up, weve given it a known size, and allowing it to
475475
escape our stack frame.

0 commit comments

Comments
 (0)