about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVictor Polevoy <fx@thefx.co>2019-08-29 10:56:13 +0200
committerVictor Polevoy <fx@thefx.co>2019-08-29 11:54:18 +0200
commit87ef86ef5a8e657ee20bd7a61c6a0cadd1b038b2 (patch)
tree82df96b302096223eeaae73d75dfc52e026f6b65
parent4c8a941dafff56a2485258b85b33ba33e66f6258 (diff)
downloadrust-87ef86ef5a8e657ee20bd7a61c6a0cadd1b038b2.tar.gz
rust-87ef86ef5a8e657ee20bd7a61c6a0cadd1b038b2.zip
Improve cognitive_complexity lint's warning.
Adds the value of complexity limit set for the lint
to the warning.

Fixes #4466

Signed-off-by: Victor Polevoy <fx@thefx.co>
-rw-r--r--clippy_lints/src/cognitive_complexity.rs6
-rw-r--r--tests/ui/cognitive_complexity.stderr40
-rw-r--r--tests/ui/cognitive_complexity_attr_used.stderr2
3 files changed, 26 insertions, 22 deletions
diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs
index 88b8d8688b6..fccec347ef0 100644
--- a/clippy_lints/src/cognitive_complexity.rs
+++ b/clippy_lints/src/cognitive_complexity.rs
@@ -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",
                 );
             }
diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr
index 824b056388b..32a56f00c5d 100644
--- a/tests/ui/cognitive_complexity.stderr
+++ b/tests/ui/cognitive_complexity.stderr
@@ -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() {
@@ -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() {
@@ -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 {
@@ -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 {
@@ -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() {
@@ -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 {
@@ -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() {
@@ -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() {
@@ -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() {
@@ -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() {
@@ -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() {
@@ -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() {
@@ -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() {
@@ -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() {
@@ -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 {
@@ -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) {
@@ -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> {
@@ -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> {
@@ -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> {
@@ -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 {
diff --git a/tests/ui/cognitive_complexity_attr_used.stderr b/tests/ui/cognitive_complexity_attr_used.stderr
index 2cf41506f56..d06066972fb 100644
--- a/tests/ui/cognitive_complexity_attr_used.stderr
+++ b/tests/ui/cognitive_complexity_attr_used.stderr
@@ -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() {