about summary refs log tree commit diff
path: root/tests/ui/async-await/task-context-arg.rs
diff options
context:
space:
mode:
authorDavid Lattimore <dvdlttmr@gmail.com>2023-03-21 21:48:03 +1100
committerDavid Lattimore <dvdlttmr@gmail.com>2023-04-11 11:07:48 +1000
commita6292676eb412d8239b308cfd1660aa75623bf5b (patch)
treeed8daa1d079b24605de44a1cd3b2c4ea7b18236d /tests/ui/async-await/task-context-arg.rs
parent7cd6f55323c15c9e8eed6361777d04e33ba7c429 (diff)
downloadrust-a6292676eb412d8239b308cfd1660aa75623bf5b.tar.gz
rust-a6292676eb412d8239b308cfd1660aa75623bf5b.zip
Preserve argument indexes when inlining MIR
We store argument indexes on VarDebugInfo. Unlike the previous method of
relying on the variable index to know whether a variable is an argument,
this survives MIR inlining.

We also no longer check if var.source_info.scope is the outermost scope.
When a function gets inlined, the arguments to the inner function will
no longer be in the outermost scope. What we care about though is
whether they were in the outermost scope prior to inlining, which we
know by whether we assigned an argument index.
Diffstat (limited to 'tests/ui/async-await/task-context-arg.rs')
-rw-r--r--tests/ui/async-await/task-context-arg.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/async-await/task-context-arg.rs b/tests/ui/async-await/task-context-arg.rs
new file mode 100644
index 00000000000..937723ca743
--- /dev/null
+++ b/tests/ui/async-await/task-context-arg.rs
@@ -0,0 +1,25 @@
+// Checks that we don't get conflicting arguments in our debug info with a particular async function
+// structure.
+
+// edition:2021
+// compile-flags: -Cdebuginfo=2
+// build-pass
+
+#![crate_type = "lib"]
+
+use std::future::Future;
+
+// The compiler produces a closure as part of this function. That closure initially takes an
+// argument _task_context. Later, when the MIR for that closure is transformed into a generator
+// state machine, _task_context is demoted to not be an argument, but just part of an unnamed
+// argument. If we emit debug info saying that both _task_context and the unnamed argument are both
+// argument number 2, then LLVM will fail with "conflicting debug info for argument". See
+// https://github.com/rust-lang/rust/pull/109466#issuecomment-1500879195 for details.
+async fn recv_unit() {
+    std::future::ready(()).await;
+}
+
+pub fn poll_recv() {
+    // This box is necessary in order to reproduce the problem.
+    let _: Box<dyn Future<Output = ()>> = Box::new(recv_unit());
+}