mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Move COGNITIVE_COMPLEXITY to use macro again
This commit is contained in:
parent
ddad55f6c2
commit
1dcfa27144
@ -64,7 +64,7 @@ declare_lint! {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default)]
|
#[derive(Copy, Clone)]
|
||||||
pub(crate) struct ShadowedIntoIter;
|
pub(crate) struct ShadowedIntoIter;
|
||||||
|
|
||||||
impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]);
|
impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]);
|
||||||
|
@ -904,15 +904,15 @@ macro_rules! declare_tool_lint {
|
|||||||
$(, @eval_always = $eval_always:literal)?
|
$(, @eval_always = $eval_always:literal)?
|
||||||
$(, @feature_gate = $gate:ident;)?
|
$(, @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,
|
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
||||||
report_in_external_macro: $rep:expr
|
report_in_external_macro: $rep:expr
|
||||||
$(, @feature_gate = $gate:ident;)?
|
|
||||||
$(, @eval_always = $eval_always: literal)?
|
$(, @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,
|
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
||||||
|
@ -8,44 +8,31 @@ use core::ops::ControlFlow;
|
|||||||
use rustc_ast::ast::Attribute;
|
use rustc_ast::ast::Attribute;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{Body, Expr, ExprKind, FnDecl};
|
use rustc_hir::{Body, Expr, ExprKind, FnDecl};
|
||||||
use rustc_lint::Level::Allow;
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
|
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::{Span, sym};
|
use rustc_span::{Span, sym};
|
||||||
|
|
||||||
use crate::LintInfo;
|
declare_clippy_lint! {
|
||||||
|
/// ### What it does
|
||||||
pub static COGNITIVE_COMPLEXITY: &Lint = &Lint {
|
/// Checks for methods with high cognitive complexity.
|
||||||
name: &"clippy::COGNITIVE_COMPLEXITY",
|
///
|
||||||
default_level: Allow,
|
/// ### Why is this bad?
|
||||||
desc: "functions that should be split up into multiple functions",
|
/// Methods of high cognitive complexity tend to be hard to
|
||||||
edition_lint_opts: None,
|
/// both read and maintain. Also LLVM will tend to optimize small methods better.
|
||||||
report_in_external_macro: true,
|
///
|
||||||
future_incompatible: None,
|
/// ### Known problems
|
||||||
is_externally_loaded: true,
|
/// Sometimes it's hard to find a way to reduce the
|
||||||
crate_level_only: false,
|
/// complexity.
|
||||||
eval_always: true,
|
///
|
||||||
..Lint::default_fields_for_macro()
|
/// ### Example
|
||||||
};
|
/// You'll see it when you get the warning.
|
||||||
pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo {
|
#[clippy::version = "1.35.0"]
|
||||||
lint: &COGNITIVE_COMPLEXITY,
|
pub COGNITIVE_COMPLEXITY,
|
||||||
category: crate::LintCategory::Nursery,
|
nursery,
|
||||||
explanation: r"### What it does
|
"functions that should be split up into multiple functions"
|
||||||
Checks for methods with high cognitive complexity.
|
@eval_always = true
|
||||||
|
}
|
||||||
### 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",
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct CognitiveComplexity {
|
pub struct CognitiveComplexity {
|
||||||
limit: LimitStack,
|
limit: LimitStack,
|
||||||
|
@ -8,7 +8,6 @@ use rustc_span::Span;
|
|||||||
|
|
||||||
/// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes).
|
/// 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.
|
/// 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 {
|
pub static CLIPPY_CTFE: &Lint = &Lint {
|
||||||
name: &"clippy::CLIPPY_CTFE",
|
name: &"clippy::CLIPPY_CTFE",
|
||||||
default_level: Deny,
|
default_level: Deny,
|
||||||
|
@ -9,6 +9,7 @@ macro_rules! declare_clippy_lint {
|
|||||||
$desc:literal,
|
$desc:literal,
|
||||||
$version_expr:expr,
|
$version_expr:expr,
|
||||||
$version_lit:literal
|
$version_lit:literal
|
||||||
|
$(, $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
rustc_session::declare_tool_lint! {
|
rustc_session::declare_tool_lint! {
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
@ -17,6 +18,7 @@ macro_rules! declare_clippy_lint {
|
|||||||
$category,
|
$category,
|
||||||
$desc,
|
$desc,
|
||||||
report_in_external_macro:true
|
report_in_external_macro:true
|
||||||
|
$(, @eval_always = $eval_always)?
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) static ${concat($lint_name, _INFO)}: &'static crate::LintInfo = &crate::LintInfo {
|
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,
|
pub $lint_name:ident,
|
||||||
restriction,
|
restriction,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Allow, crate::LintCategory::Restriction, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
style,
|
style,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Warn, crate::LintCategory::Style, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
correctness,
|
correctness,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Deny, crate::LintCategory::Correctness, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
perf,
|
perf,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Warn, crate::LintCategory::Perf, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
complexity,
|
complexity,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Warn, crate::LintCategory::Complexity, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
suspicious,
|
suspicious,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Warn, crate::LintCategory::Suspicious, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
nursery,
|
nursery,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Allow, crate::LintCategory::Nursery, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
pedantic,
|
pedantic,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Allow, crate::LintCategory::Pedantic, $desc,
|
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,
|
pub $lint_name:ident,
|
||||||
cargo,
|
cargo,
|
||||||
$desc:literal
|
$desc:literal
|
||||||
|
$(@eval_always = $eval_always: literal)?
|
||||||
) => {
|
) => {
|
||||||
declare_clippy_lint! {@
|
declare_clippy_lint! {@
|
||||||
$(#[doc = $lit])*
|
$(#[doc = $lit])*
|
||||||
pub $lint_name, Allow, crate::LintCategory::Cargo, $desc,
|
pub $lint_name, Allow, crate::LintCategory::Cargo, $desc,
|
||||||
Some($version), $version
|
Some($version), $version $(, $eval_always)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user