mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
refactor(rustc_lint): inline check_lint_name_cmdline
This commit is contained in:
parent
ecff1c012e
commit
cdbad43aba
@ -16,10 +16,6 @@
|
||||
|
||||
use self::TargetLint::*;
|
||||
|
||||
use crate::errors::{
|
||||
CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown,
|
||||
CheckNameUnknownTool, RequestedLevel, UnsupportedGroup,
|
||||
};
|
||||
use crate::levels::LintLevelsBuilder;
|
||||
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
|
||||
use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
||||
@ -330,58 +326,6 @@ impl LintStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks the validity of lint names derived from the command line.
|
||||
pub fn check_lint_name_cmdline(
|
||||
&self,
|
||||
sess: &Session,
|
||||
lint_name: &str,
|
||||
level: Level,
|
||||
registered_tools: &RegisteredTools,
|
||||
) {
|
||||
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
|
||||
if lint_name_only == crate::WARNINGS.name_lower() && matches!(level, Level::ForceWarn(_)) {
|
||||
sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
|
||||
return;
|
||||
}
|
||||
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
|
||||
CheckLintNameResult::Renamed(replace) => {
|
||||
sess.emit_warning(CheckNameRenamed {
|
||||
lint_name,
|
||||
replace: &replace,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::Removed(reason) => {
|
||||
sess.emit_warning(CheckNameRemoved {
|
||||
lint_name,
|
||||
reason: &reason,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::NoLint(suggestion) => {
|
||||
sess.emit_err(CheckNameUnknown {
|
||||
lint_name,
|
||||
suggestion,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
|
||||
sess.emit_warning(CheckNameDeprecated {
|
||||
lint_name,
|
||||
new_name: &new_name,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::NoTool => {
|
||||
sess.emit_err(CheckNameUnknownTool {
|
||||
tool_name: tool_name.unwrap(),
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
/// True if this symbol represents a lint group name.
|
||||
pub fn is_lint_group(&self, lint_name: Symbol) -> bool {
|
||||
debug!(
|
||||
@ -1402,14 +1346,3 @@ impl<'tcx> LayoutOfHelpers<'tcx> for LateContext<'tcx> {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option<Symbol>, &str) {
|
||||
match lint_name.split_once("::") {
|
||||
Some((tool_name, lint_name)) => {
|
||||
let tool_name = Symbol::intern(tool_name);
|
||||
|
||||
(Some(tool_name), lint_name)
|
||||
}
|
||||
None => (None, lint_name),
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
use crate::errors::{
|
||||
CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown,
|
||||
CheckNameUnknownTool, RequestedLevel, UnsupportedGroup,
|
||||
};
|
||||
use crate::{
|
||||
builtin::MISSING_DOCS,
|
||||
context::{CheckLintNameResult, LintStore},
|
||||
@ -552,12 +556,56 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||
|
||||
fn add_command_line(&mut self) {
|
||||
for &(ref lint_name, level) in &self.sess.opts.lint_opts {
|
||||
self.store.check_lint_name_cmdline(self.sess, &lint_name, level, self.registered_tools);
|
||||
// Checks the validity of lint names derived from the command line.
|
||||
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
|
||||
if lint_name_only == crate::WARNINGS.name_lower()
|
||||
&& matches!(level, Level::ForceWarn(_))
|
||||
{
|
||||
self.sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
|
||||
}
|
||||
match self.store.check_lint_name(lint_name_only, tool_name, self.registered_tools) {
|
||||
CheckLintNameResult::Renamed(replace) => {
|
||||
self.sess.emit_warning(CheckNameRenamed {
|
||||
lint_name,
|
||||
replace: &replace,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::Removed(reason) => {
|
||||
self.sess.emit_warning(CheckNameRemoved {
|
||||
lint_name,
|
||||
reason: &reason,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::NoLint(suggestion) => {
|
||||
self.sess.emit_err(CheckNameUnknown {
|
||||
lint_name,
|
||||
suggestion,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
|
||||
self.sess.emit_warning(CheckNameDeprecated {
|
||||
lint_name,
|
||||
new_name: &new_name,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::NoTool => {
|
||||
self.sess.emit_err(CheckNameUnknownTool {
|
||||
tool_name: tool_name.unwrap(),
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
let orig_level = level;
|
||||
let lint_flag_val = Symbol::intern(lint_name);
|
||||
|
||||
let Ok(ids) = self.store.find_lints(&lint_name) else {
|
||||
// errors handled in check_lint_name_cmdline above
|
||||
// errors already handled above
|
||||
continue;
|
||||
};
|
||||
for id in ids {
|
||||
@ -1092,3 +1140,14 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { shallow_lint_levels_on, lint_expectations, ..*providers };
|
||||
}
|
||||
|
||||
pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option<Symbol>, &str) {
|
||||
match lint_name.split_once("::") {
|
||||
Some((tool_name, lint_name)) => {
|
||||
let tool_name = Symbol::intern(tool_name);
|
||||
|
||||
(Some(tool_name), lint_name)
|
||||
}
|
||||
None => (None, lint_name),
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::context::parse_lint_and_tool_name;
|
||||
use crate::levels::parse_lint_and_tool_name;
|
||||
use rustc_span::{create_default_session_globals_then, Symbol};
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user