Skip to content

Commit 8401bee

Browse files
committed
---
yaml --- r: 223214 b: refs/heads/auto c: 11deb08 h: refs/heads/master v: v3
1 parent e1636dc commit 8401bee

File tree

213 files changed

+1596
-1093
lines changed

Some content is hidden

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

213 files changed

+1596
-1093
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 83e43bb728b95d52039824d63b1ba5bbde5c5d7b
11+
refs/heads/auto: 11deb083f5bc3e57e73fc82de4bef7b1d4dad7b1
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/mk/main.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
######################################################################
1414

1515
# The version number
16-
CFG_RELEASE_NUM=1.3.0
16+
CFG_RELEASE_NUM=1.4.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

branches/auto/src/doc/nomicon/atomics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fundamentally unsynchronized and compilers are free to aggressively optimize
127127
them. In particular, data accesses are free to be reordered by the compiler on
128128
the assumption that the program is single-threaded. The hardware is also free to
129129
propagate the changes made in data accesses to other threads as lazily and
130-
inconsistently as it wants. Mostly critically, data accesses are how data races
130+
inconsistently as it wants. Most critically, data accesses are how data races
131131
happen. Data accesses are very friendly to the hardware and compiler, but as
132132
we've seen they offer *awful* semantics to try to write synchronized code with.
133133
Actually, that's too weak.

branches/auto/src/doc/nomicon/concurrency.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ an abstraction over them in a relatively uncontroversial way. Message passing,
77
green threads, and async APIs are all diverse enough that any abstraction over
88
them tends to involve trade-offs that we weren't willing to commit to for 1.0.
99

10-
However the way Rust models concurrency makes it relatively easy design your own
10+
However the way Rust models concurrency makes it relatively easy to design your own
1111
concurrency paradigm as a library and have everyone else's code Just Work
1212
with yours. Just require the right lifetimes and Send and Sync where appropriate
1313
and you're off to the races. Or rather, off to the... not... having... races.

