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

Commit

Permalink
Propose language changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arora-aman authored Jul 31, 2020
1 parent 26714ac commit 7fa713b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lang-changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Language Changes

This document lists changes that will be made to language along with RFC-2229.

For this document let RS20 be the pre-RFC compiler and RS21 be the post-RFC compiler.

## `_` pattern in closures

Consider the following code
```rust
let x;
let c = || {
let _ = x;
};
```

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.

For RS21 we propose to ignore such captures allowing the following code to be accepted by RS21
```
let x;
let c = || {
let _ = x;
};
let f : fn() = c;
```

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 comments on commit 7fa713b

Please sign in to comment.