Skip to content

Commit 7bfdee5

Browse files
committed
Auto merge of #5428 - dtolnay:cognitive, r=flip1995
Move cognitive_complexity to nursery As discussed in #5418 (comment); Clippy's current understanding of cognitive complexity is not good enough yet at analyzing code for understandability to have this lint be enabled by default. changelog: Remove cognitive_complexity from default set of enabled lints
2 parents f8308c8 + 899a1b5 commit 7bfdee5

23 files changed

+48
-58
lines changed

clippy_lints/src/assign_ops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7777
},
7878
hir::ExprKind::Assign(assignee, e, _) => {
7979
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
80-
#[allow(clippy::cognitive_complexity)]
8180
let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| {
8281
let ty = cx.tables.expr_ty(assignee);
8382
let rty = cx.tables.expr_ty(rhs);

clippy_lints/src/cognitive_complexity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare_clippy_lint! {
2222
///
2323
/// **Example:** No. You'll see it when you get the warning.
2424
pub COGNITIVE_COMPLEXITY,
25-
complexity,
25+
nursery,
2626
"functions that should be split up into multiple functions"
2727
}
2828

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11741174
LintId::of(&booleans::LOGIC_BUG),
11751175
LintId::of(&booleans::NONMINIMAL_BOOL),
11761176
LintId::of(&bytecount::NAIVE_BYTECOUNT),
1177-
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
11781177
LintId::of(&collapsible_if::COLLAPSIBLE_IF),
11791178
LintId::of(&comparison_chain::COMPARISON_CHAIN),
11801179
LintId::of(&copies::IFS_SAME_COND),
@@ -1509,7 +1508,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15091508
LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP),
15101509
LintId::of(&attrs::DEPRECATED_CFG_ATTR),
15111510
LintId::of(&booleans::NONMINIMAL_BOOL),
1512-
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
15131511
LintId::of(&double_comparison::DOUBLE_COMPARISONS),
15141512
LintId::of(&double_parens::DOUBLE_PARENS),
15151513
LintId::of(&duration_subsec::DURATION_SUBSEC),
@@ -1678,6 +1676,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16781676

16791677
store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
16801678
LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
1679+
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
16811680
LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM),
16821681
LintId::of(&floating_point_arithmetic::IMPRECISE_FLOPS),
16831682
LintId::of(&floating_point_arithmetic::SUBOPTIMAL_FLOPS),

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ declare_lint_pass!(Methods => [
13171317
]);
13181318

