@@ -619,7 +619,7 @@ impl<'ast> State<'_, 'ast> {
619
619
fn print_fn_attribute (
620
620
& mut self ,
621
621
span : Span ,
622
- map : & mut HashMap < BytePos , ( Vec < Comment > , Vec < Comment > , Vec < Comment > ) > ,
622
+ map : & mut AttributeCommentMap ,
623
623
print_fn : & mut dyn FnMut ( & mut Self ) ,
624
624
) {
625
625
match map. remove ( & span. lo ( ) ) {
@@ -1228,7 +1228,7 @@ impl<'ast> State<'_, 'ast> {
1228
1228
ast:: ExprKind :: Assign ( lhs, Some ( bin_op) , rhs)
1229
1229
| ast:: ExprKind :: Binary ( lhs, bin_op, rhs) => {
1230
1230
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 ( ) ) ;
1232
1232
1233
1233
self . print_expr_with (
1234
1234
|s| {
@@ -1301,7 +1301,7 @@ impl<'ast> State<'_, 'ast> {
1301
1301
}
1302
1302
}
1303
1303
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) ;
1305
1305
let with_single_call_chain_child = if call_args. len ( ) == 1
1306
1306
&& let Some ( child) = & call_args. exprs ( ) . next ( )
1307
1307
&& is_call_chain ( & child. kind , false )
@@ -1559,7 +1559,7 @@ impl<'ast> State<'_, 'ast> {
1559
1559
) where
1560
1560
F : FnOnce ( & mut Self ) ,
1561
1561
{
1562
- let parent_call = self . call_stack . last ( ) . cloned ( ) ;
1562
+ let parent_call = self . call_stack . last ( ) . copied ( ) ;
1563
1563
1564
1564
// Determine the position of the formatted expression.
1565
1565
// When NOT in a chain, start a new one.
@@ -1899,7 +1899,7 @@ impl<'ast> State<'_, 'ast> {
1899
1899
1900
1900
// `return ' + expr + ';'
1901
1901
let overflows = space_left < 8 + expr_size;
1902
- let fits_alone = space_left >= expr_size + 1 ;
1902
+ let fits_alone = space_left > expr_size;
1903
1903
1904
1904
if let Some ( expr) = expr {
1905
1905
self . return_bin_expr = matches ! ( & expr. kind, ast:: ExprKind :: Binary ( ..) ) ;
@@ -2421,6 +2421,8 @@ enum AttributeKind<'ast> {
2421
2421
Modifier ( & ' ast ast:: Modifier < ' ast > ) ,
2422
2422
}
2423
2423
2424
+ type AttributeCommentMap = HashMap < BytePos , ( Vec < Comment > , Vec < Comment > , Vec < Comment > ) > ;
2425
+
2424
2426
impl < ' ast > AttributeKind < ' ast > {
2425
2427
fn is_visibility ( & self ) -> bool {
2426
2428
matches ! ( self , Self :: Visibility ( _) )
@@ -2476,17 +2478,13 @@ impl<'ast> AttributeCommentMapper<'ast> {
2476
2478
mut self ,
2477
2479
state : & mut State < ' _ , ' ast > ,
2478
2480
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 ) {
2484
2482
let first_attr = self . collect_attributes ( header) ;
2485
2483
self . cache_comments ( state) ;
2486
2484
( self . map ( ) , self . attributes , first_attr)
2487
2485
}
2488
2486
2489
- fn map ( & mut self ) -> HashMap < BytePos , ( Vec < Comment > , Vec < Comment > , Vec < Comment > ) > {
2487
+ fn map ( & mut self ) -> AttributeCommentMap {
2490
2488
let mut map = HashMap :: new ( ) ;
2491
2489
for a in 0 ..self . attributes . len ( ) {
2492
2490
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> {
2682
2680
}
2683
2681
2684
2682
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 ( ..) )
2689
2684
}
2690
2685
2691
2686
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 ( ..) )
2696
2688
}
2697
2689
2698
2690
fn is_call_chain ( expr_kind : & ast:: ExprKind < ' _ > , must_have_child : bool ) -> bool {
@@ -2735,25 +2727,16 @@ trait BinOpExt {
2735
2727
impl BinOpExt for ast:: BinOpKind {
2736
2728
fn group ( & self ) -> BinOpGroup {
2737
2729
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
+ }
2757
2740
}
2758
2741
}
2759
2742
}
0 commit comments