diff options
| author | blyxyas <blyxyas@gmail.com> | 2024-05-27 13:58:33 +0200 |
|---|---|---|
| committer | blyxyas <blyxyas@gmail.com> | 2024-10-19 16:19:44 +0200 |
| commit | edc65776274d14fc7f7f93de66ac3b2d15bbbc37 (patch) | |
| tree | 5a2394d344ef75755b183288b2359ab16aca8b69 /compiler/rustc_lint/src/levels.rs | |
| parent | b4da0585959ec8b2c111bc9f8fd0e34e78c7f260 (diff) | |
| download | rust-edc65776274d14fc7f7f93de66ac3b2d15bbbc37.tar.gz rust-edc65776274d14fc7f7f93de66ac3b2d15bbbc37.zip | |
Change lints_to_emit to lints_that_actually_run
Diffstat (limited to 'compiler/rustc_lint/src/levels.rs')
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 7ee8618bc55..527fc117351 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -1,6 +1,6 @@ use rustc_ast_pretty::pprust; -use rustc_data_structures::{fx::FxIndexMap, sync::Lrc}; -use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan}; +use rustc_data_structures::{fx::FxIndexMap, fx::FxIndexSet, sync::Lrc}; +use rustc_errors::{Diag, LintDiagnostic, MultiSpan}; use rustc_feature::{Features, GateIssue}; use rustc_hir::HirId; use rustc_hir::intravisit::{self, Visitor}; @@ -120,7 +120,7 @@ impl LintLevelSets { /// (and not allowed in the crate) and CLI lints. The returned value is a tuple /// of 1. The lints that will emit (or at least, should run), and 2. /// The lints that are allowed at the crate level and will not emit. -pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<String>)> { +pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(FxIndexSet<String>, FxIndexSet<String>)> { let mut visitor = LintLevelMinimum::new(tcx); visitor.process_opts(); tcx.hir().walk_attributes(&mut visitor); @@ -131,18 +131,18 @@ pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<Str for group in lint_groups { let binding = group.0.to_lowercase(); let group_name = name_without_tool(&binding).to_string(); - if visitor.lints_to_emit.contains(&group_name) { + if visitor.lints_that_actually_run.contains(&group_name) { for lint in group.1 { - visitor.lints_to_emit.push(name_without_tool(&lint.to_string()).to_string()); + visitor.lints_that_actually_run.insert(name_without_tool(&lint.to_string()).to_string()); } } else if visitor.lints_allowed.contains(&group_name) { for lint in &group.1 { - visitor.lints_allowed.push(name_without_tool(&lint.to_string()).to_string()); + visitor.lints_allowed.insert(name_without_tool(&lint.to_string()).to_string()); } } } - Lrc::new((visitor.lints_to_emit, visitor.lints_allowed)) + Lrc::new((visitor.lints_that_actually_run, visitor.lints_allowed)) } #[instrument(level = "trace", skip(tcx), ret)] @@ -339,26 +339,30 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> { struct LintLevelMinimum<'tcx> { tcx: TyCtxt<'tcx>, /// The actual list of detected lints. - lints_to_emit: Vec<String>, - lints_allowed: Vec<String>, + lints_that_actually_run: FxIndexSet<String>, + lints_allowed: FxIndexSet<String>, } impl<'tcx> LintLevelMinimum<'tcx> { pub fn new(tcx: TyCtxt<'tcx>) -> Self { + let mut lints_that_actually_run = FxIndexSet::default(); + lints_that_actually_run.reserve(230); + let mut lints_allowed = FxIndexSet::default(); + lints_allowed.reserve(100); Self { tcx, // That magic number is the current number of lints + some more for possible future lints - lints_to_emit: Vec::with_capacity(230), - lints_allowed: Vec::with_capacity(100), + lints_that_actually_run, + lints_allowed, } } fn process_opts(&mut self) { for (lint, level) in &self.tcx.sess.opts.lint_opts { if *level == Level::Allow { - self.lints_allowed.push(lint.clone()); + self.lints_allowed.insert(lint.clone()); } else { - self.lints_to_emit.push(lint.to_string()); + self.lints_that_actually_run.insert(lint.to_string()); } } } @@ -383,13 +387,13 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> { // If it's a tool lint (e.g. clippy::my_clippy_lint) if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list { if meta_item.path.segments.len() == 1 { - self.lints_to_emit.push( + self.lints_that_actually_run.insert( // SAFETY: Lint attributes can only have literals meta_list.ident().unwrap().name.as_str().to_string(), ); } else { - self.lints_to_emit - .push(meta_item.path.segments[1].ident.name.as_str().to_string()); + self.lints_that_actually_run + .insert(meta_item.path.segments[1].ident.name.as_str().to_string()); } } } @@ -401,10 +405,10 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> { // If it's a tool lint (e.g. clippy::my_clippy_lint) if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list { if meta_item.path.segments.len() == 1 { - self.lints_allowed.push(meta_list.name_or_empty().as_str().to_string()) + self.lints_allowed.insert(meta_list.name_or_empty().as_str().to_string()); } else { self.lints_allowed - .push(meta_item.path.segments[1].ident.name.as_str().to_string()); + .insert(meta_item.path.segments[1].ident.name.as_str().to_string()); } } } |
