Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the cognitive_complexity lint's warning. #4469

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ impl CognitiveComplexity {
cx,
COGNITIVE_COMPLEXITY,
span,
&format!("the function has a cognitive complexity of {}", rust_cc),
&format!(
"the function has a cognitive complexity of ({}/{})",
rust_cc,
self.limit.limit()
),
"you could split it up into multiple smaller functions",
);
}
Expand Down
40 changes: 20 additions & 20 deletions tests/ui/cognitive_complexity.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the function has a cognitive complexity of 28
error: the function has a cognitive complexity of (28/25)
--> $DIR/cognitive_complexity.rs:6:1
|
LL | / fn main() {
Expand All @@ -13,7 +13,7 @@ LL | | }
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 7
error: the function has a cognitive complexity of (7/0)
--> $DIR/cognitive_complexity.rs:91:1
|
LL | / fn kaboom() {
Expand All @@ -27,7 +27,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 1
error: the function has a cognitive complexity of (1/0)
--> $DIR/cognitive_complexity.rs:137:1
|
LL | / fn lots_of_short_circuits() -> bool {
Expand All @@ -37,7 +37,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 1
error: the function has a cognitive complexity of (1/0)
--> $DIR/cognitive_complexity.rs:142:1
|
LL | / fn lots_of_short_circuits2() -> bool {
Expand All @@ -47,7 +47,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:147:1
|
LL | / fn baa() {
Expand All @@ -61,7 +61,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:148:13
|
LL | let x = || match 99 {
Expand All @@ -76,7 +76,7 @@ LL | | };
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:165:1
|
LL | / fn bar() {
Expand All @@ -89,7 +89,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:184:1
|
LL | / fn barr() {
Expand All @@ -103,7 +103,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 3
error: the function has a cognitive complexity of (3/0)
--> $DIR/cognitive_complexity.rs:194:1
|
LL | / fn barr2() {
Expand All @@ -117,7 +117,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:210:1
|
LL | / fn barrr() {
Expand All @@ -131,7 +131,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 3
error: the function has a cognitive complexity of (3/0)
--> $DIR/cognitive_complexity.rs:220:1
|
LL | / fn barrr2() {
Expand All @@ -145,7 +145,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:236:1
|
LL | / fn barrrr() {
Expand All @@ -159,7 +159,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 3
error: the function has a cognitive complexity of (3/0)
--> $DIR/cognitive_complexity.rs:246:1
|
LL | / fn barrrr2() {
Expand All @@ -173,7 +173,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 2
error: the function has a cognitive complexity of (2/0)
--> $DIR/cognitive_complexity.rs:262:1
|
LL | / fn cake() {
Expand All @@ -187,7 +187,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 4
error: the function has a cognitive complexity of (4/0)
--> $DIR/cognitive_complexity.rs:272:1
|
LL | / pub fn read_file(input_path: &str) -> String {
Expand All @@ -201,7 +201,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 1
error: the function has a cognitive complexity of (1/0)
--> $DIR/cognitive_complexity.rs:303:1
|
LL | / fn void(void: Void) {
Expand All @@ -213,7 +213,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 1
error: the function has a cognitive complexity of (1/0)
--> $DIR/cognitive_complexity.rs:316:1
|
LL | / fn try_() -> Result<i32, &'static str> {
Expand All @@ -226,7 +226,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 1
error: the function has a cognitive complexity of (1/0)
--> $DIR/cognitive_complexity.rs:324:1
|
LL | / fn try_again() -> Result<i32, &'static str> {
Expand All @@ -240,7 +240,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 1
error: the function has a cognitive complexity of (1/0)
--> $DIR/cognitive_complexity.rs:340:1
|
LL | / fn early() -> Result<i32, &'static str> {
Expand All @@ -254,7 +254,7 @@ LL | | }
|
= help: you could split it up into multiple smaller functions

error: the function has a cognitive complexity of 8
error: the function has a cognitive complexity of (8/0)
--> $DIR/cognitive_complexity.rs:354:1
|
LL | / fn early_ret() -> i32 {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cognitive_complexity_attr_used.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the function has a cognitive complexity of 3
error: the function has a cognitive complexity of (3/0)
--> $DIR/cognitive_complexity_attr_used.rs:9:1
|
LL | / fn kaboom() {
Expand Down