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
We are in the process of changing this (rust-lang/#69663), but it
would be good to document the existing rules before changing them.
This should also help explain the compilation errors people are
getting in the meantime.
Copy file name to clipboardExpand all lines: src/expressions/block-expr.md
+20
Original file line number
Diff line number
Diff line change
@@ -117,6 +117,24 @@ loop {
117
117
}
118
118
```
119
119
120
+
### Auto traits and `async` blocks
121
+
122
+
Auto trait inference for `async` blocks follow the same [rules as closures] except that [temporary values that are in scope][temporary-scopes] at an `await` expression are also considered. For example, consider the following block:
123
+
124
+
```rust
125
+
#fnbar() ->i32 { 42 }
126
+
#asyncfnfoo() {}
127
+
async {
128
+
matchbar() {
129
+
_=>foo().await,
130
+
}
131
+
}
132
+
#;
133
+
```
134
+
135
+
Here the result of `bar()` is in scope during the await of `foo()`, so the result of `bar()` will impact the inferred auto traits.
136
+
If `bar()` is not `Send`, then the future for the whole match block will also not be `Send`.
0 commit comments