@@ -656,6 +656,25 @@ trait UnusedDelimLint {
656656 is_kw : bool ,
657657 ) ;
658658
659+ #[ inline]
660+ fn impacts_followed_by_block ( e : & ast:: Expr ) -> bool {
661+ return match e. kind {
662+ ExprKind :: Block ( ..) | ExprKind :: Call ( ..) | ExprKind :: MethodCall ( ..) => true ,
663+ _ => Self :: is_followed_by_block ( e) ,
664+ } ;
665+ }
666+
667+ #[ inline]
668+ fn is_followed_by_block ( e : & ast:: Expr ) -> bool {
669+ return match e. kind {
670+ ExprKind :: If ( ref cond, ..) if !matches ! ( cond. kind, ExprKind :: Let ( ..) ) => true ,
671+ ExprKind :: While ( ref cond, ..) if !matches ! ( cond. kind, ExprKind :: Let ( ..) ) => true ,
672+ ExprKind :: ForLoop { .. } => true ,
673+ ExprKind :: Match ( _, _, ast:: MatchKind :: Prefix ) => true ,
674+ _ => false ,
675+ } ;
676+ }
677+
659678 fn is_expr_delims_necessary (
660679 inner : & ast:: Expr ,
661680 ctx : UnusedDelimsCtx ,
@@ -1050,6 +1069,7 @@ pub(crate) struct UnusedParens {
10501069 /// `1 as (i32) < 2` parses to ExprKind::Lt
10511070 /// `1 as i32 < 2` parses to i32::<2[missing angle bracket]
10521071 parens_in_cast_in_lt : Vec < ast:: NodeId > ,
1072+ <<<<<<< HEAD
10531073 /// Ty nodes in this map are in TypeNoBounds position. Any bounds they
10541074 /// contain may be ambiguous w/r/t trailing `+` operators.
10551075 in_no_bounds_pos: FxHashMap < ast:: NodeId , NoBoundsException > ,
@@ -1075,6 +1095,12 @@ enum NoBoundsException {
10751095 /// The type is the last bound of the containing type expression. If it has exactly one bound,
10761096 /// parentheses around the type are unnecessary.
10771097 OneBound ,
1098+ =======
1099+ // Used for tracking parent expressions that would immediately followed
1100+ // by block. Storing false here indicates that expression itself is Block
1101+ // expression. This is meant for to prevent report false positive cases.
1102+ followed_by_block : Vec < bool > ,
1103+ >>>>>>> 5 c02bc9efda ( Improve changes)
10781104}
10791105
10801106impl_lint_pass!( UnusedParens => [ UNUSED_PARENS ] ) ;
@@ -1477,32 +1503,14 @@ declare_lint! {
14771503
14781504#[ derive( Default ) ]
14791505pub ( crate ) struct UnusedBraces {
1480- parent_followed_by_block : Vec < bool > ,
1506+ // Used for tracking parent expressions that would immediately followed
1507+ // by block. Storing false here indicates that expression itself is Block
1508+ // expression. This is meant for to prevent report false positive cases.
1509+ followed_by_block : Vec < bool > ,
14811510}
14821511
14831512impl_lint_pass ! ( UnusedBraces => [ UNUSED_BRACES ] ) ;
14841513
1485- impl UnusedBraces {
1486- #[ inline]
1487- fn should_mark_block ( e : & ast:: Expr ) -> bool {
1488- return match e. kind {
1489- ExprKind :: Block ( ..) => true ,
1490- _ => Self :: is_followed_by_block ( e) ,
1491- } ;
1492- }
1493-
1494- #[ inline]
1495- fn is_followed_by_block ( e : & ast:: Expr ) -> bool {
1496- return match e. kind {
1497- ExprKind :: If ( ref cond, ..) if !matches ! ( cond. kind, ExprKind :: Let ( ..) ) => true ,
1498- ExprKind :: While ( ref cond, ..) if !matches ! ( cond. kind, ExprKind :: Let ( ..) ) => true ,
1499- ExprKind :: ForLoop { .. } => true ,
1500- ExprKind :: Match ( _, _, ast:: MatchKind :: Prefix ) => true ,
1501- _ => false ,
1502- } ;
1503- }
1504- }
1505-
15061514impl UnusedDelimLint for UnusedBraces {
15071515 const DELIM_STR : & ' static str = "braces" ;
15081516
@@ -1600,8 +1608,8 @@ impl EarlyLintPass for UnusedBraces {
16001608 fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
16011609 <Self as UnusedDelimLint >:: check_expr ( self , cx, e) ;
16021610
1603- if Self :: should_mark_block ( e) {
1604- self . parent_followed_by_block . push ( Self :: is_followed_by_block ( e) ) ;
1611+ if < Self as UnusedDelimLint > :: impacts_followed_by_block ( e) {
1612+ self . followed_by_block . push ( < Self as UnusedDelimLint > :: is_followed_by_block ( e) ) ;
16051613 }
16061614
16071615 if let ExprKind :: Repeat ( _, ref anon_const) = e. kind {
@@ -1618,11 +1626,9 @@ impl EarlyLintPass for UnusedBraces {
16181626 }
16191627
16201628 fn check_expr_post ( & mut self , _cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
1621- if Self :: should_mark_block ( e) {
1622- let followed_by_block = self
1623- . parent_followed_by_block
1624- . pop ( )
1625- . expect ( "check_expr and check_expr_post must balance" ) ;
1629+ if <Self as UnusedDelimLint >:: impacts_followed_by_block ( e) {
1630+ let followed_by_block =
1631+ self . followed_by_block . pop ( ) . expect ( "check_expr and check_expr_post must balance" ) ;
16261632 assert_eq ! (
16271633 followed_by_block,
16281634 Self :: is_followed_by_block( e) ,
0 commit comments