Skip to content

Commit

Permalink
Rebase and merge
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Aug 30, 2024
1 parent 60fe9c2 commit 55019ea
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 46 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
builder.provider.expectations
}

pub fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
let store = unerased_lint_store(&tcx.sess);

let dont_need_to_run: FxIndexSet<LintId> = store
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ pub(crate) struct UnusedParens {
}

impl Default for UnusedParens {
pub(crate) fn default() -> Self {
fn default() -> Self {
Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() }
}
}
Expand Down
56 changes: 16 additions & 40 deletions src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,18 @@ use clippy_utils::source::{IntoSpan, SpanRangeExt};
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::visitors::for_each_expr_without_closures;
use clippy_utils::{get_async_fn_body, is_async_fn, LimitStack};
use rustc_lint::{Level::Allow, Lint};
use core::ops::ControlFlow;
use rustc_ast::ast::Attribute;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, Expr, ExprKind, FnDecl};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_lint::Level::Allow;
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId;
use rustc_span::{sym, Span};

use crate::LintInfo;

// 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"
// }

// Recursive expansion of declare_clippy_lint! macro
// ==================================================

#[doc = " ### What it does"]
#[doc = " Checks for methods with high cognitive complexity."]
#[doc = ""]
#[doc = " ### Why is this bad?"]
#[doc = " Methods of high cognitive complexity tend to be hard to"]
#[doc = " both read and maintain. Also LLVM will tend to optimize small methods better."]
#[doc = ""]
#[doc = " ### Known problems"]
#[doc = " Sometimes it\'s hard to find a way to reduce the"]
#[doc = " complexity."]
#[doc = ""]
#[doc = " ### Example"]
#[doc = " You\'ll see it when you get the warning."]
#[clippy::version = "1.35.0"]
pub static COGNITIVE_COMPLEXITY: &Lint = &Lint {
name: &"clippy::COGNITIVE_COMPLEXITY",
default_level: Allow,
Expand All @@ -68,7 +31,20 @@ pub static COGNITIVE_COMPLEXITY: &Lint = &Lint {
pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo {
lint: &COGNITIVE_COMPLEXITY,
category: crate::LintCategory::Nursery,
explanation: "### What it does\nChecks for methods with high cognitive complexity.\n\n### Why is this bad?\nMethods of high cognitive complexity tend to be hard to\nboth read and maintain. Also LLVM will tend to optimize small methods better.\n\n### Known problems\nSometimes it's hard to find a way to reduce the\ncomplexity.\n\n### Example\nYou'll see it when you get the warning.\n",
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: "#L0",
};

pub struct CognitiveComplexity {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern crate declare_clippy_lint;
mod utils;

pub mod ctfe; // VERY important lint (rust#125116)
mod declared_lints;
pub mod declared_lints;
pub mod deprecated_lints;

// begin lints modules, do not remove this comment, it’s used in `update_lints`
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/tests/ui/indexing_slicing_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ fn main() {
x[const { idx4() }];
// This should be linted, since `suppress-restriction-lint-in-const` default is false.
const { &ARR[idx()] };
// ~^ ERROR: indexing may panic
//~^ ERROR: indexing may panic
// This should be linted, since `suppress-restriction-lint-in-const` default is false.
const { &ARR[idx4()] };
// ~^ ERROR: indexing may panic
//~^ ERROR: indexing may panic

let y = &x;
// Ok, referencing shouldn't affect this lint. See the issue 6021
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/string_slice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

#![warn(clippy::string_slice)]
#[warn(clippy::string_slice)]
#[allow(clippy::no_effect)]

fn main() {
Expand Down

0 comments on commit 55019ea

Please sign in to comment.