Skip to content

Commit 4a83a93

Browse files
committed
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.
1 parent 5413d2e commit 4a83a93

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

compiler/rustc_lint/src/context.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ impl LintStore {
344344
level: Level,
345345
crate_attrs: &[ast::Attribute],
346346
) {
347-
let (tool_name, lint_name) = parse_lint_and_tool_name(lint_name);
347+
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
348348

349-
let db = match self.check_lint_and_tool_name(sess, tool_name, lint_name, crate_attrs) {
349+
let db = match self.check_lint_name(sess, lint_name_only, tool_name, crate_attrs) {
350350
CheckLintNameResult::Ok(_) => None,
351351
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
352352
CheckLintNameResult::NoLint(suggestion) => {
@@ -408,22 +408,6 @@ impl LintStore {
408408
}
409409
}
410410

411-
pub fn check_lint_and_tool_name(
412-
&self,
413-
sess: &Session,
414-
tool_name: Option<Symbol>,
415-
lint_name: &str,
416-
crate_attrs: &[ast::Attribute],
417-
) -> CheckLintNameResult<'_> {
418-
if let Some(tool_name) = tool_name {
419-
if !is_known_lint_tool(tool_name, sess, crate_attrs) {
420-
return CheckLintNameResult::NoTool;
421-
}
422-
}
423-
424-
self.check_lint_name(lint_name, tool_name)
425-
}
426-
427411
/// Checks the name of a lint for its existence, and whether it was
428412
/// renamed or removed. Generates a DiagnosticBuilder containing a
429413
/// warning for renamed and removed lints. This is over both lint
@@ -433,9 +417,17 @@ impl LintStore {
433417
/// printing duplicate warnings.
434418
pub fn check_lint_name(
435419
&self,
420+
sess: &Session,
436421
lint_name: &str,
437422
tool_name: Option<Symbol>,
423+
crate_attrs: &[ast::Attribute],
438424
) -> CheckLintNameResult<'_> {
425+
if let Some(tool_name) = tool_name {
426+
if !is_known_lint_tool(tool_name, sess, crate_attrs) {
427+
return CheckLintNameResult::NoTool;
428+
}
429+
}
430+
439431
let complete_name = if let Some(tool_name) = tool_name {
440432
format!("{}::{}", tool_name, lint_name)
441433
} else {

compiler/rustc_lint/src/levels.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ impl<'s> LintLevelsBuilder<'s> {
328328
};
329329
let tool_name = tool_ident.map(|ident| ident.name);
330330
let name = pprust::path_to_string(&meta_item.path);
331-
let lint_result =
332-
store.check_lint_and_tool_name(sess, tool_name, &name, self.crate_attrs);
331+
let lint_result = store.check_lint_name(sess, &name, tool_name, self.crate_attrs);
333332
match &lint_result {
334333
CheckLintNameResult::Ok(ids) => {
335334
let src = LintLevelSource::Node(
@@ -477,7 +476,9 @@ impl<'s> LintLevelsBuilder<'s> {
477476
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
478477
// Ignore any errors or warnings that happen because the new name is inaccurate
479478
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
480-
if let CheckLintNameResult::Ok(ids) = store.check_lint_name(&new_name, None) {
479+
if let CheckLintNameResult::Ok(ids) =
480+
store.check_lint_name(sess, &new_name, None, self.crate_attrs)
481+
{
481482
let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason);
482483
for &id in ids {
483484
self.check_gated_lint(id, attr.span);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0602]: unknown lint tool: `unknown_tool`
2+
|
3+
= note: requested on the command line with `-A unknown_tool::foo`
4+
5+
error[E0602]: unknown lint tool: `unknown_tool`
6+
|
7+
= note: requested on the command line with `-A unknown_tool::foo`
8+
9+
error: aborting due to 2 previous errors
10+
11+
For more information about this error, try `rustc --explain E0602`.

0 commit comments

Comments
 (0)