Skip to content

Commit a9fa78c

Browse files
committed
EVERYTHING GREEN
1 parent 9bb2f00 commit a9fa78c

File tree

16 files changed

+193
-77
lines changed

16 files changed

+193
-77
lines changed

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
895895
tcx.ensure().check_mod_privacy(module);
896896
});
897897
});
898-
}
898+
} // { sess.time("mir_checking", || { tcx.hir().mir_for }) }
899899
);
900900

901901
// This check has to be run after all lints are done processing. We don't

compiler/rustc_lint/src/builtin.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//! If you define a new `LateLintPass`, you will also need to add it to the
2121
//! `late_lint_methods!` invocation in `lib.rs`.
2222
23+
use std::default::Default;
2324
use std::fmt::Write;
2425

2526
use ast::token::TokenKind;
@@ -73,12 +74,10 @@ use crate::{
7374
fluent_generated as fluent, EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level,
7475
LintContext,
7576
};
76-
77-
use std::default::Default;
78-
use std::fmt::Write;
77+
// use std::fmt::Write;
7978

8079
// hardwired lints from rustc_lint_defs
81-
pub use rustc_session::lint::builtin::*;
80+
// pub use rustc_session::lint::builtin::*;
8281

8382
declare_lint! {
8483
/// The `while_true` lint detects `while true { }`.

compiler/rustc_lint/src/late.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ use rustc_hir::def_id::{LocalDefId, LocalModDefId};
2424
use rustc_hir::{intravisit as hir_visit, HirId};
2525
use rustc_middle::hir::nested_filter;
2626
use rustc_middle::ty::{self, TyCtxt};
27+
use rustc_session::lint::builtin::HardwiredLints;
2728
use rustc_session::lint::LintPass;
2829
use rustc_session::Session;
2930
use rustc_span::Span;
3031
use tracing::debug;
3132

3233
use crate::passes::LateLintPassObject;
33-
use crate::{LateContext, LateLintPass, LintStore, LintId};
34+
use crate::{LateContext, LateLintPass, LintId, LintStore};
3435

3536
/// Extract the [`LintStore`] from [`Session`].
3637
///
@@ -378,12 +379,18 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
378379
.into_iter()
379380
.filter(|pass| {
380381
let lints = LintPass::get_lints(pass);
381-
lints.iter()
382-
.any(|lint|
383-
!lints_that_dont_need_to_run.contains(&LintId::of(lint)))
384-
}).collect();
382+
if lints.is_empty() {
383+
true
384+
} else {
385+
lints
386+
.iter()
387+
.any(|lint| !lints_that_dont_need_to_run.contains(&LintId::of(lint)))
388+
}
389+
})
390+
.collect();
385391

386392
filtered_passes.push(Box::new(builtin_lints));
393+
filtered_passes.push(Box::new(HardwiredLints));
387394

388395
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
389396
late_lint_mod_inner(tcx, module_def_id, context, pass);
@@ -438,14 +445,14 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
438445

439446
// dbg!(&lints_that_dont_need_to_run);
440447
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
441-
.into_iter()
442-
.filter(|pass|{
443-
let lints = LintPass::get_lints(pass);
444-
// dbg!(&lints);
445-
lints.iter()
446-
.any(|lint|
447-
!lints_that_dont_need_to_run.contains(&LintId::of(lint)))
448-
}).collect();
448+
.into_iter()
449+
.filter(|pass| {
450+
let lints = LintPass::get_lints(pass);
451+
!lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
452+
})
453+
.collect();
454+
455+
filtered_passes.push(Box::new(HardwiredLints));
449456

450457
// let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
451458
// .into_iter()
@@ -455,6 +462,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
455462
// .any(|lint|
456463
// !lints_that_dont_need_to_run.contains(&LintId::of(lint)))
457464
// }).collect();
465+
//
458466

459467
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
460468
late_lint_crate_inner(tcx, context, pass);

compiler/rustc_lint/src/levels.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_ast_pretty::pprust;
2-
use rustc_data_structures::{fx::FxIndexMap, fx::FxIndexSet};
2+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
33
use rustc_errors::{Diag, LintDiagnostic, MultiSpan};
44
use rustc_feature::{Features, GateIssue};
55
use rustc_hir::intravisit::{self, Visitor};
@@ -31,7 +31,7 @@ use crate::errors::{
3131
OverruledAttributeSub, RequestedLevel, UnknownToolInScopedLint, UnsupportedGroup,
3232
};
3333
use crate::fluent_generated as fluent;
34-
use crate::late::{unerased_lint_store, name_without_tool};
34+
use crate::late::{unerased_lint_store /*name_without_tool*/};
3535
use crate::lints::{
3636
DeprecatedLintName, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified,
3737
OverruledAttributeLint, RemovedLint, RemovedLintFromCommandLine, RenamedLint,
@@ -115,10 +115,7 @@ impl LintLevelSets {
115115
}
116116
}
117117

