Skip to content

Commit 507f8b8

Browse files
committed
Fix merge conflict and also add markdown formatting
2 parents 6e9e76a + 571f371 commit 507f8b8

File tree

123 files changed

+1293
-914
lines changed

Some content is hidden

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

123 files changed

+1293
-914
lines changed

configure

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ probe() {
106106
T=$(command -v $P 2>&1)
107107
if [ $? -eq 0 ]
108108
then
109-
VER0=$($P --version 2>/dev/null | head -1 \
110-
| sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
109+
VER0=$($P --version 2>/dev/null \
110+
| grep -o '[vV]\?[0-9][0-9.][a-z0-9.-]*' | head -1 )
111111
if [ $? -eq 0 -a "x${VER0}" != "x" ]
112112
then
113113
VER="($VER0)"
@@ -711,6 +711,20 @@ else
711711
probe_need CFG_GIT git
712712
fi
713713

714+
# Use `md5sum` on GNU platforms, or `md5 -q` on BSD
715+
probe CFG_MD5 md5
716+
probe CFG_MD5SUM md5sum
717+
if [ -n "$CFG_MD5" ]
718+
then
719+
CFG_HASH_COMMAND="$CFG_MD5 -q | head -c 8"
720+
elif [ -n "$CFG_MD5SUM" ]
721+
then
722+
CFG_HASH_COMMAND="$CFG_MD5SUM | head -c 8"
723+
else
724+
err 'could not find one of: md5 md5sum'
725+
fi
726+
putvar CFG_HASH_COMMAND
727+
714728
probe CFG_CLANG clang++
715729
probe CFG_CCACHE ccache
716730
probe CFG_GCC gcc

mk/main.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ CFG_RELEASE_NUM=1.1.0
2020
# versions (section 9)
2121
CFG_PRERELEASE_VERSION=.1
2222

23-
CFG_FILENAME_EXTRA=4e7c5e5c
23+
# Append a version-dependent hash to each library, so we can install different
24+
# versions in the same place
25+
CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE) | $(CFG_HASH_COMMAND))
2426

2527
ifeq ($(CFG_RELEASE_CHANNEL),stable)
2628
# This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"

