Skip to content

Commit

Permalink
Fix: make the code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiTheShinobi committed May 24, 2024
1 parent ce7d055 commit 3097006
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::min;

use itertools::Itertools;
use rustc_ast::token::{Delimiter, Lit, LitKind};
use rustc_ast::{ast, ptr, token, ForLoopKind, HasAttrs};
use rustc_ast::{ast, ptr, token, ForLoopKind};
use rustc_span::{BytePos, Span};

use crate::chains::rewrite_chain;
Expand Down Expand Up @@ -139,14 +139,17 @@ pub(crate) fn format_expr(
| ast::ExprKind::While(..) => to_control_flow(expr, expr_type)
.and_then(|control_flow| control_flow.rewrite(context, shape)),
ast::ExprKind::ConstBlock(ref anon_const) => {
if let ast::ExprKind::Block(ref block, label) = anon_const.value.kind {
Some(format!(
"const {}",
rewrite_block(block, Some(expr.attrs()), label, context, shape)?
))
} else {
Some(format!("const {}", anon_const.rewrite(context, shape)?))
}
let rewrite = match anon_const.value.kind {
ast::ExprKind::Block(ref block, opt_label) => {
// Inner attributes are associated with the `ast::ExprKind::ConstBlock` node,
// not the `ast::Block` node we're about to rewrite. To prevent dropping inner
// attributes call `rewrite_block` directly.
// See https://github.com/rust-lang/rustfmt/issues/6158
rewrite_block(block, Some(&expr.attrs), opt_label, context, shape)?
}
_ => anon_const.rewrite(context, shape)?,
};
Some(format!("const {}", rewrite))
}
ast::ExprKind::Block(ref block, opt_label) => {
match expr_type {
Expand Down

0 comments on commit 3097006

Please sign in to comment.