Skip to content

Commit 83f2eb7

Browse files
committed
Auto merge of #4469 - vityafx:master, r=flip1995
Improve the 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> changelog: improve the `cognitive_complexity` lint's warning message.
2 parents 4c8a941 + 87ef86e commit 83f2eb7

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

clippy_lints/src/cognitive_complexity.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ impl CognitiveComplexity {
100100
cx,
101101
COGNITIVE_COMPLEXITY,
102102
span,
103-
&format!("the function has a cognitive complexity of {}", rust_cc),
103+
&format!(
104+
"the function has a cognitive complexity of ({}/{})",
105+
rust_cc,
106+
self.limit.limit()
107+
),
104108
"you could split it up into multiple smaller functions",
105109
);
106110
}

tests/ui/cognitive_complexity.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: the function has a cognitive complexity of 28
1+
error: the function has a cognitive complexity of (28/25)
22
--> $DIR/cognitive_complexity.rs:6:1
33
|
44
LL | / fn main() {
@@ -13,7 +13,7 @@ LL | | }
1313
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
1414
= help: you could split it up into multiple smaller functions
1515

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

257-
error: the function has a cognitive complexity of 8
257+
error: the function has a cognitive complexity of (8/0)
258258
--> $DIR/cognitive_complexity.rs:354:1
259259
|
260260
LL | / fn early_ret() -> i32 {

tests/ui/cognitive_complexity_attr_used.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: the function has a cognitive complexity of 3
1+
error: the function has a cognitive complexity of (3/0)
22
--> $DIR/cognitive_complexity_attr_used.rs:9:1
33
|
44
LL | / fn kaboom() {

0 commit comments

Comments
 (0)