Repository navigation
Reform feature(ergonomic_clones) - #165111
Jules-Bertholet wants to merge 4 commits into
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease
cc @rust-lang/miri
cc @rust-lang/rust-analyzer
cc @rust-lang/clippy
cc @rust-lang/rustfmt |
|
r? @beetrees rustbot has assigned @beetrees. Use Why was this reviewer chosen?The reviewer was selected based on:
|
4ed2142 to
87e4868
Compare
I continue to think that this is inconsistent with the rest of the language and should not be done just one feature at a time. If we are okay with turning unwinds into aborts, we should systematically think about where that should be done. But there's a notable portion of Rust users that really strongly opposes this so it needs wider discussion. |
|
This is not a final proposal, I'm open to changing my mind on everything including the abort-on-panic part. That being said, I think the "inconsistency" with e.g. drop actually makes sense. Drop can flush I/O, close network connections, and do all sorts of complicated stuff that risks a panic. |
Right. So usually this would be then a discussion between you and the t-lang champion for this feature. Given that Niko stepped back as a champion, I guess the next step would be to find a new champion, if there's still interest in the lang team for this feature. |
87e4868 to
f645fc9
Compare
f645fc9 to
738afbd
Compare
Tracking issue: #132290
It seems like the mood in the lang team is that they are no longer motivated to champion this feature in its current form: #165060 (comment)
I still like it, though. I believe that, with some tweaks, it can serve as a useful complement to
moveexpressions. This PR is my proposal to the lang team to pick this feature up and reform it for continued experimentation.Changes in this PR
use ||closures andasync use {}blocks are no longer a thing..useaborts on panic, instead of triggering UB.$expr.userequires$expr's type to implementCopyorUseCloned..usein a normal, non-moveclosure now has special capturing behavior. To elaborate:Within a closure,
.useon a captured place results in a special by-use capture mode. Captures with this mode are cloned both when the closure is created, as well as every time the closure is run. In other words,|| x.useis essentially equivalent to|| move(x.clone()).clone(). This allows the closure to implementFn()without borrowing from the stack frame of its parent.The clone on closure construction happens only once, even if the capture is
.used several times within the closure body. For example,|| { x.use; x.use }clones only once on construction, and twice each time the closure is run. (The naïve desugaring in terms ofmoveexpressions would clone twice on construction.)The by-use capture mode is considered to have the lowest priority among all other capture modes. For example, the following closures do not clone on construction:
|| { x.use; x },|| { x.use; &x }.By-use capturing also supports edition 2021 precise capturing. For example:
Fixes #141916, fixes #141952, fixes #164902,
@rustbot label F-ergonomic_clones A-closures A-panic T-lang I-lang-nominated