From b05d5db87bd9a3f31729a5c48dc5dd5bec6dbd2d Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 1 May 2019 13:35:34 +0100 Subject: Ensure that drop order of `async fn` matches `fn`. This commit modifies the lowering of `async fn` arguments so that the drop order matches the equivalent `fn`. Previously, async function arguments were lowered as shown below: async fn foo(: ) { async move { } } // <-- dropped as you "exit" the fn // ...becomes... fn foo(__arg0: ) { async move { let = __arg0; } // <-- dropped as you "exit" the async block } After this PR, async function arguments will be lowered as: async fn foo(: , : , : ) { async move { } } // <-- dropped as you "exit" the fn // ...becomes... fn foo(__arg0: , __arg1: , __arg2: ) { async move { let __arg2 = __arg2; let = __arg2; let __arg1 = __arg1; let = __arg1; let __arg0 = __arg0; let = __arg0; } // <-- dropped as you "exit" the async block } If `` is a simple ident, then it is lowered to a single `let = ;` statement as an optimization. --- src/libsyntax/ext/placeholders.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 68cd3c28676..f5e18e98436 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -199,7 +199,10 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> { if let ast::IsAsync::Async { ref mut arguments, .. } = a { for argument in arguments.iter_mut() { - self.next_id(&mut argument.stmt.id); + self.next_id(&mut argument.move_stmt.id); + if let Some(ref mut pat_stmt) = &mut argument.pat_stmt { + self.next_id(&mut pat_stmt.id); + } } } } -- cgit 1.4.1-3-g733a5