File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ impl CognitiveComplexity {
62
62
63
63
let mut cc = 1u64 ;
64
64
let mut returns = 0u64 ;
65
+ let mut prev_expr: Option < & ExprKind < ' tcx > > = None ;
65
66
let _: Option < !> = for_each_expr_without_closures ( expr, |e| {
66
67
match e. kind {
67
68
ExprKind :: If ( _, _, _) => {
@@ -73,9 +74,14 @@ impl CognitiveComplexity {
73
74
}
74
75
cc += arms. iter ( ) . filter ( |arm| arm. guard . is_some ( ) ) . count ( ) as u64 ;
75
76
} ,
76
- ExprKind :: Ret ( _) => returns += 1 ,
77
+ ExprKind :: Ret ( _) => {
78
+ if !matches ! ( prev_expr, Some ( ExprKind :: Ret ( _) ) ) {
79
+ returns += 1 ;
80
+ }
81
+ } ,
77
82
_ => { } ,
78
83
}
84
+ prev_expr = Some ( & e. kind ) ;
79
85
ControlFlow :: Continue ( ( ) )
80
86
} ) ;
81
87
Original file line number Diff line number Diff line change @@ -448,3 +448,20 @@ mod issue9300 {
448
448
}
449
449
}
450
450
}
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