Skip to content

Commit 55036b7

Browse files
committed
Merge remote-tracking branch 'upstream/rusowsky/fmt-solar' into fmt-solar-gg
2 parents ef0f664 + fc84055 commit 55036b7

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

crates/fmt/src/state/sol.rs

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl<'ast> State<'_, 'ast> {
619619
fn print_fn_attribute(
620620
&mut self,
621621
span: Span,
622-
map: &mut HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)>,
622+
map: &mut AttributeCommentMap,
623623
print_fn: &mut dyn FnMut(&mut Self),
624624
) {
625625
match map.remove(&span.lo()) {
@@ -1228,7 +1228,7 @@ impl<'ast> State<'_, 'ast> {
12281228
ast::ExprKind::Assign(lhs, Some(bin_op), rhs)
12291229
| ast::ExprKind::Binary(lhs, bin_op, rhs) => {
12301230
let cache = self.binary_expr;
1231-
let is_chain = cache.map_or(false, |prev| prev == bin_op.kind.group());
1231+
let is_chain = cache.is_some_and(|prev| prev == bin_op.kind.group());
12321232

12331233
self.print_expr_with(
12341234
|s| {
@@ -1301,7 +1301,7 @@ impl<'ast> State<'_, 'ast> {
13011301
}
13021302
}
13031303
ast::ExprKind::Call(call_expr, call_args) => {
1304-
let callee_size = get_callee_head_size(&call_expr);
1304+
let callee_size = get_callee_head_size(call_expr);
13051305
let with_single_call_chain_child = if call_args.len() == 1
13061306
&& let Some(child) = &call_args.exprs().next()
13071307
&& is_call_chain(&child.kind, false)
@@ -1559,7 +1559,7 @@ impl<'ast> State<'_, 'ast> {
15591559
) where
15601560
F: FnOnce(&mut Self),
15611561
{
1562-
let parent_call = self.call_stack.last().cloned();
1562+
let parent_call = self.call_stack.last().copied();
15631563

15641564
// Determine the position of the formatted expression.
15651565
// When NOT in a chain, start a new one.
@@ -1899,7 +1899,7 @@ impl<'ast> State<'_, 'ast> {
18991899

19001900
// `return ' + expr + ';'
19011901
let overflows = space_left < 8 + expr_size;
1902-
let fits_alone = space_left >= expr_size + 1;
1902+
let fits_alone = space_left > expr_size;
19031903

19041904
if let Some(expr) = expr {
19051905
self.return_bin_expr = matches!(&expr.kind, ast::ExprKind::Binary(..));
@@ -2421,6 +2421,8 @@ enum AttributeKind<'ast> {
24212421
Modifier(&'ast ast::Modifier<'ast>),
24222422
}
24232423

2424+
type AttributeCommentMap = HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)>;
2425+
24242426
impl<'ast> AttributeKind<'ast> {
24252427
fn is_visibility(&self) -> bool {
24262428
matches!(self, Self::Visibility(_))
@@ -2476,17 +2478,13 @@ impl<'ast> AttributeCommentMapper<'ast> {
24762478
mut self,
24772479
state: &mut State<'_, 'ast>,
24782480
header: &'ast ast::FunctionHeader<'ast>,
2479-
) -> (
2480-
HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)>,
2481-
Vec<AttributeInfo<'ast>>,
2482-
BytePos,
2483-
) {
2481+
) -> (AttributeCommentMap, Vec<AttributeInfo<'ast>>, BytePos) {
24842482
let first_attr = self.collect_attributes(header);
24852483
self.cache_comments(state);
24862484
(self.map(), self.attributes, first_attr)
24872485
}
24882486

2489-
fn map(&mut self) -> HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)> {
2487+
fn map(&mut self) -> AttributeCommentMap {
24902488
let mut map = HashMap::new();
24912489
for a in 0..self.attributes.len() {
24922490
let is_last = a == self.attributes.len() - 1;
@@ -2682,17 +2680,11 @@ fn get_chain_bottom<'a>(mut expr: &'a ast::Expr<'a>) -> &'a ast::Expr<'a> {
26822680
}
26832681

26842682
fn is_call(expr_kind: &ast::ExprKind<'_>) -> bool {
2685-
match expr_kind {
2686-
ast::ExprKind::Call(..) => true,
2687-
_ => false,
2688-
}
2683+
matches!(expr_kind, ast::ExprKind::Call(..))
26892684
}
26902685

26912686
fn is_call_or_type(expr_kind: &ast::ExprKind<'_>) -> bool {
2692-
match expr_kind {
2693-
ast::ExprKind::Call(..) | ast::ExprKind::Type(..) => true,
2694-
_ => false,
2695-
}
2687+
matches!(expr_kind, ast::ExprKind::Call(..) | ast::ExprKind::Type(..))
26962688
}
26972689

26982690
fn is_call_chain(expr_kind: &ast::ExprKind<'_>, must_have_child: bool) -> bool {
@@ -2735,25 +2727,16 @@ trait BinOpExt {
27352727
impl BinOpExt for ast::BinOpKind {
27362728
fn group(&self) -> BinOpGroup {
27372729
match self {
2738-
ast::BinOpKind::Or | ast::BinOpKind::And => BinOpGroup::Logical,
2739-
ast::BinOpKind::Eq
2740-
| ast::BinOpKind::Ne
2741-
| ast::BinOpKind::Lt
2742-
| ast::BinOpKind::Le
2743-
| ast::BinOpKind::Gt
2744-
| ast::BinOpKind::Ge => BinOpGroup::Comparison,
2745-
ast::BinOpKind::BitOr
2746-
| ast::BinOpKind::BitXor
2747-
| ast::BinOpKind::BitAnd
2748-
| ast::BinOpKind::Shl
2749-
| ast::BinOpKind::Shr
2750-
| ast::BinOpKind::Sar => BinOpGroup::Bitwise,
2751-
ast::BinOpKind::Add
2752-
| ast::BinOpKind::Sub
2753-
| ast::BinOpKind::Mul
2754-
| ast::BinOpKind::Div
2755-
| ast::BinOpKind::Rem
2756-
| ast::BinOpKind::Pow => BinOpGroup::Arithmetic,
2730+
Self::Or | Self::And => BinOpGroup::Logical,
2731+
Self::Eq | Self::Ne | Self::Lt | Self::Le | Self::Gt | Self::Ge => {
2732+
BinOpGroup::Comparison
2733+
}
2734+
Self::BitOr | Self::BitXor | Self::BitAnd | Self::Shl | Self::Shr | Self::Sar => {
2735+
BinOpGroup::Bitwise
2736+
}
2737+
Self::Add | Self::Sub | Self::Mul | Self::Div | Self::Rem | Self::Pow => {
2738+
BinOpGroup::Arithmetic
2739+
}
27572740
}
27582741
}
27592742
}

0 commit comments

Comments
 (0)