Skip to content

Commit

Permalink
Add gen blocks to ast and do some broken ast lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 27, 2023
1 parent d5bf53b commit a3be235
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down
8 changes: 4 additions & 4 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ 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 {
""
};
if let rw @ Some(_) = rewrite_single_line_block(
context,
format!("async {mover}").as_str(),
format!("{kind} {mover}").as_str(),
block,
Some(&expr.attrs),
None,
Expand All @@ -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),
Expand Down Expand Up @@ -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(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down

0 comments on commit a3be235

Please sign in to comment.