Skip to content

Commit fc84055

Browse files
committed
style: clippy
1 parent af519b6 commit fc84055

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
@@ -618,7 +618,7 @@ impl<'ast> State<'_, 'ast> {
618618
fn print_fn_attribute(
619619
&mut self,
620620
span: Span,
621-
map: &mut HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)>,
621+
map: &mut AttributeCommentMap,
622622
print_fn: &mut dyn FnMut(&mut Self),
623623
) {
624624
match map.remove(&span.lo()) {
@@ -1179,7 +1179,7 @@ impl<'ast> State<'_, 'ast> {
11791179
ast::ExprKind::Assign(lhs, Some(bin_op), rhs)
11801180
| ast::ExprKind::Binary(lhs, bin_op, rhs) => {
11811181
let cache = self.binary_expr;
1182-
let is_chain = cache.map_or(false, |prev| prev == bin_op.kind.group());
1182+
let is_chain = cache.is_some_and(|prev| prev == bin_op.kind.group());
11831183

11841184
if !is_chain {
11851185
// start of a new operator chain --> open a box and set cache
@@ -1248,7 +1248,7 @@ impl<'ast> State<'_, 'ast> {
12481248
}
12491249
}
12501250
ast::ExprKind::Call(call_expr, call_args) => {
1251-
let callee_size = get_callee_head_size(&call_expr);
1251+
let callee_size = get_callee_head_size(call_expr);
12521252
let with_single_call_chain_child = if call_args.len() == 1
12531253
&& let Some(child) = &call_args.exprs().next()
12541254
&& is_call_chain(&child.kind, false)
@@ -1499,7 +1499,7 @@ impl<'ast> State<'_, 'ast> {
14991499
) where
15001500
F: FnOnce(&mut Self),
15011501
{
1502-
let parent_call = self.call_stack.last().cloned();
1502+
let parent_call = self.call_stack.last().copied();
15031503

15041504
// Determine the position of the formatted expression.
15051505
// When NOT in a chain, start a new one.
@@ -1823,7 +1823,7 @@ impl<'ast> State<'_, 'ast> {
18231823

18241824
// `return ' + expr + ';'
18251825
let overflows = space_left < 8 + expr_size;
1826-
let fits_alone = space_left >= expr_size + 1;
1826+
let fits_alone = space_left > expr_size;
18271827

18281828
if let Some(expr) = expr {
18291829
self.return_bin_expr = matches!(&expr.kind, ast::ExprKind::Binary(..));
@@ -2338,6 +2338,8 @@ enum AttributeKind<'ast> {
23382338
Modifier(&'ast ast::Modifier<'ast>),
23392339
}
23402340

2341+
type AttributeCommentMap = HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)>;
2342+
23412343
impl<'ast> AttributeKind<'ast> {
23422344
fn is_visibility(&self) -> bool {
23432345
matches!(self, Self::Visibility(_))
@@ -2393,17 +2395,13 @@ impl<'ast> AttributeCommentMapper<'ast> {
23932395
mut self,
23942396
state: &mut State<'_, 'ast>,
23952397
header: &'ast ast::FunctionHeader<'ast>,
2396-
) -> (
2397-
HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)>,
2398-
Vec<AttributeInfo<'ast>>,
2399-
BytePos,
2400-
) {
2398+
) -> (AttributeCommentMap, Vec<AttributeInfo<'ast>>, BytePos) {
24012399
let first_attr = self.collect_attributes(header);
24022400
self.cache_comments(state);
24032401
(self.map(), self.attributes, first_attr)
24042402
}
24052403

2406-
fn map(&mut self) -> HashMap<BytePos, (Vec<Comment>, Vec<Comment>, Vec<Comment>)> {
2404+
fn map(&mut self) -> AttributeCommentMap {
24072405
let mut map = HashMap::new();
24082406
for a in 0..self.attributes.len() {
24092407
let is_last = a == self.attributes.len() - 1;
@@ -2599,17 +2597,11 @@ fn get_chain_bottom<'a>(mut expr: &'a ast::Expr<'a>) -> &'a ast::Expr<'a> {
25992597
}
26002598

26012599
fn is_call(expr_kind: &ast::ExprKind<'_>) -> bool {
2602-
match expr_kind {
2603-
ast::ExprKind::Call(..) => true,
2604-
_ => false,
2605-
}
2600+
matches!(expr_kind, ast::ExprKind::Call(..))
26062601
}
26072602

26082603
fn is_call_or_type(expr_kind: &ast::ExprKind<'_>) -> bool {
2609-
match expr_kind {
2610-
ast::ExprKind::Call(..) | ast::ExprKind::Type(..) => true,
2611-
_ => false,
2612-
}
2604+
matches!(expr_kind, ast::ExprKind::Call(..) | ast::ExprKind::Type(..))
26132605
}
26142606

26152607
fn is_call_chain(expr_kind: &ast::ExprKind<'_>, must_have_child: bool) -> bool {
@@ -2652,25 +2644,16 @@ trait BinOpExt {
26522644
impl BinOpExt for ast::BinOpKind {
26532645
fn group(&self) -> BinOpGroup {
26542646
match self {
2655-
ast::BinOpKind::Or | ast::BinOpKind::And => BinOpGroup::Logical,
2656-
ast::BinOpKind::Eq
2657-
| ast::BinOpKind::Ne
2658-
| ast::BinOpKind::Lt
2659-
| ast::BinOpKind::Le
2660-
| ast::BinOpKind::Gt
2661-
| ast::BinOpKind::Ge => BinOpGroup::Comparison,
2662-
ast::BinOpKind::BitOr
2663-
| ast::BinOpKind::BitXor
2664-
| ast::BinOpKind::BitAnd
2665-
| ast::BinOpKind::Shl
2666-
| ast::BinOpKind::Shr
2667-
| ast::BinOpKind::Sar => BinOpGroup::Bitwise,
2668-
ast::BinOpKind::Add
2669-
| ast::BinOpKind::Sub
2670-
| ast::BinOpKind::Mul
2671-
| ast::BinOpKind::Div
2672-
| ast::BinOpKind::Rem
2673-
| ast::BinOpKind::Pow => BinOpGroup::Arithmetic,
2647+
Self::Or | Self::And => BinOpGroup::Logical,
2648+
Self::Eq | Self::Ne | Self::Lt | Self::Le | Self::Gt | Self::Ge => {
2649+
BinOpGroup::Comparison
2650+
}
2651+
Self::BitOr | Self::BitXor | Self::BitAnd | Self::Shl | Self::Shr | Self::Sar => {
2652+
BinOpGroup::Bitwise
2653+
}
2654+
Self::Add | Self::Sub | Self::Mul | Self::Div | Self::Rem | Self::Pow => {
2655+
BinOpGroup::Arithmetic
2656+
}
26742657
}
26752658
}
26762659
}

0 commit comments

Comments
 (0)