File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ impl CognitiveComplexity {
6262
6363 let mut cc = 1u64 ;
6464 let mut returns = 0u64 ;
65+ let mut prev_expr: Option < & ExprKind < ' tcx > > = None ;
6566 let _: Option < !> = for_each_expr_without_closures ( expr, |e| {
6667 match e. kind {
6768 ExprKind :: If ( _, _, _) => {
@@ -73,9 +74,14 @@ impl CognitiveComplexity {
7374 }
7475 cc += arms. iter ( ) . filter ( |arm| arm. guard . is_some ( ) ) . count ( ) as u64 ;
7576 } ,
76- ExprKind :: Ret ( _) => returns += 1 ,
77+ ExprKind :: Ret ( _) => {
78+ if !matches ! ( prev_expr, Some ( ExprKind :: Ret ( _) ) ) {
79+ returns += 1 ;
80+ }
81+ } ,
7782 _ => { } ,
7883 }
84+ prev_expr = Some ( & e. kind ) ;
7985 ControlFlow :: Continue ( ( ) )
8086 } ) ;
8187
Original file line number Diff line number Diff line change @@ -448,3 +448,20 @@ mod issue9300 {
448448 }
449449 }
450450}
451+
452+ #[ clippy:: cognitive_complexity = "2" ]
453+ mod issue14422 {
454+ fn foo ( ) {
455+ for _ in 0 ..10 {
456+ println ! ( "hello there" ) ;
457+ }
458+ }
459+
460+ fn bar ( ) {
461+ for _ in 0 ..10 {
462+ println ! ( "hello there" ) ;
463+ }
464+ return ;
465+ return ;
466+ }
467+ }
You can’t perform that action at this time.
0 commit comments