Skip to content

Commit

Permalink
Cleanup: unify lint name checking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eholk committed Jul 7, 2021
1 parent 5413d2e commit 4a83a93
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
28 changes: 10 additions & 18 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ impl LintStore {
level: Level,
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::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
CheckLintNameResult::NoLint(suggestion) => {
Expand Down Expand Up @@ -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
/// renamed or removed. Generates a DiagnosticBuilder containing a
/// warning for renamed and removed lints. This is over both lint
Expand All @@ -433,9 +417,17 @@ impl LintStore {
/// printing duplicate warnings.
pub fn check_lint_name(
&self,
sess: &Session,
lint_name: &str,
tool_name: Option<Symbol>,
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;
}
}

let complete_name = if let Some(tool_name) = tool_name {
format!("{}::{}", tool_name, lint_name)
} else {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ impl<'s> LintLevelsBuilder<'s> {
};
let tool_name = tool_ident.map(|ident| ident.name);
let name = pprust::path_to_string(&meta_item.path);
let lint_result =
store.check_lint_and_tool_name(sess, tool_name, &name, self.crate_attrs);
let lint_result = store.check_lint_name(sess, &name, tool_name, self.crate_attrs);
match &lint_result {
CheckLintNameResult::Ok(ids) => {
let src = LintLevelSource::Node(
Expand Down Expand Up @@ -477,7 +476,9 @@ impl<'s> LintLevelsBuilder<'s> {
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
// 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.
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);
for &id in ids {
self.check_gated_lint(id, attr.span);
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/lint/command-line-register-unknown-lint-tool.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 4a83a93

Please sign in to comment.