Introduce move expressions (move($expr)) #155023
Introduce move expressions (move($expr)) #155023TaKO8Ki wants to merge 17 commits intorust-lang:mainfrom
move($expr)) #155023Conversation
move($expr)) move($expr))
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| allow_async_fn_traits: Arc<[Symbol]>, | ||
|
|
||
| delayed_lints: Vec<DelayedLint>, | ||
| move_expr_bindings: Vec<NodeMap<(Ident, HirId)>>, |
There was a problem hiding this comment.
under my proposed change, this would be Vec<Option<NodeMap<_>>>
This comment has been minimized.
This comment has been minimized.
replace TODO with FIXME
document move expression lowering flow
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
| fn_decl_span: Span, | ||
| fn_arg_span: Span, | ||
| whole_span: Span, | ||
| ) -> hir::Expr<'hir> { |
There was a problem hiding this comment.
Would still like a comment :)
| self.expr(whole_span, hir::ExprKind::Block(block, None)) | ||
| } | ||
|
|
||
| fn lower_expr_closure( |
There was a problem hiding this comment.
all of these methods with very similar names (lower_expr_closure_expr, lower_expr_closure, etc) could use with some comments showing how they relate to one another
| allow_async_fn_traits: Arc<[Symbol]>, | ||
|
|
||
| delayed_lints: Vec<DelayedLint>, | ||
| /// Stack of `move(...)` collection states. A plain closure body pushes |
There was a problem hiding this comment.
| /// Stack of `move(...)` collection states. A plain closure body pushes | |
| /// Stack of `move(...)` collection states. A plain closure body pushes |
| assert_eq!(x, "hello"); | ||
| }; | ||
|
|
||
| outer(); |
There was a problem hiding this comment.
| outer(); | |
| // `outer` captures `x` by *reference* (and `inner` takes ownership of a clone) | |
| println!("{x"); | |
| outer(); |
I expect that this will wind up with outer capturing x by ref, right? let's add something to demonstrate this by having println!("{x}");
There was a problem hiding this comment.
I would also want a compile-fail test like
let mut x = String::from("hello");
let outer = || {
let inner = || move(x.clone());
let y = inner();
assert_eq!(y, "hello");
assert_eq!(x, "hello");
};
x.push("more test"); //~ ERROR
outer();| #![feature(move_expr)] | ||
|
|
||
| fn main() { | ||
| let x = String::from("hello"); |
There was a problem hiding this comment.
| let x = String::from("hello"); | |
| let x = Arc::new(String::from("hello")); |
There was a problem hiding this comment.
we could try printing the ref count here and there to check?
| c(); | ||
|
|
||
| let v = "Hello, Ferris".to_string(); | ||
| let r = || { |
There was a problem hiding this comment.
I think this could be its own file
|
|
||
| fn main() { | ||
| let s = vec![1, 2, 3]; | ||
| let c = || { |
There was a problem hiding this comment.
let's add coroutine tests (which will error for now), unless they already exist.
View all comments
This is an experimental first version of move expressions.
This first version implements it just in plain closures. A support for coroutine closures will be added in follow up pull requests.
RFC: will be added later
Tracking issue: #155050
Project goal:
r? @nikomatsakis