Change lints_to_emit to lints_that_actually_run
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user