Skip to content

Commit edc6577

Browse files
committed
Change lints_to_emit to lints_that_actually_run
1 parent b4da058 commit edc6577

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

compiler/rustc_lint/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
373373
store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
374374

375375
// Filter unused lints
376-
let (lints_to_emit, lints_allowed) = &**tcx.lints_that_can_emit(());
377-
// let lints_to_emit = &lints_that_can_emit.0;
376+
let (lints_that_actually_run, lints_allowed) = &**tcx.lints_that_can_emit(());
377+
// let lints_that_actually_run = &lints_that_can_emit.0;
378378
// let lints_allowed = &lints_that_can_emit.1;
379379

380380
// Now, we'll filtered passes in a way that discards any lint that won't trigger.
@@ -386,7 +386,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
386386
let pass = LintPass::get_lints(pass);
387387
pass.iter().any(|&lint| {
388388
let lint_name = name_without_tool(&lint.name.to_lowercase()).to_string();
389-
lints_to_emit.contains(&lint_name)
389+
lints_that_actually_run.contains(&lint_name)
390390
|| (!lints_allowed.contains(&lint_name)
391391
&& lint.default_level != crate::Level::Allow)
392392
})

compiler/rustc_lint/src/levels.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast_pretty::pprust;
2-
use rustc_data_structures::{fx::FxIndexMap, sync::Lrc};
3-
use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan};
2+
use rustc_data_structures::{fx::FxIndexMap, fx::FxIndexSet, sync::Lrc};
3+
use rustc_errors::{Diag, LintDiagnostic, MultiSpan};
44
use rustc_feature::{Features, GateIssue};
55
use rustc_hir::HirId;
66
use rustc_hir::intravisit::{self, Visitor};
@@ -120,7 +120,7 @@ impl LintLevelSets {
120120
/// (and not allowed in the crate) and CLI lints. The returned value is a tuple
121121
/// of 1. The lints that will emit (or at least, should run), and 2.
122122
/// The lints that are allowed at the crate level and will not emit.
123-
pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<String>)> {
123+
pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(FxIndexSet<String>, FxIndexSet<String>)> {
124124
let mut visitor = LintLevelMinimum::new(tcx);
125125
visitor.process_opts();
126126
tcx.hir().walk_attributes(&mut visitor);
@@ -131,18 +131,18 @@ pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<Str
131131
for group in lint_groups {
132132
let binding = group.0.to_lowercase();
133133
let group_name = name_without_tool(&binding).to_string();
134-
if visitor.lints_to_emit.contains(&group_name) {
134+
if visitor.lints_that_actually_run.contains(&group_name) {
135135
for lint in group.1 {
136-
visitor.lints_to_emit.push(name_without_tool(&lint.to_string()).to_string());
136+
visitor.lints_that_actually_run.insert(name_without_tool(&lint.to_string()).to_string());
137137
}
138138
} else if visitor.lints_allowed.contains(&group_name) {
139139
for lint in &group.1 {
140-
visitor.lints_allowed.push(name_without_tool(&lint.to_string()).to_string());
140+
visitor.lints_allowed.insert(name_without_tool(&lint.to_string()).to_string());
141141
}
142142
}
143143
}
144144

145-
Lrc::new((visitor.lints_to_emit, visitor.lints_allowed))
145+
Lrc::new((visitor.lints_that_actually_run, visitor.lints_allowed))
146146
}
147147

148148
#[instrument(level = "trace", skip(tcx), ret)]
@@ -339,26 +339,30 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
339339
struct LintLevelMinimum<'tcx> {
340340
tcx: TyCtxt<'tcx>,
341341
/// The actual list of detected lints.
342-
lints_to_emit: Vec<String>,
343-
lints_allowed: Vec<String>,
342+
lints_that_actually_run: FxIndexSet<String>,
343+
lints_allowed: FxIndexSet<String>,
344344
}
345345

346346
impl<'tcx> LintLevelMinimum<'tcx> {
347347
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
348+
let mut lints_that_actually_run = FxIndexSet::default();
349+
lints_that_actually_run.reserve(230);
350+
let mut lints_allowed = FxIndexSet::default();
351+
lints_allowed.reserve(100);
348352
Self {
349353
tcx,
350354
// That magic number is the current number of lints + some more for possible future lints
351-
lints_to_emit: Vec::with_capacity(230),
352-
lints_allowed: Vec::with_capacity(100),
355+
lints_that_actually_run,
356+
lints_allowed,
353357
}
354358
}
355359

356360
fn process_opts(&mut self) {
357361
for (lint, level) in &self.tcx.sess.opts.lint_opts {
358362
if *level == Level::Allow {
359-
self.lints_allowed.push(lint.clone());
363+
self.lints_allowed.insert(lint.clone());
360364
} else {
361-
self.lints_to_emit.push(lint.to_string());
365+
self.lints_that_actually_run.insert(lint.to_string());
362366
}
363367
}
364368
}
@@ -383,13 +387,13 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
383387
// If it's a tool lint (e.g. clippy::my_clippy_lint)
384388
if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
385389
if meta_item.path.segments.len() == 1 {
386-
self.lints_to_emit.push(
390+
self.lints_that_actually_run.insert(
387391
// SAFETY: Lint attributes can only have literals
388392
meta_list.ident().unwrap().name.as_str().to_string(),
389393
);
390394
} else {
391-
self.lints_to_emit
392-
.push(meta_item.path.segments[1].ident.name.as_str().to_string());
395+
self.lints_that_actually_run
396+
.insert(meta_item.path.segments[1].ident.name.as_str().to_string());
393397
}
394398
}
395399
}
@@ -401,10 +405,10 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
401405
// If it's a tool lint (e.g. clippy::my_clippy_lint)
402406
if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
403407
if meta_item.path.segments.len() == 1 {
404-
self.lints_allowed.push(meta_list.name_or_empty().as_str().to_string())
408+
self.lints_allowed.insert(meta_list.name_or_empty().as_str().to_string());
405409
} else {
406410
self.lints_allowed
407-
.push(meta_item.path.segments[1].ident.name.as_str().to_string());
411+
.insert(meta_item.path.segments[1].ident.name.as_str().to_string());
408412
}
409413
}
410414
}

compiler/rustc_lint/src/shadowed_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ declare_lint! {
6464
};
6565
}
6666

67-
#[derive(Copy, Clone)]
67+
#[derive(Copy, Clone, Default)]
6868
pub(crate) struct ShadowedIntoIter;
6969

7070
impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]);

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ rustc_queries! {
422422
desc { "computing `#[expect]`ed lints in this crate" }
423423
}
424424

425-
query lints_that_can_emit(_: ()) -> &'tcx Lrc<(Vec<String>, Vec<String>)> {
425+
query lints_that_can_emit(_: ()) -> &'tcx Lrc<(FxIndexSet<String>, FxIndexSet<String>)> {
426426
arena_cache
427427
desc { "Computing all lints that are explicitly enabled or with a default level greater than Allow" }
428428
}

0 commit comments

Comments
 (0)