@@ -111,10 +111,10 @@ op_precedence! {
111
111
Suffix => Call ,
112
112
}
113
113
impl ExprPrec {
114
- fn merge_with ( & self , other : Self ) -> Self {
115
- match ( * self , other) {
114
+ fn merge_with ( self , other : Self ) -> Self {
115
+ match ( self , other) {
116
116
( Self :: Suffix | Self :: Field , Self :: Suffix | Self :: Field ) => other,
117
- _ => core:: cmp:: min ( * self , other) ,
117
+ _ => core:: cmp:: min ( self , other) ,
118
118
}
119
119
}
120
120
}
@@ -178,7 +178,11 @@ macro_rules! bin_op {
178
178
impl SuggBuilder {
179
179
fn parse_bin_op( & mut self , input: ParseStream <' _>, var: Option <ExprVar >) -> Option <BinOp > {
180
180
use ExprPos :: * ;
181
- $( if self . consume_op_token_space_prefixed:: <Token ![ $( $op_tt) * ] >( input, var, concat_idents!( $prec, Lhs ) ) {
181
+ $( if self . consume_op_token_space_prefixed:: <Token ![ $( $op_tt) * ] >(
182
+ input,
183
+ var,
184
+ concat_idents!( $prec, Lhs )
185
+ ) {
182
186
self . next_string. push( ' ' ) ;
183
187
Some ( BinOp {
184
188
prec: ExprPrec :: $prec,
@@ -335,7 +339,9 @@ impl SuggBuilder {
335
339
}
336
340
337
341
fn require_token < T : Token > ( & mut self , input : ParseStream < ' _ > , msg : & str ) -> Result < ( ) > {
338
- self . consume_token :: < T > ( input) . then ( || ( ) ) . ok_or_else ( || input. error ( msg) )
342
+ self . consume_token :: < T > ( input)
343
+ . then ( || ( ) )
344
+ . ok_or_else ( || input. error ( msg) )
339
345
}
340
346
341
347
fn consume_token < T : Token > ( & mut self , input : ParseStream < ' _ > ) -> bool {
@@ -430,6 +436,7 @@ impl SuggBuilder {
430
436
self . require ( input, Self :: parse_ty, "expected a type" ) . map ( Some )
431
437
}
432
438
439
+ #[ allow( clippy:: blocks_in_if_conditions) ]
433
440
fn parse_ty_body ( & mut self , input : ParseStream ) -> Result < Option < ( ) > > {
434
441
if let Some ( ends_with_ident) = self . parse_path_root ( input) ? {
435
442
if ends_with_ident && self . consume_token :: < Token ! [ <] > ( input) {
@@ -440,19 +447,17 @@ impl SuggBuilder {
440
447
input,
441
448
|_| ( ) ,
442
449
|self_, input| {
443
- self_. require ( & input, Self :: parse_ty, "expected a type" ) ?;
444
- if self_. consume_token :: < Token ! [ ; ] > ( & input) {
450
+ self_. require ( input, Self :: parse_ty, "expected a type" ) ?;
451
+ if self_. consume_token :: < Token ! [ ; ] > ( input) {
445
452
self_. next_string . push ( ' ' ) ;
446
- self_. require ( & input, Self :: parse_expr, "expected an expression" ) ?;
453
+ self_. require ( input, Self :: parse_expr, "expected an expression" ) ?;
447
454
}
448
455
Ok ( ( ) )
449
456
} ,
450
- ) ? {
451
- // Nothing to do
452
- } else if self . consume_group :: < token:: Paren > (
457
+ ) ? || self . consume_group :: < token:: Paren > (
453
458
input,
454
459
|_| ( ) ,
455
- |self_, input| self_. parse_list ( & input, Self :: parse_ty) ,
460
+ |self_, input| self_. parse_list ( input, Self :: parse_ty) ,
456
461
) ? {
457
462
// Nothing to do
458
463
} else if let Some ( var) = parse_var ( input) {
@@ -549,15 +554,14 @@ impl SuggBuilder {
549
554
}
550
555
551
556
fn parse_expr_body ( & mut self , input : ParseStream < ' _ > , pos : ExprPos , prec : ExprPrec ) -> Result < Option < ExprPrec > > {
552
- if self . consume_token :: < Literal > ( input) {
553
- // Nothing to do
554
- } else if self . consume_group :: < token:: Paren > (
555
- input,
556
- |_| ( ) ,
557
- |self_, input| self_. parse_list ( & input, Self :: parse_expr) . map ( |_| ( ) ) ,
558
- ) ? {
559
- // Nothing to do
560
- } else if self . parse_path_root ( input) ?. is_some ( ) {
557
+ if self . consume_token :: < Literal > ( input)
558
+ || self . consume_group :: < token:: Paren > (
559
+ input,
560
+ |_| ( ) ,
561
+ |self_, input| self_. parse_list ( input, Self :: parse_expr) . map ( |_| ( ) ) ,
562
+ ) ?
563
+ || self . parse_path_root ( input) ?. is_some ( )
564
+ {
561
565
// Nothing to do
562
566
} else if let Some ( var) = parse_var ( input) {
563
567
return if matches ! ( var. kind, VarKind :: Expr | VarKind :: Default ) {
@@ -585,19 +589,22 @@ impl SuggBuilder {
585
589
self . next_string . push ( ' ' ) ;
586
590
self . require ( input, Self :: parse_ty, "expected a type" ) ?;
587
591
prec. merge_with ( ExprPrec :: Cast )
588
- } else if self . consume_op_token :: < Token ! [ ?] > ( input, var, ExprPos :: Suffix ) {
589
- prec. merge_with ( ExprPrec :: Suffix )
590
- } else if self . consume_group :: < token:: Bracket > (
591
- input,
592
- |self_| self_. push_expr_var ( var, ExprPos :: Suffix ) ,
593
- |self_, input| self_. require ( & input, Self :: parse_expr, "expected an expression" ) . map ( |_| ( ) ) ,
594
- ) ? {
595
- prec. merge_with ( ExprPrec :: Suffix )
596
- } else if self . consume_group :: < token:: Paren > (
597
- input,
598
- |self_| self_. push_expr_var ( var, ExprPos :: Callee ) ,
599
- |self_, input| self_. parse_list ( & input, Self :: parse_expr) . map ( |_| ( ) ) ,
600
- ) ? {
592
+ } else if self . consume_op_token :: < Token ! [ ?] > ( input, var, ExprPos :: Suffix )
593
+ || self . consume_group :: < token:: Bracket > (
594
+ input,
595
+ |self_| self_. push_expr_var ( var, ExprPos :: Suffix ) ,
596
+ |self_, input| {
597
+ self_
598
+ . require ( input, Self :: parse_expr, "expected an expression" )
599
+ . map ( |_| ( ) )
600
+ } ,
601
+ ) ?
602
+ || self . consume_group :: < token:: Paren > (
603
+ input,
604
+ |self_| self_. push_expr_var ( var, ExprPos :: Callee ) ,
605
+ |self_, input| self_. parse_list ( input, Self :: parse_expr) . map ( |_| ( ) ) ,
606
+ ) ?
607
+ {
601
608
prec. merge_with ( ExprPrec :: Suffix )
602
609
} else if self . consume_op_token :: < Token ! [ . ] > ( input, var, ExprPos :: Suffix ) {
603
610
if self . consume_token :: < Ident > ( input) {
@@ -700,22 +707,24 @@ impl SuggBuilder {
700
707
let s = & self . next_string ;
701
708
body. extend ( iter:: once ( quote ! ( sugg. push_str( #s) ; ) ) ) ;
702
709
}
703
- if prec != ExprPrec :: Suffix {
710
+ if prec == ExprPrec :: Suffix {
711
+ body. extend ( iter:: once ( quote ! ( sugg) ) ) ;
712
+ } else {
704
713
body. extend ( iter:: once ( quote ! (
705
714
if clippy_utils:: _internal:: needs_parens( #prec, clippy_utils:: _internal:: expr_position( cx, e) ) {
706
715
format!( "({})" , sugg)
707
716
} else {
708
717
sugg
709
718
}
710
719
) ) ) ;
711
- } else {
712
- body. extend ( iter:: once ( quote ! ( sugg) ) ) ;
713
720
}
714
- Ok ( quote ! ( |cx: & rustc_lint:: LateContext <' _>, e: & rustc_hir:: Expr <' _>, app: & mut rustc_errors:: Applicability | {
715
- let ctxt = e. span. ctxt( ) ;
716
- let mut sugg = String :: new( ) ;
717
- #body
718
- } ) )
721
+ Ok (
722
+ quote ! ( |cx: & rustc_lint:: LateContext <' _>, e: & rustc_hir:: Expr <' _>, app: & mut rustc_errors:: Applicability | {
723
+ let ctxt = e. span. ctxt( ) ;
724
+ let mut sugg = String :: new( ) ;
725
+ #body
726
+ } ) ,
727
+ )
719
728
}
720
729
}
721
730
@@ -742,6 +751,7 @@ fn split_args(input: ParseStream) -> Result<Vec<TokenStream>> {
742
751
}
743
752
}
744
753
754
+ #[ allow( clippy:: module_name_repetitions) ]
745
755
pub struct ExprSugg ( pub TokenStream ) ;
746
756
impl Parse for ExprSugg {
747
757
fn parse ( input : ParseStream < ' _ > ) -> Result < Self > {
0 commit comments