branches/auto/src/doc/nomicon/destructors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ enum Link {
120120
will have its inner Box field dropped if and only if an instance stores the
121121
Next variant.
122122

123-
In general this works really nice because you don't need to worry about
123+
In general this works really nicely because you don't need to worry about
124124
adding/removing drops when you refactor your data layout. Still there's
125125
certainly many valid usecases for needing to do trickier things with
126126
destructors.

branches/auto/src/doc/nomicon/drop-flags.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Drop Flags
22

33
The examples in the previous section introduce an interesting problem for Rust.
4-
We have seen that's possible to conditionally initialize, deinitialize, and
4+
We have seen that it's possible to conditionally initialize, deinitialize, and
55
reinitialize locations of memory totally safely. For Copy types, this isn't
66
particularly notable since they're just a random pile of bits. However types
77
with destructors are a different story: Rust needs to know whether to call a

branches/auto/src/doc/nomicon/dropck.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Drop Check
22

33
We have seen how lifetimes provide us some fairly simple rules for ensuring
4-
that never read dangling references. However up to this point we have only ever
4+
that we never read dangling references. However up to this point we have only ever
55
interacted with the *outlives* relationship in an inclusive manner. That is,
66
when we talked about `'a: 'b`, it was ok for `'a` to live *exactly* as long as
77
`'b`. At first glance, this seems to be a meaningless distinction. Nothing ever

branches/auto/src/doc/nomicon/exotic-sizes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ support values.
8585
Safe code need not worry about ZSTs, but *unsafe* code must be careful about the
8686
consequence of types with no size. In particular, pointer offsets are no-ops,
8787
and standard allocators (including jemalloc, the one used by default in Rust)
88-
generally consider passing in `0` for the size of an allocation as Undefined
89-
Behaviour.
88+
may return `nullptr` when a zero-sized allocation is requested, which is
89+
indistinguishable from out of memory.
9090

9191

9292

branches/auto/src/doc/nomicon/repr-rust.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ struct A {
3636
}
3737
```
3838

39-
will be 32-bit aligned assuming these primitives are aligned to their size.
40-
It will therefore have a size that is a multiple of 32-bits. It will potentially
41-
*really* become:
39+
will be 32-bit aligned on an architecture that aligns these primitives to their
40+
respective sizes. The whole struct will therefore have a size that is a multiple
41+
of 32-bits. It will potentially become:
4242

4343
```rust
4444
struct A {
@@ -50,10 +50,10 @@ struct A {
5050
}
5151
```
5252

53-
There is *no indirection* for these types; all data is stored contiguously as
54-
you would expect in C. However with the exception of arrays (which are densely
55-
packed and in-order), the layout of data is not by default specified in Rust.
56-
Given the two following struct definitions:
53+
There is *no indirection* for these types; all data is stored within the struct,
54+
as you would expect in C. However with the exception of arrays (which are
55+
densely packed and in-order), the layout of data is not by default specified in
56+
Rust. Given the two following struct definitions:
5757

5858
```rust
5959
struct A {
@@ -62,18 +62,17 @@ struct A {
6262
}
6363

6464
struct B {
65-
x: i32,
65+
a: i32,
6666
b: u64,
6767
}
6868
```
6969

7070
Rust *does* guarantee that two instances of A have their data laid out in
71-
exactly the same way. However Rust *does not* guarantee that an instance of A
72-
has the same field ordering or padding as an instance of B (in practice there's
73-
no particular reason why they wouldn't, other than that its not currently
74-
guaranteed).
71+
exactly the same way. However Rust *does not* currently guarantee that an
72+
instance of A has the same field ordering or padding as an instance of B, though
73+
in practice there's no reason why they wouldn't.
7574

76-
With A and B as written, this is basically nonsensical, but several other
75+
With A and B as written, this point would seem to be pedantic, but several other
7776
features of Rust make it desirable for the language to play with data layout in
7877
complex ways.
7978

@@ -133,18 +132,21 @@ struct FooRepr {
133132
}
134133
```
135134

136-
And indeed this is approximately how it would be laid out in general
137-
(modulo the size and position of `tag`). However there are several cases where
138-
such a representation is inefficient. The classic case of this is Rust's
139-
"null pointer optimization". Given a pointer that is known to not be null
140-
(e.g. `&u32`), an enum can *store* a discriminant bit *inside* the pointer
141-
by using null as a special value. The net result is that
142-
`size_of::<Option<&T>>() == size_of::<&T>()`
135+
And indeed this is approximately how it would be laid out in general (modulo the
136+
size and position of `tag`).
137+
138+
However there are several cases where such a representation is inefficient. The
139+
classic case of this is Rust's "null pointer optimization": an enum consisting
140+
of a single outer unit variant (e.g. `None`) and a (potentially nested) non-
141+
nullable pointer variant (e.g. `&T`) makes the tag unnecessary, because a null
142+
pointer value can safely be interpreted to mean that the unit variant is chosen
143+
instead. The net result is that, for example, `size_of::<Option<&T>>() ==
144+
size_of::<&T>()`.
143145

144-
There are many types in Rust that are, or contain, "not null" pointers such as
146+
There are many types in Rust that are, or contain, non-nullable pointers such as
145147
`Box<T>`, `Vec<T>`, `String`, `&T`, and `&mut T`. Similarly, one can imagine
146148
nested enums pooling their tags into a single discriminant, as they are by
147-
definition known to have a limited range of valid values. In principle enums can
149+
definition known to have a limited range of valid values. In principle enums could
148150
use fairly elaborate algorithms to cache bits throughout nested types with
149151
special constrained representations. As such it is *especially* desirable that
150152
we leave enum layout unspecified today.

branches/auto/src/doc/nomicon/send-and-sync.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
Not everything obeys inherited mutability, though. Some types allow you to
44
multiply alias a location in memory while mutating it. Unless these types use
55
synchronization to manage this access, they are absolutely not thread safe. Rust
6-
captures this with through the `Send` and `Sync` traits.
6+
captures this through the `Send` and `Sync` traits.
77

88
* A type is Send if it is safe to send it to another thread.
99
* A type is Sync if it is safe to share between threads (`&T` is Send).
1010

1111
Send and Sync are fundamental to Rust's concurrency story. As such, a
1212
substantial amount of special tooling exists to make them work right. First and
1313
foremost, they're [unsafe traits][]. This means that they are unsafe to
14-
implement, and other unsafe code can that they are correctly
14+
implement, and other unsafe code can assume that they are correctly
1515
implemented. Since they're *marker traits* (they have no associated items like
1616
methods), correctly implemented simply means that they have the intrinsic
1717
properties an implementor should have. Incorrectly implementing Send or Sync can

branches/auto/src/doc/nomicon/subtyping.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ fn main() {
9393

9494
The signature of `overwrite` is clearly valid: it takes mutable references to
9595
two values of the same type, and overwrites one with the other. If `&mut T` was
96-
variant over T, then `&mut &'a str` would be a subtype of `&mut &'static str`,
97-
since `&'a str` is a subtype of `&'static str`. Therefore the lifetime of
96+
variant over T, then `&mut &'static str` would be a subtype of `&mut &'a str`,
97+
since `&'static str` is a subtype of `&'a str`. Therefore the lifetime of
9898
`forever_str` would successfully be "shrunk" down to the shorter lifetime of
9999
`string`, and `overwrite` would be called successfully. `string` would
100100
subsequently be dropped, and `forever_str` would point to freed memory when we

branches/auto/src/doc/nomicon/unchecked-uninit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ contain any `Drop` types.
7777
However when working with uninitialized memory you need to be ever-vigilant for
7878
Rust trying to drop values you make like this before they're fully initialized.
7979
Every control path through that variable's scope must initialize the value
80-
before it ends, if has a destructor.
80+
before it ends, if it has a destructor.
8181
*[This includes code panicking](unwinding.html)*.
8282

8383
And that's about it for working with uninitialized memory! Basically nothing

branches/auto/src/doc/reference.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,9 @@ balanced, but they are otherwise not special.
538538
In the matcher, `$` _name_ `:` _designator_ matches the nonterminal in the Rust
539539
syntax named by _designator_. Valid designators are `item`, `block`, `stmt`,
540540
`pat`, `expr`, `ty` (type), `ident`, `path`, `tt` (either side of the `=>`
541-
in macro rules). In the transcriber, the designator is already known, and so
542-
only the name of a matched nonterminal comes after the dollar sign.
541+
in macro rules), and `meta` (contents of an attribute). In the transcriber, the
542+
designator is already known, and so only the name of a matched nonterminal comes
543+
after the dollar sign.
543544

544545
In both the matcher and transcriber, the Kleene star-like operator indicates
545546
repetition. The Kleene star operator consists of `$` and parentheses, optionally
@@ -1500,7 +1501,29 @@ have an implementation for `Shape`. Multiple supertraits are separated by `+`,
15001501
`trait Circle : Shape + PartialEq { }`. In an implementation of `Circle` for a
15011502
given type `T`, methods can refer to `Shape` methods, since the typechecker
15021503
checks that any type with an implementation of `Circle` also has an
1503-
implementation of `Shape`.
1504+
implementation of `Shape`:
1505+
1506+
```rust
1507+
struct Foo;
1508+
1509+
trait Shape { fn area(&self) -> f64; }
1510+
trait Circle : Shape { fn radius(&self) -> f64; }
1511+
# impl Shape for Foo {
1512+
# fn area(&self) -> f64 {
1513+
# 0.0
1514+
# }
1515+
# }
1516+
impl Circle for Foo {
1517+
fn radius(&self) -> f64 {
1518+
println!("calling area: {}", self.area());
1519+
1520+
0.0
1521+
}
1522+
}
1523+
1524+
let c = Foo;
1525+
c.radius();
1526+
```
15041527

15051528
In type-parameterized functions, methods of the supertrait may be called on
15061529
values of subtrait-bound type parameters. Referring to the previous example of

branches/auto/src/doc/trpl/closures.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,35 @@ assert_eq!(3, answer);
316316
Now we take a trait object, a `&Fn`. And we have to make a reference
317317
to our closure when we pass it to `call_with_one`, so we use `&||`.
318318

319+
# Function pointers and closures
320+
321+
A function pointer is kind of like a closure that has no environment. As such,
322+
you can pass a function pointer to any function expecting a closure argument,
323+
and it will work:
324+
325+
```rust
326+
fn call_with_one(some_closure: &Fn(i32) -> i32) -> i32 {
327+
some_closure(1)
328+
}
329+
330+
fn add_one(i: i32) -> i32 {
331+
i + 1
332+
}
333+
334+
let f = add_one;
335+
336+
let answer = call_with_one(&f);
337+
338+
assert_eq!(2, answer);
339+
```
340+
341+
In this example, we don’t strictly need the intermediate variable `f`,
342+
the name of the function works just fine too:
343+
344+
```ignore
345+
let answer = call_with_one(&add_one);
346+
```
347+
319348
# Returning closures
320349

321350
It’s very common for functional-style code to return closures in various

0 commit comments

Comments
 (0)