about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2024-05-27 13:58:33 +0200
committerblyxyas <blyxyas@gmail.com>2024-10-19 16:19:44 +0200
commitedc65776274d14fc7f7f93de66ac3b2d15bbbc37 (patch)
tree5a2394d344ef75755b183288b2359ab16aca8b69
parentb4da0585959ec8b2c111bc9f8fd0e34e78c7f260 (diff)
downloadrust-edc65776274d14fc7f7f93de66ac3b2d15bbbc37.tar.gz
rust-edc65776274d14fc7f7f93de66ac3b2d15bbbc37.zip
Change lints_to_emit to lints_that_actually_run
-rw-r--r--compiler/rustc_lint/src/late.rs6
-rw-r--r--compiler/rustc_lint/src/levels.rs40
-rw-r--r--compiler/rustc_lint/src/shadowed_into_iter.rs2
-rw-r--r--compiler/rustc_middle/src/query/mod.rs2
4 files changed, 27 insertions, 23 deletions
diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs
index ccd06ba612b..c7187ee1b30 100644
--- a/compiler/rustc_lint/src/late.rs
+++ b/compiler/rustc_lint/src/late.rs
@@ -373,8 +373,8 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
             store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
 
         // Filter unused lints
-        let (lints_to_emit, lints_allowed) = &**tcx.lints_that_can_emit(());
-        // let lints_to_emit = &lints_that_can_emit.0;
+        let (lints_that_actually_run, lints_allowed) = &**tcx.lints_that_can_emit(());
+        // let lints_that_actually_run = &lints_that_can_emit.0;
         // let lints_allowed = &lints_that_can_emit.1;
 
         // 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>(
                 let pass = LintPass::get_lints(pass);
                 pass.iter().any(|&lint| {
                     let lint_name = name_without_tool(&lint.name.to_lowercase()).to_string();
-                    lints_to_emit.contains(&lint_name)
+                    lints_that_actually_run.contains(&lint_name)
                         || (!lints_allowed.contains(&lint_name)
                             && lint.default_level != crate::Level::Allow)
                 })
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());
                         }
                     }
                 }
diff --git a/compiler/rustc_lint/src/shadowed_into_iter.rs b/compiler/rustc_lint/src/shadowed_into_iter.rs
index a73904cd776..33a4ae60663 100644
--- a/compiler/rustc_lint/src/shadowed_into_iter.rs
+++ b/compiler/rustc_lint/src/shadowed_into_iter.rs
@@ -64,7 +64,7 @@ declare_lint! {
     };
 }
 
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Default)]
 pub(crate) struct ShadowedIntoIter;
 
 impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]);
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index e90c3a4c23d..b6cb11a2a2c 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -422,7 +422,7 @@ rustc_queries! {
         desc { "computing `#[expect]`ed lints in this crate" }
     }
 
-    query lints_that_can_emit(_: ()) -> &'tcx Lrc<(Vec<String>, Vec<String>)> {
+    query lints_that_can_emit(_: ()) -> &'tcx Lrc<(FxIndexSet<String>, FxIndexSet<String>)> {
         arena_cache
         desc { "Computing all lints that are explicitly enabled or with a default level greater than Allow" }
     }