Add gen blocks to ast and do some broken ast lowering

This commit is contained in:
Oli Scherer 2023-10-20 21:26:57 +00:00
parent d5bf53b454
commit a3be235fcc
3 changed files with 6 additions and 6 deletions

View File

@ -188,7 +188,7 @@ fn rewrite_closure_expr(
fn allow_multi_line(expr: &ast::Expr) -> bool { fn allow_multi_line(expr: &ast::Expr) -> bool {
match expr.kind { match expr.kind {
ast::ExprKind::Match(..) ast::ExprKind::Match(..)
| ast::ExprKind::Async(..) | ast::ExprKind::Gen(..)
| ast::ExprKind::Block(..) | ast::ExprKind::Block(..)
| ast::ExprKind::TryBlock(..) | ast::ExprKind::TryBlock(..)
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)

View File

@ -367,7 +367,7 @@ pub(crate) fn format_expr(
)) ))
} }
} }
ast::ExprKind::Async(capture_by, ref block) => { ast::ExprKind::Gen(capture_by, ref block, ref kind) => {
let mover = if capture_by == ast::CaptureBy::Value { let mover = if capture_by == ast::CaptureBy::Value {
"move " "move "
} else { } else {
@ -375,7 +375,7 @@ pub(crate) fn format_expr(
}; };
if let rw @ Some(_) = rewrite_single_line_block( if let rw @ Some(_) = rewrite_single_line_block(
context, context,
format!("async {mover}").as_str(), format!("{kind} {mover}").as_str(),
block, block,
Some(&expr.attrs), Some(&expr.attrs),
None, None,
@ -386,7 +386,7 @@ pub(crate) fn format_expr(
// 6 = `async ` // 6 = `async `
let budget = shape.width.saturating_sub(6); let budget = shape.width.saturating_sub(6);
Some(format!( Some(format!(
"async {mover}{}", "{kind} {mover}{}",
rewrite_block( rewrite_block(
block, block,
Some(&expr.attrs), Some(&expr.attrs),
@ -1371,7 +1371,7 @@ pub(crate) fn can_be_overflowed_expr(
} }
// Handle always block-like expressions // Handle always block-like expressions
ast::ExprKind::Async(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true, ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true,
// Handle `[]` and `{}`-like expressions // Handle `[]` and `{}`-like expressions
ast::ExprKind::Array(..) | ast::ExprKind::Struct(..) => { ast::ExprKind::Array(..) | ast::ExprKind::Struct(..) => {

View File

@ -473,7 +473,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::If(..) | ast::ExprKind::If(..)
| ast::ExprKind::Block(..) | ast::ExprKind::Block(..)
| ast::ExprKind::ConstBlock(..) | ast::ExprKind::ConstBlock(..)
| ast::ExprKind::Async(..) | ast::ExprKind::Gen(..)
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop(..)
| ast::ExprKind::TryBlock(..) | ast::ExprKind::TryBlock(..)