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
{{ message }}
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
Breif details about implementation:
- Instead of pre-initializing `closure_captured` and `upvars_capture_map` using `upvars_mentioned` we will be rely on use within the closure. This will be handled as part of #7
- For coercing a closure to FnPtr, instead of relying on `upvars_mentioned` in typechk we will accept such code in typechk while setting a no-capture obligation that will be validated in trait selection post capture analysis.
This document lists changes that will be made to language along with RFC-2229.
4
+
5
+
For this document let RS20 be the pre-RFC compiler and RS21 be the post-RFC compiler.
6
+
7
+
## `_` pattern in closures
8
+
9
+
Consider the following code
10
+
```rust
11
+
letx;
12
+
letc=|| {
13
+
let_=x;
14
+
};
15
+
```
16
+
17
+
RS20 will result in the capture of x within the closure, but `_` is just an ignore/discard and that means x can't/won't be used within the closure and should not result in a capture.
18
+
19
+
For RS21 we propose to ignore such captures allowing the following code to be accepted by RS21
20
+
```
21
+
let x;
22
+
let c = || {
23
+
let _ = x;
24
+
};
25
+
26
+
let f : fn() = c;
27
+
```
28
+
29
+
The above code works now because `x` isn't captured by `c` anymore making `c` a non-capturing closure, which can be coerced to a `FnPtr`
0 commit comments