The implementation for RFC 2229 has been progressing rapidly but we've encountered some interesting complications, especially around move
closures (although the problems apply more generally).
More detailed update from the group
![feature(capture_disjoint_fields)
works for simple casesClone
there may be changes in behavior, not just failure to compilelet x = x
and why?x
) but now moves a more specific place (e.g., x.y
)x
that are no longer moved have 'significant' destructors (e.g., x.z
)
x.z
runs when x
goes out of scope, rather than when the closure is droppedlet x = x;
into the closurelet (a, b, c) = (a, b, c);
x.z
is of type String
, we would not insert let x = x;
into the closure.Observations and shortcomings:
let x = x
looks odd to be the recommended pattern, to be more specific
let _ = x
looks similar but is very different :)drop(x)
in some cases to make a more obvious desugaringw.0: !Send
but w: Send
(also for Sync
and maybe Clone
) for the migration lintCapturing subpaths can change the semantics of closure.clone()
:
struct Foo { x: *mut u32 };
let foo: Foo;
let c = move || {
// fix is to add `let foo = foo;`
let y = foo.x;
};
c.clone(); // used to run `Foo::clone()` but now it runs `<*mut u32>::Clone`
We could detect cases where clone is implemented manually.
With specialization could be true for autotraits, but we don't have that yet.
Notable bugs and limitations:
There are also some cases where the implementation is capturing more than you might think. These occur most notably around patterns, for example in cases like these:
let _ = x;
match x { _ => () }
let (_, _) = x;
match x { (_, _) => () }
We have tried to stick to the rule that "if the borrow checker considers this an access of type X, then the closure captures do too", for the most part. But right now when pattern matching against a place expression (e.g., x
in the examples above), that place is always captured at least by read. This should be fixable with more refactoring, we've deferred the work.
Current behavor:
let _ = <place>
ICEsBehavior we discussed last week:
let _ = <place>
will trigger a "fake capture" of <place>
, as will match
Ultimate behavior:
x
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing