Skip to content

Commit

Permalink
Auto merge of #5428 - dtolnay:cognitive, r=flip1995
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 8, 2020
2 parents f8308c8 + 899a1b5 commit 7bfdee5
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 58 deletions.
1 change: 0 additions & 1 deletion clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
},
hir::ExprKind::Assign(assignee, e, _) => {
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
#[allow(clippy::cognitive_complexity)]
let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| {
let ty = cx.tables.expr_ty(assignee);
let rty = cx.tables.expr_ty(rhs);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare_clippy_lint! {
///
/// **Example:** No. You'll see it when you get the warning.
pub COGNITIVE_COMPLEXITY,
complexity,
nursery,
"functions that should be split up into multiple functions"
}

Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&booleans::LOGIC_BUG),
LintId::of(&booleans::NONMINIMAL_BOOL),
LintId::of(&bytecount::NAIVE_BYTECOUNT),
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
LintId::of(&collapsible_if::COLLAPSIBLE_IF),
LintId::of(&comparison_chain::COMPARISON_CHAIN),
LintId::of(&copies::IFS_SAME_COND),
Expand Down Expand Up @@ -1509,7 +1508,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP),
LintId::of(&attrs::DEPRECATED_CFG_ATTR),
LintId::of(&booleans::NONMINIMAL_BOOL),
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
LintId::of(&double_comparison::DOUBLE_COMPARISONS),
LintId::of(&double_parens::DOUBLE_PARENS),
LintId::of(&duration_subsec::DURATION_SUBSEC),
Expand Down Expand Up @@ -1678,6 +1676,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:

store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM),
LintId::of(&floating_point_arithmetic::IMPRECISE_FLOPS),
LintId::of(&floating_point_arithmetic::SUBOPTIMAL_FLOPS),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ declare_lint_pass!(Methods => [
]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
#[allow(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
if in_macro(expr.span) {
return;
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/mutable_debug_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall {
}

//HACK(hellow554): remove this when #4694 is implemented
#[allow(clippy::cognitive_complexity)]
fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option<Span> {
if_chain! {
if let ExprKind::Block(ref block, _) = e.kind;
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ impl Types {
/// The parameter `is_local` distinguishes the context of the type; types from
/// local bindings should only be checked for the `BORROWED_BOX` lint.
#[allow(clippy::too_many_lines)]
#[allow(clippy::cognitive_complexity)]
fn check_ty(&mut self, cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool) {
if hir_ty.span.from_expansion() {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "cognitive_complexity",
group: "complexity",
group: "nursery",
desc: "functions that should be split up into multiple functions",
deprecation: None,
module: "cognitive_complexity",
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/collapsible_else_if.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#![allow(clippy::assertions_on_constants)]

#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/collapsible_else_if.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#![allow(clippy::assertions_on_constants)]

#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/collapsible_if.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#![allow(clippy::assertions_on_constants)]

#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/collapsible_if.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#![allow(clippy::assertions_on_constants)]

#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/debug_assert_with_mut_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
#![warn(clippy::debug_assert_with_mut_call)]
#![allow(clippy::cognitive_complexity, clippy::redundant_closure_call)]
#![allow(clippy::redundant_closure_call)]

struct S;

Expand Down
1 change: 0 additions & 1 deletion tests/ui/for_loop_fixable.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl Unrelated {
clippy::linkedlist,
clippy::shadow_unrelated,
clippy::unnecessary_mut_passed,
clippy::cognitive_complexity,
clippy::similar_names
)]
#[allow(clippy::many_single_char_names, unused_variables)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/for_loop_fixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl Unrelated {
clippy::linkedlist,
clippy::shadow_unrelated,
clippy::unnecessary_mut_passed,
clippy::cognitive_complexity,
clippy::similar_names
)]
#[allow(clippy::many_single_char_names, unused_variables)]
Expand Down
40 changes: 20 additions & 20 deletions tests/ui/for_loop_fixable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this range is empty so this for loop will never run
--> $DIR/for_loop_fixable.rs:39:14
--> $DIR/for_loop_fixable.rs:38:14
|
LL | for i in 10..0 {
| ^^^^^
Expand All @@ -11,7 +11,7 @@ LL | for i in (0..10).rev() {
| ^^^^^^^^^^^^^

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: it is more concise to loop over containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:332:18
--> $DIR/for_loop_fixable.rs:331:18
|
LL | for _ in r.into_iter() {}
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `r`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/for_loop_unfixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
clippy::linkedlist,
clippy::shadow_unrelated,
clippy::unnecessary_mut_passed,
clippy::cognitive_complexity,
clippy::similar_names,
unused,
dead_code
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/for_loop_unfixable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0425]: cannot find function `f` in this scope
--> $DIR/for_loop_unfixable.rs:37:12
--> $DIR/for_loop_unfixable.rs:36:12
|
LL | if f(&vec[i], &vec[i]) {
| ^ help: a local variable with a similar name exists: `i`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/if_same_then_else2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![warn(clippy::if_same_then_else)]
#![allow(
clippy::blacklisted_name,
clippy::cognitive_complexity,
clippy::collapsible_if,
clippy::ifs_same_cond,
clippy::needless_return
Expand Down
Loading

0 comments on commit 7bfdee5

Please sign in to comment.