diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 122429276e3c..a2df3dcb85ac 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -41,6 +41,11 @@ fn is_enabled(&self, sess: &rustc_session::Session) -> bool { #[instrument(skip_all level = "debug")] fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + // Avoid query cycles from coroutines. + if body.coroutine.is_some() { + return; + } + debug!(def_id = ?body.source.def_id()); if tcx.sess.mir_opt_level() < 4 && body.basic_blocks.len() > BLOCK_LIMIT { debug!("aborted dataflow const prop due too many basic blocks"); diff --git a/tests/ui/dataflow_const_prop/recursive-async.rs b/tests/ui/dataflow_const_prop/recursive-async.rs new file mode 100644 index 000000000000..f2c194c6ca3f --- /dev/null +++ b/tests/ui/dataflow_const_prop/recursive-async.rs @@ -0,0 +1,11 @@ +//! Ensure DataflowConstProp doesn't cause an error with async recursion as in #155376. + +//@ edition:2018 +//@ check-pass +//@ compile-flags: -Zmir-opt-level=0 -Zmir-enable-passes=+DataflowConstProp --crate-type=lib + +pub async fn foo(n: usize) { + if n > 0 { + Box::pin(foo(n - 1)).await; + } +}