Skip to content

Commit 3dcfa4a

Browse files
authored
Merge branch 'rust-lang:master' into c-unwind-documentation
2 parents bf96c20 + e647eb1 commit 3dcfa4a

File tree

12 files changed

+32
-73
lines changed

12 files changed

+32
-73
lines changed

src/attributes/type_system.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ match message {
127127
}
128128
```
129129

130+
It's also not allowed to cast non-exhaustive types from foreign crates.
131+
```rust, ignore
132+
use othercrate::NonExhaustiveEnum;
133+
134+
// Cannot cast a non-exhaustive enum outside of its defining crate.
135+
let _ = NonExhaustiveEnum::default() as u8;
136+
```
137+
130138
Non-exhaustive types are always considered inhabited in downstream crates.
131139

132140
[_MetaWord_]: ../attributes.md#meta-item-attribute-syntax

src/comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
3535
## Non-doc comments
3636

37-
Comments in Rust code follow the general C++ style of line (`//`) and
37+
Comments follow the general C++ style of line (`//`) and
3838
block (`/* ... */`) comment forms. Nested block comments are supported.
3939

4040
Non-doc comments are interpreted as a form of whitespace.

src/expressions/array-expr.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ When the repeat operand is a constant item, it is evaluated the length operand's
2929
If that value is `0`, then the constant item is not evaluated at all.
3030
For expressions that are not a constant item, it is evaluated exactly once, and then the result is copied the length operand's value times.
3131