118-
pub fn lints_that_dont_need_to_run(
119-
tcx: TyCtxt<'_>,
120-
(): (),
121-
) -> FxIndexSet<LintId> {
118+
pub fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
122119
let store = unerased_lint_store(&tcx.sess);
123120

124121
let dont_need_to_run: FxIndexSet<LintId> = store
@@ -394,8 +391,14 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
394391

395392
for meta_list in meta_item_list {
396393
// Convert Path to String
397-
let Some(meta_item) = meta_list.meta_item() else {return};
398-
let ident: &str = &meta_item.path.segments.iter().map(|segment| segment.ident.as_str()).collect::<Vec<&str>>().join("::");
394+
let Some(meta_item) = meta_list.meta_item() else { return };
395+
let ident: &str = &meta_item
396+
.path
397+
.segments
398+
.iter()
399+
.map(|segment| segment.ident.as_str())
400+
.collect::<Vec<&str>>()
401+
.join("::");
399402
let Ok(lints) = store.find_lints(
400403
// SAFETY: Lint attributes can only have literals
401404
ident,
@@ -430,23 +433,25 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
430433
// self.dont_need_to_run.swap_remove(&lint);
431434
// }
432435
// }
433-
}
436+
}
434437
// We handle #![allow]s differently, as these remove checking rather than adding.
435438
} // Some(Level::Allow) if ast::AttrStyle::Inner == attribute.style => {
436-
// for meta_list in meta.meta_item_list().unwrap() {
437-
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
438-
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
439-
// if meta_item.path.segments.len() == 1 {
440-
// self.lints_allowed
441-
// .insert(meta_list.name_or_empty().as_str().to_string());
442-
// } else {
443-
// self.lints_allowed
444-
// .insert(meta_item.path.segments[1].ident.name.as_str().to_string());
445-
// }
446-
// }
447-
// }
448-
// }
449-
_ => { return; }
439+
// for meta_list in meta.meta_item_list().unwrap() {
440+
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
441+
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
442+
// if meta_item.path.segments.len() == 1 {
443+
// self.lints_allowed
444+
// .insert(meta_list.name_or_empty().as_str().to_string());
445+
// } else {
446+
// self.lints_allowed
447+
// .insert(meta_item.path.segments[1].ident.name.as_str().to_string());
448+
// }
449+
// }
450+
// }
451+
// }
452+
_ => {
453+
return;
454+
}
450455
}
451456
}
452457
}

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ late_lint_methods!(
194194
ForLoopsOverFallibles: ForLoopsOverFallibles,
195195
DerefIntoDynSupertrait: DerefIntoDynSupertrait,
196196
DropForgetUseless: DropForgetUseless,
197-
HardwiredLints: HardwiredLints,
198197
ImproperCTypesDeclarations: ImproperCTypesDeclarations,
199198
ImproperCTypesDefinitions: ImproperCTypesDefinitions,
200199
InvalidFromUtf8: InvalidFromUtf8,
@@ -272,6 +271,7 @@ fn register_builtins(store: &mut LintStore) {
272271
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
273272
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
274273
store.register_lints(&foreign_modules::get_lints());
274+
store.register_lints(&HardwiredLints::default().get_lints());
275275

276276
add_lint_group!(
277277
"nonstandard_style",

compiler/rustc_lint/src/passes.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ macro_rules! declare_late_lint_pass {
6868
// for all the `check_*` methods.
6969
late_lint_methods!(declare_late_lint_pass, []);
7070

71-
impl LateLintPass<'_> for HardwiredLints {}
71+
impl LateLintPass<'_> for HardwiredLints {
72+
fn check_fn(
73+
&mut self,
74+
_: &LateContext<'_>,
75+
_: rustc_hir::intravisit::FnKind<'_>,
76+
_: &'_ rustc_hir::FnDecl<'_>,
77+
_: &'_ rustc_hir::Body<'_>,
78+
_: rustc_span::Span,
79+
_: rustc_span::def_id::LocalDefId,
80+
) {
81+
}
82+
}
7283

7384
#[macro_export]
7485
macro_rules! expand_combined_late_lint_pass_method {

compiler/rustc_lint_defs/src/builtin.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use rustc_span::edition::Edition;
1212
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
1313

1414
declare_lint_pass! {
15-
/// Does nothing as a lint pass, but registers some `Lint`s
16-
/// that are used by other parts of the compiler.
1715
HardwiredLints => [
1816
// tidy-alphabetical-start
1917
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
@@ -403,7 +401,8 @@ declare_lint! {
403401
/// `panic!` or `unreachable!` macro instead in case the panic is intended.
404402
pub UNCONDITIONAL_PANIC,
405403
Deny,
406-
"operation will cause a panic at runtime"
404+
"operation will cause a panic at runtime",
405+
[loadbearing: true]
407406
}
408407

409408
declare_lint! {

compiler/rustc_session/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub struct Session {
186186
/// errors.
187187
pub ctfe_backtrace: Lock<CtfeBacktrace>,
188188

189+
// pub force_ctfe: bool,
189190
/// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
190191
/// const check, optionally with the relevant feature gate. We use this to
191192
/// warn about unleashing, but with a single diagnostic instead of dozens that

src/tools/clippy/clippy_lints/src/asm_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions};
55
use rustc_ast::{InlineAsm, Item, ItemKind};
6-
use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintPass, LintContext};
6+
use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext};
77
use rustc_session::declare_lint_pass;
88
use rustc_span::Span;
99
use rustc_target::asm::InlineAsmArch;

src/tools/clippy/clippy_lints/src/cognitive_complexity.rs

+57-19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use clippy_utils::source::{IntoSpan, SpanRangeExt};
44
use clippy_utils::ty::is_type_diagnostic_item;
55
use clippy_utils::visitors::for_each_expr_without_closures;
66
use clippy_utils::{get_async_fn_body, is_async_fn, LimitStack};
7+
use rustc_lint::{Level::Allow, Lint};
78
use core::ops::ControlFlow;
89
use rustc_ast::ast::Attribute;
910
use rustc_hir::intravisit::FnKind;
@@ -13,25 +14,62 @@ use rustc_session::impl_lint_pass;
1314
use rustc_span::def_id::LocalDefId;
1415
use rustc_span::{sym, Span};
1516

16-
declare_clippy_lint! {
17-
/// ### What it does
18-
/// Checks for methods with high cognitive complexity.
19-
///
20-
/// ### Why is this bad?
21-
/// Methods of high cognitive complexity tend to be hard to
22-
/// both read and maintain. Also LLVM will tend to optimize small methods better.
23-
///
24-
/// ### Known problems
25-
/// Sometimes it's hard to find a way to reduce the
26-
/// complexity.
27-
///
28-
/// ### Example
29-
/// You'll see it when you get the warning.
30-
#[clippy::version = "1.35.0"]
31-
pub COGNITIVE_COMPLEXITY,
32-
nursery,
33-
"functions that should be split up into multiple functions"
34-
}
17+
use crate::LintInfo;
18+
19+
// declare_clippy_lint! {
20+
// /// ### What it does
21+
// /// Checks for methods with high cognitive complexity.
22+
// ///
23+
// /// ### Why is this bad?
24+
// /// Methods of high cognitive complexity tend to be hard to
25+
// /// both read and maintain. Also LLVM will tend to optimize small methods better.
26+
// ///
27+
// /// ### Known problems
28+
// /// Sometimes it's hard to find a way to reduce the
29+
// /// complexity.
30+
// ///
31+
// /// ### Example
32+
// /// You'll see it when you get the warning.
33+
// #[clippy::version = "1.35.0"]
34+
// pub COGNITIVE_COMPLEXITY,
35+
// nursery,
36+
// "functions that should be split up into multiple functions"
37+
// }
38+
39+
// Recursive expansion of declare_clippy_lint! macro
40+
// ==================================================
41+
42+
#[doc = " ### What it does"]
43+
#[doc = " Checks for methods with high cognitive complexity."]
44+
#[doc = ""]
45+
#[doc = " ### Why is this bad?"]
46+
#[doc = " Methods of high cognitive complexity tend to be hard to"]
47+
#[doc = " both read and maintain. Also LLVM will tend to optimize small methods better."]
48+
#[doc = ""]
49+
#[doc = " ### Known problems"]
50+
#[doc = " Sometimes it\'s hard to find a way to reduce the"]
51+
#[doc = " complexity."]
52+
#[doc = ""]
53+
#[doc = " ### Example"]
54+
#[doc = " You\'ll see it when you get the warning."]
55+
#[clippy::version = "1.35.0"]
56+
pub static COGNITIVE_COMPLEXITY: &Lint = &Lint {
57+
name: &"clippy::COGNITIVE_COMPLEXITY",
58+
default_level: Allow,
59+
desc: "functions that should be split up into multiple functions",
60+
edition_lint_opts: None,
61+
report_in_external_macro: true,
62+
future_incompatible: None,
63+
is_externally_loaded: true,
64+
crate_level_only: false,
65+
loadbearing: true,
66+
..Lint::default_fields_for_macro()
67+
};
68+
pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo {
69+
lint: &COGNITIVE_COMPLEXITY,
70+
category: crate::LintCategory::Nursery,
71+
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",
72+
};
3573

3674
pub struct CognitiveComplexity {
3775
limit: LimitStack,

0 commit comments

Comments
 (0)