Skip to content

Commit

Permalink
Rollup merge of rust-lang#122680 - lqd:nested-await-args, r=compiler-…
Browse files Browse the repository at this point in the history
…errors

Do not eat nested expressions' results in `MayContainYieldPoint` format args visitor

rust-lang#121563 unintentionally changed the `MayContainYieldPoint` format args visitor behavior, now missing yield points in nested expressions, as seen in rust-lang#122674.

The walk can find a yield point in an expression but it was ignored.

r? ``@petrochenkov`` as the reviewer of rust-lang#121563
cc ``@Jarcho`` as the author

Fixes rust-lang#122674.
We're in the 1.77 release week. rust-lang#121563 will land on 1.78 but beta is still 1.77.9: this PR will likely need to be backported soon after beta is cut.
  • Loading branch information
matthiaskrgr committed Mar 18, 2024
2 parents 1ac0239 + f3e9dfa commit 72e2c7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
22 changes: 22 additions & 0 deletions tests/ui/fmt/nested-awaits-issue-122674.rs
Original file line number Diff line number Diff line change
@@ -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<Output = Result<(), String>> + Send {
async {
should_work().await?;
Ok(())
}
}

async fn should_work() -> Result<String, String> {
let x = 1;
Err(format!("test: {}: {}", x, inner().await?))
}

async fn inner() -> Result<String, String> {
Ok("test".to_string())
}

fn main() {}

0 comments on commit 72e2c7c

Please sign in to comment.