32-
<div class="warning">
33-
34-
Warning: In the case where the length operand is 0, and the repeat operand is a non-constant item, there is currently a bug in `rustc` where the value `a` is evaluated but not dropped, thus causing a leak.
35-
See [issue #74836](https://github.com/rust-lang/rust/issues/74836).
36-
37-
</div>
38-
3932
```rust
4033
[1, 2, 3, 4];
4134
["a", "b", "c", "d"];

src/expressions/await-expr.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
> _AwaitExpression_ :\
55
> &nbsp;&nbsp; [_Expression_] `.` `await`
66
7-
*Await expressions* suspend the current computation until the given future is ready to produce a value.
8-
The syntax for an await expression is an expression with a type that implements the [Future] trait, called the *future operand*, then the token `.`, and then the `await` keyword.
7+
An `await` expression is a syntactic construct for suspending a computation
8+
provided by an implementation of `std::future::IntoFuture` until the given
9+
future is ready to produce a value.
10+
The syntax for an await expression is an expression with a type that implements the [`IntoFuture`] trait, called the *future operand*, then the token `.`, and then the `await` keyword.
911
Await expressions are legal only within an [async context], like an [`async fn`] or an [`async` block].
1012

1113
More specifically, an await expression has the following effect.
1214

13-
1. Evaluate the future operand to a [future] `tmp`;
14-
2. Pin `tmp` using [`Pin::new_unchecked`];
15-
3. This pinned future is then polled by calling the [`Future::poll`] method and passing it the current [task context](#task-context);
16-
3. If the call to `poll` returns [`Poll::Pending`], then the future returns `Poll::Pending`, suspending its state so that, when the surrounding async context is re-polled,execution returns to step 2;
17-
4. Otherwise the call to `poll` must have returned [`Poll::Ready`], in which case the value contained in the [`Poll::Ready`] variant is used as the result of the `await` expression itself.
15+
1. Create a future by calling [`IntoFuture::into_future`] on the future operand.
16+
2. Evaluate the future to a [future] `tmp`;
17+
3. Pin `tmp` using [`Pin::new_unchecked`];
18+
4. This pinned future is then polled by calling the [`Future::poll`] method and passing it the current [task context](#task-context);
19+
5. If the call to `poll` returns [`Poll::Pending`], then the future returns `Poll::Pending`, suspending its state so that, when the surrounding async context is re-polled,execution returns to step 3;
20+
6. Otherwise the call to `poll` must have returned [`Poll::Ready`], in which case the value contained in the [`Poll::Ready`] variant is used as the result of the `await` expression itself.
1821

1922
> **Edition differences**: Await expressions are only available beginning with Rust 2018.
2023
@@ -29,7 +32,7 @@ Effectively, an await expression is roughly equivalent to the following non-norm
2932

3033
<!-- ignore: example expansion -->
3134
```rust,ignore
32-
match future_operand {
35+
match operand.into_future() {
3336
mut pinned => loop {
3437
let mut pin = unsafe { Pin::new_unchecked(&mut pinned) };
3538
match Pin::future::poll(Pin::borrow(&mut pin), &mut current_context) {
@@ -53,3 +56,5 @@ The variable `current_context` refers to the context taken from the async enviro
5356
[`poll::Ready`]: ../../std/task/enum.Poll.html#variant.Ready
5457
[async context]: ../expressions/block-expr.md#async-context
5558
[future]: ../../std/future/trait.Future.html
59+
[`IntoFuture`]: ../../std/future/trait.IntoFuture.html
60+
[`IntoFuture::into_future`]: ../../std/future/trait.IntoFuture.html#tymethod.into_future

src/interior-mutability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mutability if its internal state can be changed through a [shared reference] to
66
it. This goes against the usual [requirement][ub] that the value pointed to by a
77
shared reference is not mutated.
88

9-
[`std::cell::UnsafeCell<T>`] type is the only allowed way in Rust to disable
9+
[`std::cell::UnsafeCell<T>`] type is the only allowed way to disable
1010
this requirement. When `UnsafeCell<T>` is immutably aliased, it is still safe to
1111
mutate, or obtain a mutable reference to, the `T` it contains. As with all
1212
other types, it is undefined behavior to have multiple `&mut UnsafeCell<T>`

src/items/external-blocks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ block.
167167
This modifier is only compatible with the `static` linking kind.
168168
Using any other kind will result in a compiler error.
169169

170-
When building a rlib or staticlib `+bundle` means that all object files from the native static
171-
library will be added to the rlib or staticlib archive, and then used from it during linking of
172-
the final binary.
170+
When building a rlib or staticlib `+bundle` means that the native static library
171+
will be packed into the rlib or staticlib archive, and then retrieved from there
172+
during linking of the final binary.
173173

174174
When building a rlib `-bundle` means that the native static library is registered as a dependency
175175
of that rlib "by name", and object files from it are included only during linking of the final

src/items/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ is equivalent to:
175175
extern "Rust" fn foo() {}
176176
```
177177

178-
Functions in Rust can be called by foreign code, and using an ABI that
178+
Functions can be called by foreign code, and using an ABI that
179179
differs from Rust allows, for example, to provide functions that can be
180180
called from other programming languages like C:
181181

src/macros-by-example.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -193,53 +193,6 @@ compiler knows how to expand them properly:
193193
not have the same number. This requirement applies to every layer of nested
194194
repetitions.
195195

196-
## Dollar-dollar ($$)
197-
198-
`$$` expands to a single `$`.
199-
200-
Since metavariable expressions always apply during the expansion of a macro, they cannot be used in recursive macro definitions and this is where `$$` expressions comes into play, i.e., `$$` can be used to resolve ambiguities in nested macros.
201-
202-
The following example illustrates a macro that fails to compile due to the ambiguity of the repetition in a nested macro:
203-
204-
```rust,compile_fail
205-
macro_rules! foo_error {
206-
() => {
207-
macro_rules! bar_error {
208-
( $( $any:tt )* ) => { $( $any )* };
209-
// ^^^^^^^^^^^ error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
210-
}
211-
};
212-
}
213-
214-
foo_error!();
215-
```
216-
217-
The following resolves the problem by escaping the `$` in the repetition with `$$`:
218-
219-
```rust
220-
macro_rules! foo_ok {
221-
() => {
222-
macro_rules! bar_ok {
223-
( $$( $any:tt )* ) => { $$( $any )* };
224-
}
225-
};
226-
}
227-
228-
foo_ok!();
229-
```
230-
231-
One consequence of such expansion is that deeper nested levels make dollar-dollar declarations grown linearly, starting at `$$`, then `$$$$`, then `$$$$$` and so on. This is also necessary to be fully featured so that it is possible to specify names of metavariables using other metavariables at each nesting level.
232-
233-
```ignore
234-
$foo => bar => bar // Evaluate foo at level 1
235-
$$foo => $foo => bar // Evaluate foo at level 2
236-
$$$foo => $bar => baz // Evaluate foo at level 1, and use that as a name at level 2
237-
$$$$foo => $$foo => $foo // Evaluate foo at level 3
238-
$$$$$foo => $$bar => $bar // Evaluate foo at level 1, and use that as a name at level 3
239-
$$$$$$foo => $$$foo => $bar // Evaluate foo at level 2, and use that as a name at level 3
240-
$$$$$$$foo => $$$bar => $baz // Evaluate foo at level 1, use that at level 2, and then use *that* at level 3
241-
```
242-
243196
## Scoping, Exporting, and Importing
244197

245198
For historical reasons, the scoping of macros by example does not work entirely

src/statements-and-expressions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ each other kind of expression, and rules for evaluation of expressions involve
77
specifying both the value produced by the expression and the order in which its
88
sub-expressions are themselves evaluated.
99

10-
In contrast, statements in Rust serve _mostly_ to contain and explicitly
10+
In contrast, statements serve _mostly_ to contain and explicitly
1111
sequence expression evaluation.

src/subtyping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Subtyping and Variance
22

33
Subtyping is implicit and can occur at any stage in type checking or
4-
inference. Subtyping in Rust is very restricted and occurs only due to
4+
inference. Subtyping is restricted to two cases:
55
variance with respect to lifetimes and between types with higher ranked
66
lifetimes. If we were to erase lifetimes from types, then the only subtyping
77
would be due to type equality.

0 commit comments

Comments
 (0)