@@ -618,7 +618,7 @@ impl<'ast> State<'_, 'ast> {
618
618
fn print_fn_attribute (
619
619
& mut self ,
620
620
span : Span ,
621
- map : & mut HashMap < BytePos , ( Vec < Comment > , Vec < Comment > , Vec < Comment > ) > ,
621
+ map : & mut AttributeCommentMap ,
622
622
print_fn : & mut dyn FnMut ( & mut Self ) ,
623
623
) {
624
624
match map. remove ( & span. lo ( ) ) {
@@ -1179,7 +1179,7 @@ impl<'ast> State<'_, 'ast> {
1179
1179
ast:: ExprKind :: Assign ( lhs, Some ( bin_op) , rhs)
1180
1180
| ast:: ExprKind :: Binary ( lhs, bin_op, rhs) => {
1181
1181
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 ( ) ) ;
1183
1183
1184
1184
if !is_chain {
1185
1185
// start of a new operator chain --> open a box and set cache
@@ -1248,7 +1248,7 @@ impl<'ast> State<'_, 'ast> {
1248
1248
}
1249
1249
}
1250
1250
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) ;
1252
1252
let with_single_call_chain_child = if call_args. len ( ) == 1
1253
1253
&& let Some ( child) = & call_args. exprs ( ) . next ( )
1254
1254
&& is_call_chain ( & child. kind , false )
@@ -1499,7 +1499,7 @@ impl<'ast> State<'_, 'ast> {
1499
1499
) where
1500
1500
F : FnOnce ( & mut Self ) ,
1501
1501
{
1502
- let parent_call = self . call_stack . last ( ) . cloned ( ) ;
1502
+ let parent_call = self . call_stack . last ( ) . copied ( ) ;
1503
1503
1504
1504
// Determine the position of the formatted expression.
1505
1505
// When NOT in a chain, start a new one.
@@ -1823,7 +1823,7 @@ impl<'ast> State<'_, 'ast> {
1823
1823
1824
1824
// `return ' + expr + ';'
1825
1825
let overflows = space_left < 8 + expr_size;
1826
- let fits_alone = space_left >= expr_size + 1 ;
1826
+ let fits_alone = space_left > expr_size;
1827
1827
1828
1828
if let Some ( expr) = expr {
1829
1829
self . return_bin_expr = matches ! ( & expr. kind, ast:: ExprKind :: Binary ( ..) ) ;
@@ -2338,6 +2338,8 @@ enum AttributeKind<'ast> {
2338
2338
Modifier ( & ' ast ast:: Modifier < ' ast > ) ,
2339
2339
}
2340
2340
2341
+ type AttributeCommentMap = HashMap < BytePos , ( Vec < Comment > , Vec < Comment > , Vec < Comment > ) > ;
2342
+
2341
2343
impl < ' ast > AttributeKind < ' ast > {
2342
2344
fn is_visibility ( & self ) -> bool {
2343
2345
matches ! ( self , Self :: Visibility ( _) )
@@ -2393,17 +2395,13 @@ impl<'ast> AttributeCommentMapper<'ast> {
2393
2395
mut self ,
2394
2396
state : & mut State < ' _ , ' ast > ,
2395
2397
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 ) {
2401
2399
let first_attr = self . collect_attributes ( header) ;
2402
2400
self . cache_comments ( state) ;
2403
2401
( self . map ( ) , self . attributes , first_attr)
2404
2402
}
2405
2403
2406
- fn map ( & mut self ) -> HashMap < BytePos , ( Vec < Comment > , Vec < Comment > , Vec < Comment > ) > {
2404
+ fn map ( & mut self ) -> AttributeCommentMap {
2407
2405
let mut map = HashMap :: new ( ) ;
2408
2406
for a in 0 ..self . attributes . len ( ) {
2409
2407
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> {
2599
2597
}
2600
2598
2601
2599
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 ( ..) )
2606
2601
}
2607
2602
2608
2603
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 ( ..) )
2613
2605
}
2614
2606
2615
2607
fn is_call_chain ( expr_kind : & ast:: ExprKind < ' _ > , must_have_child : bool ) -> bool {
@@ -2652,25 +2644,16 @@ trait BinOpExt {
2652
2644
impl BinOpExt for ast:: BinOpKind {
2653
2645
fn group ( & self ) -> BinOpGroup {
2654
2646
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
+ }
2674
2657
}
2675
2658
}
2676
2659
}
0 commit comments