mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Correctly handle inlining of async fn
This commit is contained in:
parent
fcfc6afe05
commit
52f1ce17aa
2 changed files with 146 additions and 10 deletions
|
@ -447,6 +447,21 @@ pub fn block_expr(
|
|||
ast_from_text(&format!("fn f() {buf}"))
|
||||
}
|
||||
|
||||
pub fn async_move_block_expr(
|
||||
stmts: impl IntoIterator<Item = ast::Stmt>,
|
||||
tail_expr: Option<ast::Expr>,
|
||||
) -> ast::BlockExpr {
|
||||
let mut buf = "async move {\n".to_string();
|
||||
for stmt in stmts.into_iter() {
|
||||
format_to!(buf, " {stmt}\n");
|
||||
}
|
||||
if let Some(tail_expr) = tail_expr {
|
||||
format_to!(buf, " {tail_expr}\n");
|
||||
}
|
||||
buf += "}";
|
||||
ast_from_text(&format!("const _: () = {buf};"))
|
||||
}
|
||||
|
||||
pub fn tail_only_block_expr(tail_expr: ast::Expr) -> ast::BlockExpr {
|
||||
ast_from_text(&format!("fn f() {{ {tail_expr} }}"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue