Skip to content

Commit e376123

Browse files
committed
Deprecate cognitive_complexity lint
This also deprecates the `cyclomatic_complexity` lint which had been renamed into `cognitive_complexity` back in 2019.
1 parent 4ead403 commit e376123

30 files changed

+166
-1051
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6520,7 +6520,6 @@ Released 2018-09-13
65206520
[`check-incompatible-msrv-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-incompatible-msrv-in-tests
65216521
[`check-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-inconsistent-struct-field-initializers
65226522
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
6523-
[`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold
65246523
[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros
65256524
[`disallowed-methods`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-methods
65266525
[`disallowed-names`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-names

book/src/lint_configuration.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,6 @@ Whether to also run the listed lints on private items.
475475
* [`unnecessary_safety_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc)
476476

477477

478-
## `cognitive-complexity-threshold`
479-
The maximum cognitive complexity a function can have
480-
481-
**Default Value:** `25`
482-
483-
---
484-
**Affected lints:**
485-
* [`cognitive_complexity`](https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity)
486-
487-
488478
## `disallowed-macros`
489479
The list of disallowed macros, written as fully qualified paths.
490480

clippy_config/src/conf.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,6 @@ define_Conf! {
566566
/// Whether to also run the listed lints on private items.
567567
#[lints(missing_errors_doc, missing_panics_doc, missing_safety_doc, unnecessary_safety_doc)]
568568
check_private_items: bool = false,
569-
/// The maximum cognitive complexity a function can have
570-
#[lints(cognitive_complexity)]
571-
cognitive_complexity_threshold: u64 = 25,
572-
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
573-
///
574-
/// Use the Cognitive Complexity lint instead.
575-
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
576-
cyclomatic_complexity_threshold: u64 = 25,
577569
/// The list of disallowed macros, written as fully qualified paths.
578570
///
579571
/// **Fields:**

clippy_lints/src/cognitive_complexity.rs

Lines changed: 0 additions & 165 deletions
This file was deleted.

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
7878
crate::checked_conversions::CHECKED_CONVERSIONS_INFO,
7979
crate::cloned_ref_to_slice_refs::CLONED_REF_TO_SLICE_REFS_INFO,
8080
crate::coerce_container_to_any::COERCE_CONTAINER_TO_ANY_INFO,
81-
crate::cognitive_complexity::COGNITIVE_COMPLEXITY_INFO,
8281
crate::collapsible_if::COLLAPSIBLE_ELSE_IF_INFO,
8382
crate::collapsible_if::COLLAPSIBLE_IF_INFO,
8483
crate::collection_is_never_read::COLLECTION_IS_NEVER_READ_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ macro_rules! declare_with_version {
1616
declare_with_version! { DEPRECATED(DEPRECATED_VERSION) = [
1717
#[clippy::version = "1.30.0"]
1818
("clippy::assign_ops", "compound operators are harmless and linting on them is not in scope for clippy"),
19+
#[clippy::version = "1.90.0"]
20+
("clippy::cognitive_complexity", "`excessive_nesting` and `too_many_lines` lints allow for finer-grain controls"),
21+
#[clippy::version = "1.35.0"]
22+
("clippy::cyclomatic_complexity", "`excessive_nesting` and `too_many_lines` lints allow for finer-grain controls"),
1923
#[clippy::version = "pre 1.29.0"]
2024
("clippy::extend_from_slice", "`Vec::extend_from_slice` is no longer faster than `Vec::extend` due to specialization"),
2125
#[clippy::version = "1.86.0"]
@@ -69,8 +73,6 @@ declare_with_version! { RENAMED(RENAMED_VERSION) = [
6973
#[clippy::version = ""]
7074
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
7175
#[clippy::version = ""]
72-
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
73-
#[clippy::version = ""]
7476
("clippy::derive_hash_xor_eq", "clippy::derived_hash_with_manual_eq"),
7577
#[clippy::version = ""]
7678
("clippy::disallowed_method", "clippy::disallowed_methods"),

clippy_lints/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ mod cfg_not_test;
9696
mod checked_conversions;
9797
mod cloned_ref_to_slice_refs;
9898
mod coerce_container_to_any;
99-
mod cognitive_complexity;
10099
mod collapsible_if;
101100
mod collection_is_never_read;
102101
mod comparison_chain;
@@ -537,7 +536,6 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
537536
store.register_late_pass(|_| Box::<no_effect::NoEffect>::default());
538537
store.register_late_pass(|_| Box::new(temporary_assignment::TemporaryAssignment));
539538
store.register_late_pass(move |_| Box::new(transmute::Transmute::new(conf)));
540-
store.register_late_pass(move |_| Box::new(cognitive_complexity::CognitiveComplexity::new(conf)));
541539
store.register_late_pass(move |_| Box::new(escape::BoxedLocal::new(conf)));
542540
store.register_late_pass(move |_| Box::new(vec::UselessVec::new(conf)));
543541
store.register_late_pass(move |_| Box::new(panic_unimplemented::PanicUnimplemented::new(conf)));

tests/ui-toml/conf_deprecated_key/clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Expect errors from these deprecated configs
2-
cyclomatic-complexity-threshold = 2
32
blacklisted-names = [ "..", "wibble" ]
3+
lint-inconsistent-struct-field-initializers = true
44

55
# that one is white-listed
66
[third-party]
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
#![allow(clippy::uninlined_format_args)]
1+
//@error-in-other-file:
22

33
fn main() {}
4-
5-
#[warn(clippy::cognitive_complexity)]
6-
fn cognitive_complexity() {
7-
//~^ cognitive_complexity
8-
let x = vec![1, 2, 3];
9-
for i in x {
10-
if i == 1 {
11-
println!("{}", i);
12-
}
13-
}
14-
}
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
warning: error reading Clippy's configuration file: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
2-
--> $DIR/tests/ui-toml/conf_deprecated_key/clippy.toml:2:1
3-
|
4-
LL | cyclomatic-complexity-threshold = 2
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
71
warning: error reading Clippy's configuration file: deprecated field `blacklisted-names`. Please use `disallowed-names` instead
8-
--> $DIR/tests/ui-toml/conf_deprecated_key/clippy.toml:3:1
2+
--> $DIR/tests/ui-toml/conf_deprecated_key/clippy.toml:2:1
93
|
104
LL | blacklisted-names = [ "..", "wibble" ]
115
| ^^^^^^^^^^^^^^^^^
126

13-
error: the function has a cognitive complexity of (3/2)
14-
--> tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs:6:4
15-
|
16-
LL | fn cognitive_complexity() {
17-
| ^^^^^^^^^^^^^^^^^^^^
7+
warning: error reading Clippy's configuration file: deprecated field `lint-inconsistent-struct-field-initializers`. Please use `check-inconsistent-struct-field-initializers` instead
8+
--> $DIR/tests/ui-toml/conf_deprecated_key/clippy.toml:3:1
189
|
19-
= help: you could split it up into multiple smaller functions
20-
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
21-
= help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]`
10+
LL | lint-inconsistent-struct-field-initializers = true
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2212

23-
error: aborting due to 1 previous error; 2 warnings emitted
13+
warning: 2 warnings emitted
2414

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cognitive-complexity-threshold = 2
1+
disallowed-names = ["core::panic"]
22
# This is the deprecated name for the same key
3-
cyclomatic-complexity-threshold = 3
3+
blacklisted-names = ["core::panic"]
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error: error reading Clippy's configuration file: duplicate field `cognitive_complexity_threshold` (provided as `cyclomatic_complexity_threshold`)
1+
error: error reading Clippy's configuration file: duplicate field `disallowed_names` (provided as `blacklisted_names`)
22
--> $DIR/tests/ui-toml/duplicated_keys_deprecated/clippy.toml:3:1
33
|
4-
LL | cyclomatic-complexity-threshold = 3
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | blacklisted-names = ["core::panic"]
5+
| ^^^^^^^^^^^^^^^^^
66

7-
warning: error reading Clippy's configuration file: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
7+
warning: error reading Clippy's configuration file: deprecated field `blacklisted-names`. Please use `disallowed-names` instead
88
--> $DIR/tests/ui-toml/duplicated_keys_deprecated/clippy.toml:3:1
99
|
10-
LL | cyclomatic-complexity-threshold = 3
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | blacklisted-names = ["core::panic"]
11+
| ^^^^^^^^^^^^^^^^^
1212

1313
error: aborting due to 1 previous error; 1 warning emitted
1414

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This is the deprecated name for cognitive-complexity-threshold
2-
cyclomatic-complexity-threshold = 3
1+
# This is the deprecated name for disallowed-names
2+
blacklisted-names = ["core::panic"]
33
# Check we get duplication warning regardless of order
4-
cognitive-complexity-threshold = 4
4+
disallowed-names = ["core::panic"]
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error: error reading Clippy's configuration file: duplicate field `cognitive-complexity-threshold`
1+
error: error reading Clippy's configuration file: duplicate field `disallowed-names`
22
--> $DIR/tests/ui-toml/duplicated_keys_deprecated_2/clippy.toml:4:1
33
|
4-
LL | cognitive-complexity-threshold = 4
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | disallowed-names = ["core::panic"]
5+
| ^^^^^^^^^^^^^^^^
66

7-
warning: error reading Clippy's configuration file: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
7+
warning: error reading Clippy's configuration file: deprecated field `blacklisted-names`. Please use `disallowed-names` instead
88
--> $DIR/tests/ui-toml/duplicated_keys_deprecated_2/clippy.toml:2:1
99
|
10-
LL | cyclomatic-complexity-threshold = 3
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | blacklisted-names = ["core::panic"]
11+
| ^^^^^^^^^^^^^^^^^
1212

1313
error: aborting due to 1 previous error; 1 warning emitted
1414

tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
3434
check-incompatible-msrv-in-tests
3535
check-inconsistent-struct-field-initializers
3636
check-private-items
37-
cognitive-complexity-threshold
3837
disallowed-macros
3938
disallowed-methods
4039
disallowed-names
@@ -128,7 +127,6 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
128127
check-incompatible-msrv-in-tests
129128
check-inconsistent-struct-field-initializers
130129
check-private-items
131-
cognitive-complexity-threshold
132130
disallowed-macros
133131
disallowed-methods
134132
disallowed-names
@@ -222,7 +220,6 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
222220
check-incompatible-msrv-in-tests
223221
check-inconsistent-struct-field-initializers
224222
check-private-items
225-
cognitive-complexity-threshold
226223
disallowed-macros
227224
disallowed-methods
228225
disallowed-names

0 commit comments

Comments
 (0)