Move COGNITIVE_COMPLEXITY to use macro again

This commit is contained in:
blyxyas 2024-10-19 17:47:16 +02:00
parent ddad55f6c2
commit 1dcfa27144
5 changed files with 45 additions and 49 deletions

View File

@ -64,7 +64,7 @@ declare_lint! {
};
}
#[derive(Copy, Clone, Default)]
#[derive(Copy, Clone)]
pub(crate) struct ShadowedIntoIter;
impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]);

View File

@ -904,15 +904,15 @@ macro_rules! declare_tool_lint {
$(, @eval_always = $eval_always:literal)?
$(, @feature_gate = $gate:ident;)?
) => (
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @feature_gate = $gate;)?}
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @eval_always = $eval_always)? $(, @feature_gate = $gate;)?}
);
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
report_in_external_macro: $rep:expr
$(, @feature_gate = $gate:ident;)?
$(, @eval_always = $eval_always: literal)?
$(, @feature_gate = $gate:ident;)?
) => (
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @feature_gate = $gate;)?}
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @eval_always = $eval_always)? $(, @feature_gate = $gate;)?}
);
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,

View File

@ -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,

View File

@ -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,

View File

@ -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)?
}
};