You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/array-expr.md
-7Lines changed: 0 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,13 +29,6 @@ When the repeat operand is a constant item, it is evaluated the length operand's
29
29
If that value is `0`, then the constant item is not evaluated at all.
30
30
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.
31
31
32
-
<divclass="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).
Copy file name to clipboardExpand all lines: src/expressions/await-expr.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,20 @@
4
4
> _AwaitExpression_ :\
5
5
> [_Expression_]`.``await`
6
6
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.
9
11
Await expressions are legal only within an [async context], like an [`async fn`] or an [`async` block].
10
12
11
13
More specifically, an await expression has the following effect.
12
14
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.
18
21
19
22
> **Edition differences**: Await expressions are only available beginning with Rust 2018.
20
23
@@ -29,7 +32,7 @@ Effectively, an await expression is roughly equivalent to the following non-norm
29
32
30
33
<!-- ignore: example expansion -->
31
34
```rust,ignore
32
-
match future_operand {
35
+
match operand.into_future() {
33
36
mut pinned => loop {
34
37
let mut pin = unsafe { Pin::new_unchecked(&mut pinned) };
35
38
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
Copy file name to clipboardExpand all lines: src/macros-by-example.md
-47Lines changed: 0 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,53 +193,6 @@ compiler knows how to expand them properly:
193
193
not have the same number. This requirement applies to every layer of nested
194
194
repetitions.
195
195
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
0 commit comments