13191319
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
1320-
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
1320+
#[allow(clippy::too_many_lines)]
13211321
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
13221322
if in_macro(expr.span) {
13231323
return;

clippy_lints/src/mutable_debug_assertion.rs

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall {
5353
}
5454

5555
//HACK(hellow554): remove this when #4694 is implemented
56-
#[allow(clippy::cognitive_complexity)]
5756
fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option<Span> {
5857
if_chain! {
5958
if let ExprKind::Block(ref block, _) = e.kind;

clippy_lints/src/types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ impl Types {
315315
/// The parameter `is_local` distinguishes the context of the type; types from
316316
/// local bindings should only be checked for the `BORROWED_BOX` lint.
317317
#[allow(clippy::too_many_lines)]
318-
#[allow(clippy::cognitive_complexity)]
319318
fn check_ty(&mut self, cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool) {
320319
if hir_ty.span.from_expansion() {
321320
return;

src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
250250
},
251251
Lint {
252252
name: "cognitive_complexity",
253-
group: "complexity",
253+
group: "nursery",
254254
desc: "functions that should be split up into multiple functions",
255255
deprecation: None,
256256
module: "cognitive_complexity",

tests/ui/collapsible_else_if.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
2+
#![allow(clippy::assertions_on_constants)]
33

44
#[rustfmt::skip]
55
#[warn(clippy::collapsible_if)]

tests/ui/collapsible_else_if.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
2+
#![allow(clippy::assertions_on_constants)]
33

44
#[rustfmt::skip]
55
#[warn(clippy::collapsible_if)]

tests/ui/collapsible_if.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
2+
#![allow(clippy::assertions_on_constants)]
33

44
#[rustfmt::skip]
55
#[warn(clippy::collapsible_if)]

tests/ui/collapsible_if.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
2+
#![allow(clippy::assertions_on_constants)]
33

44
#[rustfmt::skip]
55
#[warn(clippy::collapsible_if)]

tests/ui/debug_assert_with_mut_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(custom_inner_attributes)]
33
#![rustfmt::skip]
44
#![warn(clippy::debug_assert_with_mut_call)]
5-
#![allow(clippy::cognitive_complexity, clippy::redundant_closure_call)]
5+
#![allow(clippy::redundant_closure_call)]
66

77
struct S;
88

tests/ui/for_loop_fixable.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ impl Unrelated {
2828
clippy::linkedlist,
2929
clippy::shadow_unrelated,
3030
clippy::unnecessary_mut_passed,
31-
clippy::cognitive_complexity,
3231
clippy::similar_names
3332
)]
3433
#[allow(clippy::many_single_char_names, unused_variables)]

tests/ui/for_loop_fixable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ impl Unrelated {
2828
clippy::linkedlist,
2929
clippy::shadow_unrelated,
3030
clippy::unnecessary_mut_passed,
31-
clippy::cognitive_complexity,
3231
clippy::similar_names
3332
)]
3433
#[allow(clippy::many_single_char_names, unused_variables)]

tests/ui/for_loop_fixable.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this range is empty so this for loop will never run
2-
--> $DIR/for_loop_fixable.rs:39:14
2+
--> $DIR/for_loop_fixable.rs:38:14
33
|
44
LL | for i in 10..0 {
55
| ^^^^^
@@ -11,7 +11,7 @@ LL | for i in (0..10).rev() {
1111
| ^^^^^^^^^^^^^
1212

1313
error: this range is empty so this for loop will never run
14-
--> $DIR/for_loop_fixable.rs:43:14
14+
--> $DIR/for_loop_fixable.rs:42:14
1515
|
1616
LL | for i in 10..=0 {
1717
| ^^^^^^
@@ -22,7 +22,7 @@ LL | for i in (0..=10).rev() {
2222
| ^^^^^^^^^^^^^^
2323

2424
error: this range is empty so this for loop will never run
25-
--> $DIR/for_loop_fixable.rs:47:14
25+
--> $DIR/for_loop_fixable.rs:46:14
2626
|
2727
LL | for i in MAX_LEN..0 {
2828
| ^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | for i in (0..MAX_LEN).rev() {
3333
| ^^^^^^^^^^^^^^^^^^
3434

3535
error: this range is empty so this for loop will never run
36-
--> $DIR/for_loop_fixable.rs:72:14
36+
--> $DIR/for_loop_fixable.rs:71:14
3737
|
3838
LL | for i in 10..5 + 4 {
3939
| ^^^^^^^^^
@@ -44,7 +44,7 @@ LL | for i in (5 + 4..10).rev() {
4444
| ^^^^^^^^^^^^^^^^^
4545

4646
error: this range is empty so this for loop will never run
47-
--> $DIR/for_loop_fixable.rs:76:14
47+
--> $DIR/for_loop_fixable.rs:75:14
4848
|
4949
LL | for i in (5 + 2)..(3 - 1) {
5050
| ^^^^^^^^^^^^^^^^
@@ -55,95 +55,95 @@ LL | for i in ((3 - 1)..(5 + 2)).rev() {
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^
5656

5757
error: it is more concise to loop over references to containers instead of using explicit iteration methods
58-
--> $DIR/for_loop_fixable.rs:98:15
58+
--> $DIR/for_loop_fixable.rs:97:15
5959
|
6060
LL | for _v in vec.iter() {}
6161
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
6262
|
6363
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
6464

6565
error: it is more concise to loop over references to containers instead of using explicit iteration methods
66-
--> $DIR/for_loop_fixable.rs:100:15
66+
--> $DIR/for_loop_fixable.rs:99:15
6767
|
6868
LL | for _v in vec.iter_mut() {}
6969
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
7070

7171
error: it is more concise to loop over containers instead of using explicit iteration methods
72-
--> $DIR/for_loop_fixable.rs:103:15
72+
--> $DIR/for_loop_fixable.rs:102:15
7373
|
7474
LL | for _v in out_vec.into_iter() {}
7575
| ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
7676
|
7777
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
7878

7979
error: it is more concise to loop over references to containers instead of using explicit iteration methods
80-
--> $DIR/for_loop_fixable.rs:108:15
80+
--> $DIR/for_loop_fixable.rs:107:15
8181
|
8282
LL | for _v in [1, 2, 3].iter() {}
8383
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
8484

8585
error: it is more concise to loop over references to containers instead of using explicit iteration methods
86-
--> $DIR/for_loop_fixable.rs:112:15
86+
--> $DIR/for_loop_fixable.rs:111:15
8787
|
8888
LL | for _v in [0; 32].iter() {}
8989
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
9090

9191
error: it is more concise to loop over references to containers instead of using explicit iteration methods
92-
--> $DIR/for_loop_fixable.rs:117:15
92+
--> $DIR/for_loop_fixable.rs:116:15
9393
|
9494
LL | for _v in ll.iter() {}
9595
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
9696

9797
error: it is more concise to loop over references to containers instead of using explicit iteration methods
98-
--> $DIR/for_loop_fixable.rs:120:15
98+
--> $DIR/for_loop_fixable.rs:119:15
9999
|
100100
LL | for _v in vd.iter() {}
101101
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
102102

103103
error: it is more concise to loop over references to containers instead of using explicit iteration methods
104-
--> $DIR/for_loop_fixable.rs:123:15
104+
--> $DIR/for_loop_fixable.rs:122:15
105105
|
106106
LL | for _v in bh.iter() {}
107107
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
108108

109109
error: it is more concise to loop over references to containers instead of using explicit iteration methods
110-
--> $DIR/for_loop_fixable.rs:126:15
110+
--> $DIR/for_loop_fixable.rs:125:15
111111
|
112112
LL | for _v in hm.iter() {}
113113
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
114114

115115
error: it is more concise to loop over references to containers instead of using explicit iteration methods
116-
--> $DIR/for_loop_fixable.rs:129:15
116+
--> $DIR/for_loop_fixable.rs:128:15
117117
|
118118
LL | for _v in bt.iter() {}
119119
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
120120

121121
error: it is more concise to loop over references to containers instead of using explicit iteration methods
122-
--> $DIR/for_loop_fixable.rs:132:15
122+
--> $DIR/for_loop_fixable.rs:131:15
123123
|
124124
LL | for _v in hs.iter() {}
125125
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
126126

127127
error: it is more concise to loop over references to containers instead of using explicit iteration methods
128-
--> $DIR/for_loop_fixable.rs:135:15
128+
--> $DIR/for_loop_fixable.rs:134:15
129129
|
130130
LL | for _v in bs.iter() {}
131131
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
132132

133133
error: it is more concise to loop over containers instead of using explicit iteration methods
134-
--> $DIR/for_loop_fixable.rs:310:18
134+
--> $DIR/for_loop_fixable.rs:309:18
135135
|
136136
LL | for i in iterator.into_iter() {
137137
| ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator`
138138

139139
error: it is more concise to loop over references to containers instead of using explicit iteration methods
140-
--> $DIR/for_loop_fixable.rs:330:18
140+
--> $DIR/for_loop_fixable.rs:329:18
141141
|
142142
LL | for _ in t.into_iter() {}
143143
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t`
144144

145145
error: it is more concise to loop over containers instead of using explicit iteration methods
146-
--> $DIR/for_loop_fixable.rs:332:18
146+
--> $DIR/for_loop_fixable.rs:331:18
147147
|
148148
LL | for _ in r.into_iter() {}
149149
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `r`

tests/ui/for_loop_unfixable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
clippy::linkedlist,
1313
clippy::shadow_unrelated,
1414
clippy::unnecessary_mut_passed,
15-
clippy::cognitive_complexity,
1615
clippy::similar_names,
1716
unused,
1817
dead_code

tests/ui/for_loop_unfixable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find function `f` in this scope
2-
--> $DIR/for_loop_unfixable.rs:37:12
2+
--> $DIR/for_loop_unfixable.rs:36:12
33
|
44
LL | if f(&vec[i], &vec[i]) {
55
| ^ help: a local variable with a similar name exists: `i`

tests/ui/if_same_then_else2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![warn(clippy::if_same_then_else)]
22
#![allow(
33
clippy::blacklisted_name,
4-
clippy::cognitive_complexity,
54
clippy::collapsible_if,
65
clippy::ifs_same_cond,
76
clippy::needless_return

0 commit comments

Comments
 (0)