about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/errors.rs13
-rw-r--r--compiler/rustc_lint/src/levels.rs27
-rw-r--r--compiler/rustc_lint/src/lib.rs3
3 files changed, 27 insertions, 16 deletions
diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs
new file mode 100644
index 00000000000..3f4d856a1cc
--- /dev/null
+++ b/compiler/rustc_lint/src/errors.rs
@@ -0,0 +1,13 @@
+use rustc_macros::SessionDiagnostic;
+use rustc_span::Span;
+
+#[derive(SessionDiagnostic)]
+#[error(lint::unknown_tool, code = "E0710")]
+pub struct UnknownTool {
+    #[primary_span]
+    pub span: Option<Span>,
+    pub tool_name: String,
+    pub lint_name: String,
+    #[help]
+    pub is_nightly_build: Option<()>,
+}
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs
index 1cabb58bbeb..3db88b7ace4 100644
--- a/compiler/rustc_lint/src/levels.rs
+++ b/compiler/rustc_lint/src/levels.rs
@@ -1,3 +1,6 @@
+// #![deny(rustc::diagnostic_outside_of_impl)]
+// #![deny(rustc::untranslatable_diagnostic)]
+//
 use crate::context::{CheckLintNameResult, LintStore};
 use crate::late::unerased_lint_store;
 use rustc_ast as ast;
@@ -23,6 +26,8 @@ use rustc_span::symbol::{sym, Symbol};
 use rustc_span::{Span, DUMMY_SP};
 use tracing::debug;
 
+use crate::errors::UnknownTool;
+
 fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
     let store = unerased_lint_store(tcx);
     let levels =
@@ -485,22 +490,12 @@ impl<'s> LintLevelsBuilder<'s> {
                     }
 
                     &CheckLintNameResult::NoTool => {
-                        let mut err = struct_span_err!(
-                            sess,
-                            tool_ident.map_or(DUMMY_SP, |ident| ident.span),
-                            E0710,
-                            "unknown tool name `{}` found in scoped lint: `{}::{}`",
-                            tool_name.unwrap(),
-                            tool_name.unwrap(),
-                            pprust::path_to_string(&meta_item.path),
-                        );
-                        if sess.is_nightly_build() {
-                            err.help(&format!(
-                                "add `#![register_tool({})]` to the crate root",
-                                tool_name.unwrap()
-                            ));
-                        }
-                        err.emit();
+                        sess.emit_err(UnknownTool {
+                            span: tool_ident.map(|ident| ident.span),
+                            tool_name: tool_name.unwrap().to_string(),
+                            lint_name: pprust::path_to_string(&meta_item.path),
+                            is_nightly_build: sess.is_nightly_build().then_some(()),
+                        });
                         continue;
                     }
 
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index f087c624917..23fd5d5eea0 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -36,6 +36,8 @@
 #![feature(let_else)]
 #![feature(never_type)]
 #![recursion_limit = "256"]
+// #![deny(rustc::diagnostic_outside_of_impl)]
+// #![deny(rustc::untranslatable_diagnostic)]
 
 #[macro_use]
 extern crate rustc_middle;
@@ -47,6 +49,7 @@ pub mod builtin;
 mod context;
 mod early;
 mod enum_intrinsics_non_enums;
+mod errors;
 mod expect;
 pub mod hidden_unicode_codepoints;
 mod internal;