From 8beec62315538da7449fe869fd366181f7923b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 18 Mar 2024 09:27:47 +0000 Subject: [PATCH 1/2] do not eat nested exprs result in format args visitor --- compiler/rustc_ast_lowering/src/format.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 3f84e6b100d11..d2c3b8b2d5652 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -604,8 +604,7 @@ fn may_contain_yield_point(e: &ast::Expr) -> bool { if let ast::ExprKind::Await(_, _) | ast::ExprKind::Yield(_) = e.kind { ControlFlow::Break(()) } else { - visit::walk_expr(self, e); - ControlFlow::Continue(()) + visit::walk_expr(self, e) } } From f3e9dfaed6c4d44fc0a5182221c31e5b0ff038fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 18 Mar 2024 09:33:16 +0000 Subject: [PATCH 2/2] add non-regression test for issue 122674 --- tests/ui/fmt/nested-awaits-issue-122674.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/ui/fmt/nested-awaits-issue-122674.rs diff --git a/tests/ui/fmt/nested-awaits-issue-122674.rs b/tests/ui/fmt/nested-awaits-issue-122674.rs new file mode 100644 index 0000000000000..f250933dadb48 --- /dev/null +++ b/tests/ui/fmt/nested-awaits-issue-122674.rs @@ -0,0 +1,22 @@ +// Non-regression test for issue #122674: a change in the format args visitor missed nested awaits. + +//@ edition: 2021 +//@ check-pass + +pub fn f1() -> impl std::future::Future> + Send { + async { + should_work().await?; + Ok(()) + } +} + +async fn should_work() -> Result { + let x = 1; + Err(format!("test: {}: {}", x, inner().await?)) +} + +async fn inner() -> Result { + Ok("test".to_string()) +} + +fn main() {}