src/doc/reference.md

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,8 @@ vtable when the trait is used as a [trait object](#trait-objects).
13461346
Traits are implemented for specific types through separate
13471347
[implementations](#implementations).
13481348

1349+
Consider the following trait:
1350+
13491351
```
13501352
# type Surface = i32;
13511353
# type BoundingBox = i32;
@@ -1360,6 +1362,20 @@ This defines a trait with two methods. All values that have
13601362
`draw` and `bounding_box` methods called, using `value.bounding_box()`
13611363
[syntax](#method-call-expressions).
13621364

1365+
Traits can include default implementations of methods, as in:
1366+
1367+
```
1368+
trait Foo {
1369+
fn bar(&self);
1370+
1371+
fn baz(&self) { println!("We called baz."); }
1372+
}
1373+
```
1374+
1375+
Here the `baz` method has a default implementation, so types that implement
1376+
`Foo` need only implement `bar`. It is also possible for implementing types
1377+
to override a method that has a default implementation.
1378+
13631379
Type parameters can be specified for a trait to make it generic. These appear
13641380
after the trait name, using the same syntax used in [generic
13651381
functions](#generic-functions).
@@ -1372,6 +1388,35 @@ trait Seq<T> {
13721388
}
13731389
```
13741390

1391+
It is also possible to define associated types for a trait. Consider the
1392+
following example of a `Container` trait. Notice how the type is available
1393+
for use in the method signatures:
1394+
1395+
```
1396+
trait Container {
1397+
type E;
1398+
fn empty() -> Self;
1399+
fn insert(&mut self, Self::E);
1400+
}
1401+
```
1402+
1403+
In order for a type to implement this trait, it must not only provide
1404+
implementations for every method, but it must specify the type `E`. Here's
1405+
an implementation of `Container` for the standard library type `Vec`:
1406+
1407+
```
1408+
# trait Container {
1409+
# type E;
1410+
# fn empty() -> Self;
1411+
# fn insert(&mut self, Self::E);
1412+
# }
1413+
impl<T> Container for Vec<T> {
1414+
type E = T;
1415+
fn empty() -> Vec<T> { Vec::new() }
1416+
fn insert(&mut self, x: T) { self.push(x); }
1417+
}
1418+
```
1419+
13751420
Generic functions may use traits as _bounds_ on their type parameters. This
13761421
will have two effects: only types that have the trait may instantiate the
13771422
parameter, and within the generic function, the methods of the trait can be
@@ -3470,13 +3515,23 @@ more of the closure traits:
34703515

34713516
### Trait objects
34723517

3473-
Every trait item (see [traits](#traits)) defines a type with the same name as
3474-
the trait. This type is called the _trait object_ of the trait. Trait objects
3475-
permit "late binding" of methods, dispatched using _virtual method tables_
3476-
("vtables"). Whereas most calls to trait methods are "early bound" (statically
3477-
resolved) to specific implementations at compile time, a call to a method on an
3478-
trait objects is only resolved to a vtable entry at compile time. The actual
3479-
implementation for each vtable entry can vary on an object-by-object basis.
3518+
In Rust, a type like `&SomeTrait` or `Box<SomeTrait>` is called a _trait object_.
3519+
Each instance of a trait object includes:
3520+
3521+
- a pointer to an instance of a type `T` that implements `SomeTrait`
3522+
- a _virtual method table_, often just called a _vtable_, which contains, for
3523+
each method of `SomeTrait` that `T` implements, a pointer to `T`'s
3524+
implementation (i.e. a function pointer).
3525+
3526+
The purpose of trait objects is to permit "late binding" of methods. A call to
3527+
a method on a trait object is only resolved to a vtable entry at compile time.
3528+
The actual implementation for each vtable entry can vary on an object-by-object
3529+
basis.
3530+
3531+
Note that for a trait object to be instantiated, the trait must be
3532+
_object-safe_. Object safety rules are defined in [RFC 255].
3533+
3534+
[RFC 255]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
34803535

34813536
Given a pointer-typed expression `E` of type `&T` or `Box<T>`, where `T`
34823537
implements trait `R`, casting `E` to the corresponding pointer type `&R` or

src/doc/trpl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ data, we call the `clone()` method. In this example, `y` is no longer a referenc
175175
to the vector stored in `x`, but a copy of its first element, `"Hello"`. Now
176176
that we don’t have a reference, our `push()` works just fine.
177177

178-
[move]: move-semantics.html
178+
[move]: ownership.html#move-semantics
179179

180180
If we truly want a reference, we need the other option: ensure that our reference
181181
goes out of scope before we try to do the mutation. That looks like this:

src/doc/trpl/dining-philosophers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ which blocks execution until the thread has completed execution. This ensures
450450
that the threads complete their work before the program exits.
451451

452452
If you run this program, you’ll see that the philosophers eat out of order!
453-
We have mult-threading!
453+
We have multi-threading!
454454

455455
```text
456456
Gilles Deleuze is eating.

src/doc/trpl/error-handling.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ match version {
181181
This function makes use of an enum, `ParseError`, to enumerate the various
182182
errors that can occur.
183183

184+
The [`Debug`](../std/fmt/trait.Debug.html) trait is what lets us print the enum value using the `{:?}` format operation.
185+
184186
# Non-recoverable errors with `panic!`
185187

186188
In the case of an error that is unexpected and not recoverable, the `panic!`

src/doc/trpl/iterators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ loop is just a handy way to write this `loop`/`match`/`break` construct.
4242
`for` loops aren't the only thing that uses iterators, however. Writing your
4343
own iterator involves implementing the `Iterator` trait. While doing that is
4444
outside of the scope of this guide, Rust provides a number of useful iterators
45-
to accomplish various threads. Before we talk about those, we should talk about a
45+
to accomplish various tasks. Before we talk about those, we should talk about a
4646
Rust anti-pattern. And that's using ranges like this.
4747

4848
Yes, we just talked about how ranges are cool. But ranges are also very

src/doc/trpl/the-stack-and-the-heap.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ This memory is kind of like a giant array: addresses start at zero and go
8080
up to the final number. So here’s a diagram of our first stack frame:
8181

8282
| Address | Name | Value |
83-
+---------+------+-------+
83+
|---------|------|-------|
8484
| 0 | x | 42 |
8585

8686
We’ve got `x` located at address `0`, with the value `42`.
8787

8888
When `foo()` is called, a new stack frame is allocated:
8989

9090
| Address | Name | Value |
91-
+---------+------+-------+
91+
|---------|------|-------|
9292
| 2 | z | 100 |
9393
| 1 | y | 5 |
9494
| 0 | x | 42 |
@@ -107,7 +107,7 @@ value being stored.
107107
After `foo()` is over, its frame is deallocated:
108108

109109
| Address | Name | Value |
110-
+---------+------+-------+
110+
|---------|------|-------|
111111
| 0 | x | 42 |
112112

113113
And then, after `main()`, even this last value goes away. Easy!
@@ -142,13 +142,13 @@ fn main() {
142142
Okay, first, we call `main()`:
143143

144144
| Address | Name | Value |
145-
+---------+------+-------+
145+
|---------|------|-------|
146146
| 0 | x | 42 |
147147

148148
Next up, `main()` calls `foo()`:
149149

150150
| Address | Name | Value |
151-
+---------+------+-------+
151+
|---------|------|-------|
152152
| 3 | c | 1 |
153153
| 2 | b | 100 |
154154
| 1 | a | 5 |
@@ -157,7 +157,7 @@ Next up, `main()` calls `foo()`:
157157
And then `foo()` calls `bar()`:
158158

159159
| Address | Name | Value |
160-
+---------+------+-------+
160+
|---------|------|-------|
161161
| 4 | i | 6 |
162162
| 3 | c | 1 |
163163
| 2 | b | 100 |
@@ -170,7 +170,7 @@ After `bar()` is over, its frame is deallocated, leaving just `foo()` and
170170
`main()`:
171171

172172
| Address | Name | Value |
173-
+---------+------+-------+
173+
|---------|------|-------|
174174
| 3 | c | 1 |
175175
| 2 | b | 100 |
176176
| 1 | a | 5 |
@@ -179,7 +179,7 @@ After `bar()` is over, its frame is deallocated, leaving just `foo()` and
179179
And then `foo()` ends, leaving just `main()`
180180

181181
| Address | Name | Value |
182-
+---------+------+-------+
182+
|---------|------|-------|
183183
| 0 | x | 42 |
184184

185185
And then we’re done. Getting the hang of it? It’s like piling up dishes: you
@@ -206,7 +206,7 @@ fn main() {
206206
Here’s what happens in memory when `main()` is called:
207207

208208
| Address | Name | Value |
209-
+---------+------+--------+
209+
|---------|------|--------|
210210
| 1 | y | 42 |
211211
| 0 | x | ?????? |
212212

@@ -218,7 +218,7 @@ it allocates some memory for the heap, and puts `5` there. The memory now looks
218218
like this:
219219

220220
| Address | Name | Value |
221-
+-----------------+------+----------------+
221+
|-----------------|------|----------------|
222222
| 2<sup>30</sup> | | 5 |
223223
| ... | ... | ... |
224224
| 1 | y | 42 |
@@ -243,7 +243,7 @@ layout of a program which has been running for a while now:
243243

244244

245245
| Address | Name | Value |
246-
+----------------------+------+----------------------+
246+
|----------------------|------|----------------------|
247247
| 2<sup>30</sup> | | 5 |
248248
| (2<sup>30</sup>) - 1 | | |
249249
| (2<sup>30</sup>) - 2 | | |
@@ -266,13 +266,13 @@ Rust programs use [jemalloc][jemalloc] for this purpose.
266266
Anyway, back to our example. Since this memory is on the heap, it can stay
267267
alive longer than the function which allocates the box. In this case, however,
268268
it doesn’t.[^moving] When the function is over, we need to free the stack frame
269-
for `main()`. `Box<T>`, though, has a trick up its sleve: [Drop][drop]. The
269+
for `main()`. `Box<T>`, though, has a trick up its sleeve: [Drop][drop]. The
270270
implementation of `Drop` for `Box` deallocates the memory that was allocated
271271
when it was created. Great! So when `x` goes away, it first frees the memory
272272
allocated on the heap:
273273

274274
| Address | Name | Value |
275-
+---------+------+--------+
275+
|---------|------|--------|
276276
| 1 | y | 42 |
277277
| 0 | x | ?????? |
278278

@@ -305,7 +305,7 @@ fn main() {
305305
When we enter `main()`, memory looks like this:
306306

307307
| Address | Name | Value |
308-
+---------+------+-------+
308+
|---------|------|-------|
309309
| 1 | y | 0 |
310310
| 0 | x | 5 |
311311

@@ -315,7 +315,7 @@ memory location that `x` lives at, which in this case is `0`.
315315
What about when we call `foo()`, passing `y` as an argument?
316316

317317
| Address | Name | Value |
318-
+---------+------+-------+
318+
|---------|------|-------|
319319
| 3 | z | 42 |
320320
| 2 | i | 0 |
321321
| 1 | y | 0 |
@@ -367,7 +367,7 @@ fn main() {
367367
First, we call `main()`:
368368

369369
| Address | Name | Value |
370-
+-----------------+------+----------------+
370+
|-----------------|------|----------------|
371371
| 2<sup>30</sup> | | 20 |
372372
| ... | ... | ... |
373373
| 2 | j | 0 |
@@ -380,7 +380,7 @@ value pointing there.
380380
Next, at the end of `main()`, `foo()` gets called:
381381

382382
| Address | Name | Value |
383-
+-----------------+------+----------------+
383+
|-----------------|------|----------------|
384384
| 2<sup>30</sup> | | 20 |
385385
| ... | ... | ... |
386386
| 5 | z | 4 |
@@ -397,7 +397,7 @@ since `j` points at `h`.
397397
Next, `foo()` calls `baz()`, passing `z`:
398398

399399
| Address | Name | Value |
400-
+-----------------+------+----------------+
400+
|-----------------|------|----------------|
401401
| 2<sup>30</sup> | | 20 |
402402
| ... | ... | ... |
403403
| 7 | g | 100 |
@@ -413,7 +413,7 @@ We’ve allocated memory for `f` and `g`. `baz()` is very short, so when it’s
413413
over, we get rid of its stack frame:
414414

415415
| Address | Name | Value |
416-
+-----------------+------+----------------+
416+
|-----------------|------|----------------|
417417
| 2<sup>30</sup> | | 20 |
418418
| ... | ... | ... |
419419
| 5 | z | 4 |
@@ -426,7 +426,7 @@ over, we get rid of its stack frame:
426426
Next, `foo()` calls `bar()` with `x` and `z`:
427427

428428
| Address | Name | Value |
429-
+----------------------+------+----------------------+
429+
|----------------------|------|----------------------|
430430
| 2<sup>30</sup> | | 20 |
431431
| (2<sup>30</sup>) - 1 | | 5 |
432432
| ... | ... | ... |
@@ -449,7 +449,7 @@ case, we set up the variables as usual.
449449
At the end of `bar()`, it calls `baz()`:
450450

451451
| Address | Name | Value |
452-
+----------------------+------+----------------------+
452+
|----------------------|------|----------------------|
453453
| 2<sup>30</sup> | | 20 |
454454
| (2<sup>30</sup>) - 1 | | 5 |
455455
| ... | ... | ... |
@@ -473,7 +473,7 @@ far.
473473
After `baz()` is over, we get rid of `f` and `g`:
474474

475475
| Address | Name | Value |
476-
+----------------------+------+----------------------+
476+
|----------------------|------|----------------------|
477477
| 2<sup>30</sup> | | 20 |
478478
| (2<sup>30</sup>) - 1 | | 5 |
479479
| ... | ... | ... |
@@ -493,7 +493,7 @@ Next, we return from `bar()`. `d` in this case is a `Box<T>`, so it also frees
493493
what it points to: (2<sup>30</sup>) - 1.
494494

495495
| Address | Name | Value |
496-
+-----------------+------+----------------+
496+
|-----------------|------|----------------|
497497
| 2<sup>30</sup> | | 20 |
498498
| ... | ... | ... |
499499
| 5 | z | 4 |
@@ -506,7 +506,7 @@ what it points to: (2<sup>30</sup>) - 1.
506506
And after that, `foo()` returns:
507507

508508
| Address | Name | Value |
509-
+-----------------+------+----------------+
509+
|-----------------|------|----------------|
510510
| 2<sup>30</sup> | | 20 |
511511
| ... | ... | ... |
512512
| 2 | j | 0 |

0 commit comments

Comments
 (0)