Cleanup: unify lint name checking
This change merges `check_lint_and_tool_name` into `check_lint_name` in order to avoid having two very similar functions. Also adds the `.stderr` file back for the test case, since apparently it is still needed.
This commit is contained in:
parent
5413d2e529
commit
4a83a93e9a
3 changed files with 25 additions and 21 deletions
|
@ -344,9 +344,9 @@ impl LintStore {
|
||||||
level: Level,
|
level: Level,
|
||||||
crate_attrs: &[ast::Attribute],
|
crate_attrs: &[ast::Attribute],
|
||||||
) {
|
) {
|
||||||
let (tool_name, lint_name) = parse_lint_and_tool_name(lint_name);
|
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
|
||||||
|
|
||||||
let db = match self.check_lint_and_tool_name(sess, tool_name, lint_name, crate_attrs) {
|
let db = match self.check_lint_name(sess, lint_name_only, tool_name, crate_attrs) {
|
||||||
CheckLintNameResult::Ok(_) => None,
|
CheckLintNameResult::Ok(_) => None,
|
||||||
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
|
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
|
||||||
CheckLintNameResult::NoLint(suggestion) => {
|
CheckLintNameResult::NoLint(suggestion) => {
|
||||||
|
@ -408,22 +408,6 @@ impl LintStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_lint_and_tool_name(
|
|
||||||
&self,
|
|
||||||
sess: &Session,
|
|
||||||
tool_name: Option<Symbol>,
|
|
||||||
lint_name: &str,
|
|
||||||
crate_attrs: &[ast::Attribute],
|
|
||||||
) -> CheckLintNameResult<'_> {
|
|
||||||
if let Some(tool_name) = tool_name {
|
|
||||||
if !is_known_lint_tool(tool_name, sess, crate_attrs) {
|
|
||||||
return CheckLintNameResult::NoTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.check_lint_name(lint_name, tool_name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks the name of a lint for its existence, and whether it was
|
/// Checks the name of a lint for its existence, and whether it was
|
||||||
/// renamed or removed. Generates a DiagnosticBuilder containing a
|
/// renamed or removed. Generates a DiagnosticBuilder containing a
|
||||||
/// warning for renamed and removed lints. This is over both lint
|
/// warning for renamed and removed lints. This is over both lint
|
||||||
|
@ -433,9 +417,17 @@ impl LintStore {
|
||||||
/// printing duplicate warnings.
|
/// printing duplicate warnings.
|
||||||
pub fn check_lint_name(
|
pub fn check_lint_name(
|
||||||
&self,
|
&self,
|
||||||
|
sess: &Session,
|
||||||
lint_name: &str,
|
lint_name: &str,
|
||||||
tool_name: Option<Symbol>,
|
tool_name: Option<Symbol>,
|
||||||
|
crate_attrs: &[ast::Attribute],
|
||||||
) -> CheckLintNameResult<'_> {
|
) -> CheckLintNameResult<'_> {
|
||||||
|
if let Some(tool_name) = tool_name {
|
||||||
|
if !is_known_lint_tool(tool_name, sess, crate_attrs) {
|
||||||
|
return CheckLintNameResult::NoTool;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let complete_name = if let Some(tool_name) = tool_name {
|
let complete_name = if let Some(tool_name) = tool_name {
|
||||||
format!("{}::{}", tool_name, lint_name)
|
format!("{}::{}", tool_name, lint_name)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -328,8 +328,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
};
|
};
|
||||||
let tool_name = tool_ident.map(|ident| ident.name);
|
let tool_name = tool_ident.map(|ident| ident.name);
|
||||||
let name = pprust::path_to_string(&meta_item.path);
|
let name = pprust::path_to_string(&meta_item.path);
|
||||||
let lint_result =
|
let lint_result = store.check_lint_name(sess, &name, tool_name, self.crate_attrs);
|
||||||
store.check_lint_and_tool_name(sess, tool_name, &name, self.crate_attrs);
|
|
||||||
match &lint_result {
|
match &lint_result {
|
||||||
CheckLintNameResult::Ok(ids) => {
|
CheckLintNameResult::Ok(ids) => {
|
||||||
let src = LintLevelSource::Node(
|
let src = LintLevelSource::Node(
|
||||||
|
@ -477,7 +476,9 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
|
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
|
||||||
// Ignore any errors or warnings that happen because the new name is inaccurate
|
// Ignore any errors or warnings that happen because the new name is inaccurate
|
||||||
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
|
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
|
||||||
if let CheckLintNameResult::Ok(ids) = store.check_lint_name(&new_name, None) {
|
if let CheckLintNameResult::Ok(ids) =
|
||||||
|
store.check_lint_name(sess, &new_name, None, self.crate_attrs)
|
||||||
|
{
|
||||||
let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason);
|
let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason);
|
||||||
for &id in ids {
|
for &id in ids {
|
||||||
self.check_gated_lint(id, attr.span);
|
self.check_gated_lint(id, attr.span);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0602]: unknown lint tool: `unknown_tool`
|
||||||
|
|
|
||||||
|
= note: requested on the command line with `-A unknown_tool::foo`
|
||||||
|
|
||||||
|
error[E0602]: unknown lint tool: `unknown_tool`
|
||||||
|
|
|
||||||
|
= note: requested on the command line with `-A unknown_tool::foo`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0602`.
|
Loading…
Add table
Reference in a new issue