diff options
| author | Eric Holk <ericholk@microsoft.com> | 2021-07-07 10:50:50 -0700 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2021-07-07 10:50:50 -0700 |
| commit | 4a83a93e9afd29e7494af3cc2a33c44ec32b0303 (patch) | |
| tree | ebbfeff4198dd4e2439078a5c771da62682ef98c | |
| parent | 5413d2e52981924bd42a5497ea4a0bf76f2a572f (diff) | |
| download | rust-4a83a93e9afd29e7494af3cc2a33c44ec32b0303.tar.gz rust-4a83a93e9afd29e7494af3cc2a33c44ec32b0303.zip | |
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.
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-register-unknown-lint-tool.stderr | 11 |
3 files changed, 25 insertions, 21 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 263ed83ed5a..b6ea89b5074 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -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) => { @@ -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 @@ -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 { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 30ee8c9b6ae..b603483414f 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -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( @@ -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); diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr new file mode 100644 index 00000000000..c9a2aff2137 --- /dev/null +++ b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr @@ -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`. |
