Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit d7869cd

Browse files
authored
Propose language changes
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.
1 parent 26714ac commit d7869cd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lang-changes.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Language Changes
2+
3+
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+
let x;
12+
let c = || {
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`
30+
31+

0 commit comments

Comments
 (0)