about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md2
-rw-r--r--clippy_lints/src/assign_ops.rs2
-rw-r--r--clippy_lints/src/cognitive_complexity.rs (renamed from clippy_lints/src/cyclomatic_complexity.rs)40
-rw-r--r--clippy_lints/src/lib.rs9
-rw-r--r--clippy_lints/src/methods/mod.rs2
-rw-r--r--clippy_lints/src/utils/attrs.rs6
-rw-r--r--clippy_lints/src/utils/conf.rs25
-rw-r--r--tests/ui-toml/conf_deprecated_key/clippy.toml6
-rw-r--r--tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs4
-rw-r--r--tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr4
-rw-r--r--tests/ui-toml/good_toml_no_false_negatives/clippy.toml3
-rw-r--r--tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs3
-rw-r--r--tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr2
-rw-r--r--tests/ui/cognitive_complexity.rs (renamed from tests/ui/cyclomatic_complexity.rs)44
-rw-r--r--tests/ui/cognitive_complexity.stderr (renamed from tests/ui/cyclomatic_complexity.stderr)82
-rw-r--r--tests/ui/cognitive_complexity_attr_used.rs (renamed from tests/ui/cyclomatic_complexity_attr_used.rs)4
-rw-r--r--tests/ui/cognitive_complexity_attr_used.stderr (renamed from tests/ui/cyclomatic_complexity_attr_used.stderr)6
-rw-r--r--tests/ui/collapsible_if.fixed2
-rw-r--r--tests/ui/collapsible_if.rs2
-rw-r--r--tests/ui/for_loop.rs2
-rw-r--r--tests/ui/if_same_then_else.rs2
-rw-r--r--tests/ui/match_same_arms.rs2
-rw-r--r--tests/ui/rename.rs1
-rw-r--r--tests/ui/rename.stderr24
-rw-r--r--tests/ui/renamed_builtin_attr.rs2
-rw-r--r--tests/ui/renamed_builtin_attr.stderr8
-rw-r--r--tests/ui/unknown_attribute.rs2
-rw-r--r--tests/ui/while_loop.rs2
29 files changed, 175 insertions, 120 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d57e99db5ab..b05fa25fb1b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -798,11 +798,11 @@ All notable changes to this project will be documented in this file.
 [`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan
 [`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
 [`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
+[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
 [`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
 [`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
 [`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
 [`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
-[`cyclomatic_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cyclomatic_complexity
 [`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
 [`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
 [`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
diff --git a/README.md b/README.md
index 98365d228d0..7f8757e6cd2 100644
--- a/README.md
+++ b/README.md
@@ -131,7 +131,7 @@ Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml
 
 ```toml
 blacklisted-names = ["toto", "tata", "titi"]
-cyclomatic-complexity-threshold = 30
+cognitive-complexity-threshold = 30
 ```
 
 See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which lints can be configured and the
diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs
index d0c72ba92c0..b24e0cdfced 100644
--- a/clippy_lints/src/assign_ops.rs
+++ b/clippy_lints/src/assign_ops.rs
@@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
             },
             hir::ExprKind::Assign(assignee, e) => {
                 if let hir::ExprKind::Binary(op, l, r) = &e.node {
-                    #[allow(clippy::cyclomatic_complexity)]
+                    #[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);
diff --git a/clippy_lints/src/cyclomatic_complexity.rs b/clippy_lints/src/cognitive_complexity.rs
index fa046d8bb7b..d44784843e7 100644
--- a/clippy_lints/src/cyclomatic_complexity.rs
+++ b/clippy_lints/src/cognitive_complexity.rs
@@ -1,4 +1,4 @@
-//! calculate cyclomatic complexity and warn about overly complex functions
+//! calculate cognitive complexity and warn about overly complex functions
 
 use rustc::cfg::CFG;
 use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
@@ -12,25 +12,25 @@ use syntax::source_map::Span;
 use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
 
 declare_clippy_lint! {
-    /// **What it does:** Checks for methods with high cyclomatic complexity.
+    /// **What it does:** Checks for methods with high cognitive complexity.
     ///
-    /// **Why is this bad?** Methods of high cyclomatic complexity tend to be badly
-    /// readable. Also LLVM will usually optimize small methods better.
+    /// **Why is this bad?** Methods of high cognitive complexity tend to be hard to
+    /// both read and maintain. Also LLVM will tend to optimize small methods better.
     ///
     /// **Known problems:** Sometimes it's hard to find a way to reduce the
     /// complexity.
     ///
     /// **Example:** No. You'll see it when you get the warning.
-    pub CYCLOMATIC_COMPLEXITY,
+    pub COGNITIVE_COMPLEXITY,
     complexity,
     "functions that should be split up into multiple functions"
 }
 
-pub struct CyclomaticComplexity {
+pub struct CognitiveComplexity {
     limit: LimitStack,
 }
 
-impl CyclomaticComplexity {
+impl CognitiveComplexity {
     pub fn new(limit: u64) -> Self {
         Self {
             limit: LimitStack::new(limit),
@@ -38,17 +38,17 @@ impl CyclomaticComplexity {
     }
 }
 
-impl LintPass for CyclomaticComplexity {
+impl LintPass for CognitiveComplexity {
     fn get_lints(&self) -> LintArray {
-        lint_array!(CYCLOMATIC_COMPLEXITY)
+        lint_array!(COGNITIVE_COMPLEXITY)
     }
 
     fn name(&self) -> &'static str {
-        "CyclomaticComplexity"
+        "CognitiveComplexity"
     }
 }
 
-impl CyclomaticComplexity {
+impl CognitiveComplexity {
     fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {
         if in_macro(span) {
             return;
@@ -105,9 +105,9 @@ impl CyclomaticComplexity {
             if rust_cc > self.limit.limit() {
                 span_help_and_lint(
                     cx,
-                    CYCLOMATIC_COMPLEXITY,
+                    COGNITIVE_COMPLEXITY,
                     span,
-                    &format!("the function has a cyclomatic complexity of {}", rust_cc),
+                    &format!("the function has a cognitive complexity of {}", rust_cc),
                     "you could split it up into multiple smaller functions",
                 );
             }
@@ -115,7 +115,7 @@ impl CyclomaticComplexity {
     }
 }
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CyclomaticComplexity {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
     fn check_fn(
         &mut self,
         cx: &LateContext<'a, 'tcx>,
@@ -132,10 +132,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CyclomaticComplexity {
     }
 
     fn enter_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) {
-        self.limit.push_attrs(cx.sess(), attrs, "cyclomatic_complexity");
+        self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity");
     }
     fn exit_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) {
-        self.limit.pop_attrs(cx.sess(), attrs, "cyclomatic_complexity");
+        self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
     }
 }
 
@@ -201,7 +201,7 @@ fn report_cc_bug(
 ) {
     span_bug!(
         span,
-        "Clippy encountered a bug calculating cyclomatic complexity: cc = {}, arms = {}, \
+        "Clippy encountered a bug calculating cognitive complexity: cc = {}, arms = {}, \
          div = {}, shorts = {}, returns = {}. Please file a bug report.",
         cc,
         narms,
@@ -222,12 +222,12 @@ fn report_cc_bug(
     span: Span,
     id: HirId,
 ) {
-    if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
+    if !is_allowed(cx, COGNITIVE_COMPLEXITY, id) {
         cx.sess().span_note_without_error(
             span,
             &format!(
-                "Clippy encountered a bug calculating cyclomatic complexity \
-                 (hide this message with `#[allow(cyclomatic_complexity)]`): \
+                "Clippy encountered a bug calculating cognitive complexity \
+                 (hide this message with `#[allow(cognitive_complexity)]`): \
                  cc = {}, arms = {}, div = {}, shorts = {}, returns = {}. \
                  Please file a bug report.",
                 cc, narms, div, shorts, returns
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index ae24ef54c27..06d6a508701 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -152,11 +152,11 @@ pub mod block_in_if_condition;
 pub mod booleans;
 pub mod bytecount;
 pub mod cargo_common_metadata;
+pub mod cognitive_complexity;
 pub mod collapsible_if;
 pub mod const_static_lifetime;
 pub mod copies;
 pub mod copy_iterator;
-pub mod cyclomatic_complexity;
 pub mod dbg_macro;
 pub mod default_trait_access;
 pub mod derive;
@@ -478,7 +478,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
     reg.register_late_lint_pass(box temporary_assignment::Pass);
     reg.register_late_lint_pass(box transmute::Transmute);
     reg.register_late_lint_pass(
-        box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
+        box cognitive_complexity::CognitiveComplexity::new(conf.cognitive_complexity_threshold)
     );
     reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
     reg.register_early_lint_pass(box misc_early::MiscEarly);
@@ -666,11 +666,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
         booleans::LOGIC_BUG,
         booleans::NONMINIMAL_BOOL,
         bytecount::NAIVE_BYTECOUNT,
+        cognitive_complexity::COGNITIVE_COMPLEXITY,
         collapsible_if::COLLAPSIBLE_IF,
         const_static_lifetime::CONST_STATIC_LIFETIME,
         copies::IFS_SAME_COND,
         copies::IF_SAME_THEN_ELSE,
-        cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
         derive::DERIVE_HASH_XOR_EQ,
         double_comparison::DOUBLE_COMPARISONS,
         double_parens::DOUBLE_PARENS,
@@ -962,7 +962,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
         assign_ops::MISREFACTORED_ASSIGN_OP,
         attrs::DEPRECATED_CFG_ATTR,
         booleans::NONMINIMAL_BOOL,
-        cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
+        cognitive_complexity::COGNITIVE_COMPLEXITY,
         double_comparison::DOUBLE_COMPARISONS,
         double_parens::DOUBLE_PARENS,
         duration_subsec::DURATION_SUBSEC,
@@ -1131,6 +1131,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
 pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
     ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
     ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
+    ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity");
 }
 
 // only exists to let the dogfood integration test works.
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 5ffdced712b..685e83c4d70 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -821,7 +821,7 @@ impl LintPass for Pass {
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
-    #[allow(clippy::cyclomatic_complexity)]
+    #[allow(clippy::cognitive_complexity)]
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
         if in_macro(expr.span) {
             return;
diff --git a/clippy_lints/src/utils/attrs.rs b/clippy_lints/src/utils/attrs.rs
index db086a58e5c..fbd36ba71de 100644
--- a/clippy_lints/src/utils/attrs.rs
+++ b/clippy_lints/src/utils/attrs.rs
@@ -15,7 +15,11 @@ pub enum DeprecationStatus {
 
 pub const BUILTIN_ATTRIBUTES: &[(&str, DeprecationStatus)] = &[
     ("author", DeprecationStatus::None),
-    ("cyclomatic_complexity", DeprecationStatus::None),
+    ("cognitive_complexity", DeprecationStatus::None),
+    (
+        "cyclomatic_complexity",
+        DeprecationStatus::Replaced("cognitive_complexity"),
+    ),
     ("dump", DeprecationStatus::None),
 ];
 
diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs
index ff802dbb3a8..9efaeeb2e37 100644
--- a/clippy_lints/src/utils/conf.rs
+++ b/clippy_lints/src/utils/conf.rs
@@ -110,8 +110,10 @@ macro_rules! define_Conf {
 define_Conf! {
     /// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about
     (blacklisted_names, "blacklisted_names", ["foo", "bar", "baz", "quux"] => Vec<String>),
-    /// Lint: CYCLOMATIC_COMPLEXITY. The maximum cyclomatic complexity a function can have
-    (cyclomatic_complexity_threshold, "cyclomatic_complexity_threshold", 25 => u64),
+    /// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have
+    (cognitive_complexity_threshold, "cognitive_complexity_threshold", 25 => u64),
+    /// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
+    (cyclomatic_complexity_threshold, "cyclomatic_complexity_threshold", None => Option<u64>),
     /// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
     (doc_valid_idents, "doc_valid_idents", [
         "KiB", "MiB", "GiB", "TiB", "PiB", "EiB",
@@ -227,13 +229,24 @@ pub fn read(path: Option<&path::Path>) -> (Conf, Vec<Error>) {
 
     assert!(ERRORS.lock().expect("no threading -> mutex always safe").is_empty());
     match toml::from_str(&file) {
-        Ok(toml) => (
-            toml,
-            ERRORS.lock().expect("no threading -> mutex always safe").split_off(0),
-        ),
+        Ok(toml) => {
+            let mut errors = ERRORS.lock().expect("no threading -> mutex always safe").split_off(0);
+
+            let toml_ref: &Conf = &toml;
+
+            let cyc_field: Option<u64> = toml_ref.cyclomatic_complexity_threshold;
+
+            if cyc_field.is_some() {
+                let cyc_err = "found deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead.".to_string();
+                errors.push(Error::Toml(cyc_err));
+            }
+
+            (toml, errors)
+        },
         Err(e) => {
             let mut errors = ERRORS.lock().expect("no threading -> mutex always safe").split_off(0);
             errors.push(Error::Toml(e.to_string()));
+
             default(errors)
         },
     }
diff --git a/tests/ui-toml/conf_deprecated_key/clippy.toml b/tests/ui-toml/conf_deprecated_key/clippy.toml
new file mode 100644
index 00000000000..ac47b195042
--- /dev/null
+++ b/tests/ui-toml/conf_deprecated_key/clippy.toml
@@ -0,0 +1,6 @@
+# that one is an error
+cyclomatic-complexity-threshold = 42
+
+# that one is white-listed
+[third-party]
+clippy-feature = "nightly"
diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs
new file mode 100644
index 00000000000..2577c1eef92
--- /dev/null
+++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs
@@ -0,0 +1,4 @@
+// error-pattern: error reading Clippy's configuration file: found deprecated field
+// `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead.
+
+fn main() {}
diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr
new file mode 100644
index 00000000000..34267c0daf7
--- /dev/null
+++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr
@@ -0,0 +1,4 @@
+error: error reading Clippy's configuration file `$DIR/clippy.toml`: found deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead.
+
+error: aborting due to previous error
+
diff --git a/tests/ui-toml/good_toml_no_false_negatives/clippy.toml b/tests/ui-toml/good_toml_no_false_negatives/clippy.toml
new file mode 100644
index 00000000000..a1dd6b2f081
--- /dev/null
+++ b/tests/ui-toml/good_toml_no_false_negatives/clippy.toml
@@ -0,0 +1,3 @@
+# that one is white-listed
+[third-party]
+clippy-feature = "nightly"
diff --git a/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs b/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs
new file mode 100644
index 00000000000..270b9c5c43c
--- /dev/null
+++ b/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs
@@ -0,0 +1,3 @@
+// error-pattern: should give absolutely no error
+
+fn main() {}
diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
index ec2ac20684b..cdb1576b677 100644
--- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
@@ -1,4 +1,4 @@
-error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `third-party`
+error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `third-party`
 
 error: aborting due to previous error
 
diff --git a/tests/ui/cyclomatic_complexity.rs b/tests/ui/cognitive_complexity.rs
index d552ef50ff0..4e4016e78c2 100644
--- a/tests/ui/cyclomatic_complexity.rs
+++ b/tests/ui/cognitive_complexity.rs
@@ -1,5 +1,5 @@
 #![allow(clippy::all)]
-#![warn(clippy::cyclomatic_complexity)]
+#![warn(clippy::cognitive_complexity)]
 #![allow(unused)]
 
 #[rustfmt::skip]
@@ -87,7 +87,7 @@ fn main() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn kaboom() {
     let n = 0;
     'a: for i in 0..20 {
@@ -133,17 +133,17 @@ fn bloo() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn lots_of_short_circuits() -> bool {
     true && false && true && false && true && false && true
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn lots_of_short_circuits2() -> bool {
     true || false || true || false || true || false || true
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn baa() {
     let x = || match 99 {
         0 => 0,
@@ -161,7 +161,7 @@ fn baa() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn bar() {
     match 99 {
         0 => println!("hi"),
@@ -170,8 +170,8 @@ fn bar() {
 }
 
 #[test]
-#[clippy::cyclomatic_complexity = "0"]
-/// Tests are usually complex but simple at the same time. `clippy::cyclomatic_complexity` used to
+#[clippy::cognitive_complexity = "0"]
+/// Tests are usually complex but simple at the same time. `clippy::cognitive_complexity` used to
 /// give lots of false-positives in tests.
 fn dont_warn_on_tests() {
     match 99 {
@@ -180,7 +180,7 @@ fn dont_warn_on_tests() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn barr() {
     match 99 {
         0 => println!("hi"),
@@ -190,7 +190,7 @@ fn barr() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn barr2() {
     match 99 {
         0 => println!("hi"),
@@ -206,7 +206,7 @@ fn barr2() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn barrr() {
     match 99 {
         0 => println!("hi"),
@@ -216,7 +216,7 @@ fn barrr() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn barrr2() {
     match 99 {
         0 => println!("hi"),
@@ -232,7 +232,7 @@ fn barrr2() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn barrrr() {
     match 99 {
         0 => println!("hi"),
@@ -242,7 +242,7 @@ fn barrrr() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn barrrr2() {
     match 99 {
         0 => println!("hi"),
@@ -258,7 +258,7 @@ fn barrrr2() {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn cake() {
     if 4 == 5 {
         println!("yea");
@@ -268,7 +268,7 @@ fn cake() {
     println!("whee");
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 pub fn read_file(input_path: &str) -> String {
     use std::fs::File;
     use std::io::{Read, Write};
@@ -299,20 +299,20 @@ pub fn read_file(input_path: &str) -> String {
 
 enum Void {}
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn void(void: Void) {
     if true {
         match void {}
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn mcarton_sees_all() {
     panic!("meh");
     panic!("möh");
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn try() -> Result<i32, &'static str> {
     match 5 {
         5 => Ok(5),
@@ -320,7 +320,7 @@ fn try() -> Result<i32, &'static str> {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn try_again() -> Result<i32, &'static str> {
     let _ = try!(Ok(42));
     let _ = try!(Ok(43));
@@ -336,7 +336,7 @@ fn try_again() -> Result<i32, &'static str> {
     }
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn early() -> Result<i32, &'static str> {
     return Ok(5);
     return Ok(5);
@@ -350,7 +350,7 @@ fn early() -> Result<i32, &'static str> {
 }
 
 #[rustfmt::skip]
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn early_ret() -> i32 {
     let a = if true { 42 } else { return 0; };
     let a = if a < 99 { 42 } else { return 0; };
diff --git a/tests/ui/cyclomatic_complexity.stderr b/tests/ui/cognitive_complexity.stderr
index 944bba6e488..168653b9711 100644
--- a/tests/ui/cyclomatic_complexity.stderr
+++ b/tests/ui/cognitive_complexity.stderr
@@ -1,5 +1,5 @@
-error: the function has a cyclomatic complexity of 28
-  --> $DIR/cyclomatic_complexity.rs:6:1
+error: the function has a cognitive complexity of 28
+  --> $DIR/cognitive_complexity.rs:6:1
    |
 LL | / fn main() {
 LL | |     if true {
@@ -10,11 +10,11 @@ LL | |     }
 LL | | }
    | |_^
    |
-   = note: `-D clippy::cyclomatic-complexity` implied by `-D warnings`
+   = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 7
-  --> $DIR/cyclomatic_complexity.rs:91:1
+error: the function has a cognitive complexity of 7
+  --> $DIR/cognitive_complexity.rs:91:1
    |
 LL | / fn kaboom() {
 LL | |     let n = 0;
@@ -27,8 +27,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 1
-  --> $DIR/cyclomatic_complexity.rs:137:1
+error: the function has a cognitive complexity of 1
+  --> $DIR/cognitive_complexity.rs:137:1
    |
 LL | / fn lots_of_short_circuits() -> bool {
 LL | |     true && false && true && false && true && false && true
@@ -37,8 +37,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 1
-  --> $DIR/cyclomatic_complexity.rs:142:1
+error: the function has a cognitive complexity of 1
+  --> $DIR/cognitive_complexity.rs:142:1
    |
 LL | / fn lots_of_short_circuits2() -> bool {
 LL | |     true || false || true || false || true || false || true
@@ -47,8 +47,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:147:1
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:147:1
    |
 LL | / fn baa() {
 LL | |     let x = || match 99 {
@@ -61,8 +61,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:148:13
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:148:13
    |
 LL |       let x = || match 99 {
    |  _____________^
@@ -76,8 +76,8 @@ LL | |     };
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:165:1
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:165:1
    |
 LL | / fn bar() {
 LL | |     match 99 {
@@ -89,8 +89,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:184:1
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:184:1
    |
 LL | / fn barr() {
 LL | |     match 99 {
@@ -103,8 +103,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 3
-  --> $DIR/cyclomatic_complexity.rs:194:1
+error: the function has a cognitive complexity of 3
+  --> $DIR/cognitive_complexity.rs:194:1
    |
 LL | / fn barr2() {
 LL | |     match 99 {
@@ -117,8 +117,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:210:1
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:210:1
    |
 LL | / fn barrr() {
 LL | |     match 99 {
@@ -131,8 +131,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 3
-  --> $DIR/cyclomatic_complexity.rs:220:1
+error: the function has a cognitive complexity of 3
+  --> $DIR/cognitive_complexity.rs:220:1
    |
 LL | / fn barrr2() {
 LL | |     match 99 {
@@ -145,8 +145,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:236:1
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:236:1
    |
 LL | / fn barrrr() {
 LL | |     match 99 {
@@ -159,8 +159,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 3
-  --> $DIR/cyclomatic_complexity.rs:246:1
+error: the function has a cognitive complexity of 3
+  --> $DIR/cognitive_complexity.rs:246:1
    |
 LL | / fn barrrr2() {
 LL | |     match 99 {
@@ -173,8 +173,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 2
-  --> $DIR/cyclomatic_complexity.rs:262:1
+error: the function has a cognitive complexity of 2
+  --> $DIR/cognitive_complexity.rs:262:1
    |
 LL | / fn cake() {
 LL | |     if 4 == 5 {
@@ -187,8 +187,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 4
-  --> $DIR/cyclomatic_complexity.rs:272:1
+error: the function has a cognitive complexity of 4
+  --> $DIR/cognitive_complexity.rs:272:1
    |
 LL | / pub fn read_file(input_path: &str) -> String {
 LL | |     use std::fs::File;
@@ -201,8 +201,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 1
-  --> $DIR/cyclomatic_complexity.rs:303:1
+error: the function has a cognitive complexity of 1
+  --> $DIR/cognitive_complexity.rs:303:1
    |
 LL | / fn void(void: Void) {
 LL | |     if true {
@@ -213,8 +213,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 1
-  --> $DIR/cyclomatic_complexity.rs:316:1
+error: the function has a cognitive complexity of 1
+  --> $DIR/cognitive_complexity.rs:316:1
    |
 LL | / fn try() -> Result<i32, &'static str> {
 LL | |     match 5 {
@@ -226,8 +226,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 1
-  --> $DIR/cyclomatic_complexity.rs:324:1
+error: the function has a cognitive complexity of 1
+  --> $DIR/cognitive_complexity.rs:324:1
    |
 LL | / fn try_again() -> Result<i32, &'static str> {
 LL | |     let _ = try!(Ok(42));
@@ -240,8 +240,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 1
-  --> $DIR/cyclomatic_complexity.rs:340:1
+error: the function has a cognitive complexity of 1
+  --> $DIR/cognitive_complexity.rs:340:1
    |
 LL | / fn early() -> Result<i32, &'static str> {
 LL | |     return Ok(5);
@@ -254,8 +254,8 @@ LL | | }
    |
    = help: you could split it up into multiple smaller functions
 
-error: the function has a cyclomatic complexity of 8
-  --> $DIR/cyclomatic_complexity.rs:354:1
+error: the function has a cognitive complexity of 8
+  --> $DIR/cognitive_complexity.rs:354:1
    |
 LL | / fn early_ret() -> i32 {
 LL | |     let a = if true { 42 } else { return 0; };
diff --git a/tests/ui/cyclomatic_complexity_attr_used.rs b/tests/ui/cognitive_complexity_attr_used.rs
index 8b5028557d9..403eff566ed 100644
--- a/tests/ui/cyclomatic_complexity_attr_used.rs
+++ b/tests/ui/cognitive_complexity_attr_used.rs
@@ -1,11 +1,11 @@
-#![warn(clippy::cyclomatic_complexity)]
+#![warn(clippy::cognitive_complexity)]
 #![warn(unused)]
 
 fn main() {
     kaboom();
 }
 
-#[clippy::cyclomatic_complexity = "0"]
+#[clippy::cognitive_complexity = "0"]
 fn kaboom() {
     if 42 == 43 {
         panic!();
diff --git a/tests/ui/cyclomatic_complexity_attr_used.stderr b/tests/ui/cognitive_complexity_attr_used.stderr
index 7b732119774..2cf41506f56 100644
--- a/tests/ui/cyclomatic_complexity_attr_used.stderr
+++ b/tests/ui/cognitive_complexity_attr_used.stderr
@@ -1,5 +1,5 @@
-error: the function has a cyclomatic complexity of 3
-  --> $DIR/cyclomatic_complexity_attr_used.rs:9:1
+error: the function has a cognitive complexity of 3
+  --> $DIR/cognitive_complexity_attr_used.rs:9:1
    |
 LL | / fn kaboom() {
 LL | |     if 42 == 43 {
@@ -10,7 +10,7 @@ LL | |     }
 LL | | }
    | |_^
    |
-   = note: `-D clippy::cyclomatic-complexity` implied by `-D warnings`
+   = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
    = help: you could split it up into multiple smaller functions
 
 error: aborting due to previous error
diff --git a/tests/ui/collapsible_if.fixed b/tests/ui/collapsible_if.fixed
index 3c7de56406e..69570c515b6 100644
--- a/tests/ui/collapsible_if.fixed
+++ b/tests/ui/collapsible_if.fixed
@@ -1,5 +1,5 @@
 // run-rustfix
-#![allow(clippy::cyclomatic_complexity, clippy::assertions_on_constants)]
+#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
 
 #[rustfmt::skip]
 #[warn(clippy::collapsible_if)]
diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs
index e46d7537577..5dac42a3dd9 100644
--- a/tests/ui/collapsible_if.rs
+++ b/tests/ui/collapsible_if.rs
@@ -1,5 +1,5 @@
 // run-rustfix
-#![allow(clippy::cyclomatic_complexity, clippy::assertions_on_constants)]
+#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
 
 #[rustfmt::skip]
 #[warn(clippy::collapsible_if)]
diff --git a/tests/ui/for_loop.rs b/tests/ui/for_loop.rs
index f73bb41a9bb..ce8de074577 100644
--- a/tests/ui/for_loop.rs
+++ b/tests/ui/for_loop.rs
@@ -29,7 +29,7 @@ impl Unrelated {
     clippy::linkedlist,
     clippy::shadow_unrelated,
     clippy::unnecessary_mut_passed,
-    clippy::cyclomatic_complexity,
+    clippy::cognitive_complexity,
     clippy::similar_names
 )]
 #[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)]
diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs
index eef2ef14117..71f228c32bd 100644
--- a/tests/ui/if_same_then_else.rs
+++ b/tests/ui/if_same_then_else.rs
@@ -2,7 +2,7 @@
 #![allow(
     clippy::blacklisted_name,
     clippy::collapsible_if,
-    clippy::cyclomatic_complexity,
+    clippy::cognitive_complexity,
     clippy::eq_op,
     clippy::needless_return,
     clippy::never_loop,
diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs
index a1f15c0268b..8a7588f2e7f 100644
--- a/tests/ui/match_same_arms.rs
+++ b/tests/ui/match_same_arms.rs
@@ -1,7 +1,7 @@
 #![allow(
     clippy::blacklisted_name,
     clippy::collapsible_if,
-    clippy::cyclomatic_complexity,
+    clippy::cognitive_complexity,
     clippy::eq_op,
     clippy::needless_continue,
     clippy::needless_return,
diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs
index bd916fa7196..b1846a1096c 100644
--- a/tests/ui/rename.rs
+++ b/tests/ui/rename.rs
@@ -1,4 +1,5 @@
 #![allow(stutter)]
+#![warn(clippy::cyclomatic_complexity)]
 
 #[warn(clippy::stutter)]
 fn main() {}
diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr
index 7864e2a1fca..ac850b60d97 100644
--- a/tests/ui/rename.stderr
+++ b/tests/ui/rename.stderr
@@ -6,16 +6,22 @@ LL | #![allow(stutter)]
    |
    = note: `-D unknown-lints` implied by `-D warnings`
 
+error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
+  --> $DIR/rename.rs:2:9
+   |
+LL | #![warn(clippy::cyclomatic_complexity)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
+   |
+   = note: `-D renamed-and-removed-lints` implied by `-D warnings`
+
 error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
-  --> $DIR/rename.rs:3:8
+  --> $DIR/rename.rs:4:8
    |
 LL | #[warn(clippy::stutter)]
    |        ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
-   |
-   = note: `-D renamed-and-removed-lints` implied by `-D warnings`
 
 error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
-  --> $DIR/rename.rs:6:8
+  --> $DIR/rename.rs:7:8
    |
 LL | #[warn(clippy::new_without_default_derive)]
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default`
@@ -26,11 +32,11 @@ error: unknown lint: `stutter`
 LL | #![allow(stutter)]
    |          ^^^^^^^
 
-error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
-  --> $DIR/rename.rs:3:8
+error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
+  --> $DIR/rename.rs:2:9
    |
-LL | #[warn(clippy::stutter)]
-   |        ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
+LL | #![warn(clippy::cyclomatic_complexity)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
 
-error: aborting due to 5 previous errors
+error: aborting due to 6 previous errors
 
diff --git a/tests/ui/renamed_builtin_attr.rs b/tests/ui/renamed_builtin_attr.rs
new file mode 100644
index 00000000000..fdb425363e8
--- /dev/null
+++ b/tests/ui/renamed_builtin_attr.rs
@@ -0,0 +1,2 @@
+#[clippy::cyclomatic_complexity = "1"]
+fn main() {}
diff --git a/tests/ui/renamed_builtin_attr.stderr b/tests/ui/renamed_builtin_attr.stderr
new file mode 100644
index 00000000000..cf6cccd3688
--- /dev/null
+++ b/tests/ui/renamed_builtin_attr.stderr
@@ -0,0 +1,8 @@
+error: Usage of deprecated attribute
+  --> $DIR/renamed_builtin_attr.rs:1:11
+   |
+LL | #[clippy::cyclomatic_complexity = "1"]
+   |           ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/unknown_attribute.rs b/tests/ui/unknown_attribute.rs
index 8d695692863..e993e63f8ed 100644
--- a/tests/ui/unknown_attribute.rs
+++ b/tests/ui/unknown_attribute.rs
@@ -1,3 +1,3 @@
 #[clippy::unknown]
-#[clippy::cyclomatic_complexity = "1"]
+#[clippy::cognitive_complexity = "1"]
 fn main() {}
diff --git a/tests/ui/while_loop.rs b/tests/ui/while_loop.rs
index 8c3bf1cc674..d6921578721 100644
--- a/tests/ui/while_loop.rs
+++ b/tests/ui/while_loop.rs
@@ -1,5 +1,5 @@
 #![warn(clippy::while_let_loop, clippy::empty_loop, clippy::while_let_on_iterator)]
-#![allow(dead_code, clippy::never_loop, unused, clippy::cyclomatic_complexity)]
+#![allow(dead_code, clippy::never_loop, unused, clippy::cognitive_complexity)]
 
 fn main() {
     let y = Some(true);