From 3773534f29f817c46f13f30e118d430225d3a299 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Sat, 19 Oct 2024 17:47:16 +0200 Subject: [PATCH] Move COGNITIVE_COMPLEXITY to use macro again --- clippy_lints/src/cognitive_complexity.rs | 55 +++++++++--------------- clippy_lints/src/ctfe.rs | 1 - clippy_lints/src/declare_clippy_lint.rs | 30 ++++++++----- 3 files changed, 41 insertions(+), 45 deletions(-) diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 91cb8b78ba8..477435236a5 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -8,44 +8,31 @@ use core::ops::ControlFlow; use rustc_ast::ast::Attribute; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, FnDecl}; -use rustc_lint::Level::Allow; -use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, sym}; -use crate::LintInfo; - -pub static COGNITIVE_COMPLEXITY: &Lint = &Lint { - name: &"clippy::COGNITIVE_COMPLEXITY", - default_level: Allow, - desc: "functions that should be split up into multiple functions", - edition_lint_opts: None, - report_in_external_macro: true, - future_incompatible: None, - is_externally_loaded: true, - crate_level_only: false, - eval_always: true, - ..Lint::default_fields_for_macro() -}; -pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo { - lint: &COGNITIVE_COMPLEXITY, - category: crate::LintCategory::Nursery, - explanation: r"### What it does -Checks for methods with high cognitive complexity. - -### 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 -You'll see it when you get the warning.", - version: Some("1.35.0"), - location: "clippy_lints/src/cognitive_complexity.rs#L47", -}; +declare_clippy_lint! { + /// ### What it does + /// Checks for methods with high cognitive complexity. + /// + /// ### 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 + /// You'll see it when you get the warning. + #[clippy::version = "1.35.0"] + pub COGNITIVE_COMPLEXITY, + nursery, + "functions that should be split up into multiple functions" + @eval_always = true +} pub struct CognitiveComplexity { limit: LimitStack, diff --git a/clippy_lints/src/ctfe.rs b/clippy_lints/src/ctfe.rs index 93d0ad789be..2fe37a64db6 100644 --- a/clippy_lints/src/ctfe.rs +++ b/clippy_lints/src/ctfe.rs @@ -8,7 +8,6 @@ use rustc_span::Span; /// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes). /// As Clippy deactivates codegen, this lint ensures that CTFE (used in hard errors) is still ran. -#[clippy::version = "1.82.0"] pub static CLIPPY_CTFE: &Lint = &Lint { name: &"clippy::CLIPPY_CTFE", default_level: Deny, diff --git a/clippy_lints/src/declare_clippy_lint.rs b/clippy_lints/src/declare_clippy_lint.rs index b1e39c70baa..a785a9d377c 100644 --- a/clippy_lints/src/declare_clippy_lint.rs +++ b/clippy_lints/src/declare_clippy_lint.rs @@ -9,6 +9,7 @@ macro_rules! declare_clippy_lint { $desc:literal, $version_expr:expr, $version_lit:literal + $(, $eval_always: literal)? ) => { rustc_session::declare_tool_lint! { $(#[doc = $lit])* @@ -17,6 +18,7 @@ macro_rules! declare_clippy_lint { $category, $desc, report_in_external_macro:true + $(, @eval_always = $eval_always)? } pub(crate) static ${concat($lint_name, _INFO)}: &'static crate::LintInfo = &crate::LintInfo { @@ -33,11 +35,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, restriction, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Allow, crate::LintCategory::Restriction, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; ( @@ -46,12 +49,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, style, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Warn, crate::LintCategory::Style, $desc, - Some($version), $version - + Some($version), $version $(, $eval_always)? } }; ( @@ -60,11 +63,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, correctness, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Deny, crate::LintCategory::Correctness, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; @@ -74,11 +78,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, perf, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Warn, crate::LintCategory::Perf, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; ( @@ -87,11 +92,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, complexity, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Warn, crate::LintCategory::Complexity, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; ( @@ -100,11 +106,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, suspicious, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Warn, crate::LintCategory::Suspicious, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; ( @@ -113,11 +120,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, nursery, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Allow, crate::LintCategory::Nursery, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; ( @@ -126,11 +134,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, pedantic, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Allow, crate::LintCategory::Pedantic, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } }; ( @@ -139,11 +148,12 @@ macro_rules! declare_clippy_lint { pub $lint_name:ident, cargo, $desc:literal + $(@eval_always = $eval_always: literal)? ) => { declare_clippy_lint! {@ $(#[doc = $lit])* pub $lint_name, Allow, crate::LintCategory::Cargo, $desc, - Some($version), $version + Some($version), $version $(, $eval_always)? } };