From a3be235fccea89aed17043c917c7fb52c4a57894 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 20 Oct 2023 21:26:57 +0000 Subject: [PATCH] Add gen blocks to ast and do some broken ast lowering --- src/closures.rs | 2 +- src/expr.rs | 8 ++++---- src/utils.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/closures.rs b/src/closures.rs index a09146e95924..16b8ce7a916a 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -188,7 +188,7 @@ fn rewrite_closure_expr( fn allow_multi_line(expr: &ast::Expr) -> bool { match expr.kind { ast::ExprKind::Match(..) - | ast::ExprKind::Async(..) + | ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::TryBlock(..) | ast::ExprKind::Loop(..) diff --git a/src/expr.rs b/src/expr.rs index acde88093296..8c2262fde811 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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 { "move " } else { @@ -375,7 +375,7 @@ pub(crate) fn format_expr( }; if let rw @ Some(_) = rewrite_single_line_block( context, - format!("async {mover}").as_str(), + format!("{kind} {mover}").as_str(), block, Some(&expr.attrs), None, @@ -386,7 +386,7 @@ pub(crate) fn format_expr( // 6 = `async ` let budget = shape.width.saturating_sub(6); Some(format!( - "async {mover}{}", + "{kind} {mover}{}", rewrite_block( block, Some(&expr.attrs), @@ -1371,7 +1371,7 @@ pub(crate) fn can_be_overflowed_expr( } // 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 ast::ExprKind::Array(..) | ast::ExprKind::Struct(..) => { diff --git a/src/utils.rs b/src/utils.rs index 79a759d68ce8..fd49030bf1b4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -473,7 +473,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::If(..) | ast::ExprKind::Block(..) | ast::ExprKind::ConstBlock(..) - | ast::ExprKind::Async(..) + | ast::ExprKind::Gen(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop(..) | ast::ExprKind::TryBlock(..)