diff --git a/compiler/rustc_error_messages/locales/en-US/lint.ftl b/compiler/rustc_error_messages/locales/en-US/lint.ftl index 97317114716..e0943323ade 100644 --- a/compiler/rustc_error_messages/locales/en-US/lint.ftl +++ b/compiler/rustc_error_messages/locales/en-US/lint.ftl @@ -393,3 +393,6 @@ lint_builtin_deref_nullptr = dereferencing a null pointer .label = this code causes undefined behavior when executed lint_builtin_asm_labels = avoid using named labels in inline assembly + +lint_unknown_tool = unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}` + .help = add `#![register_tool({$tool_name})]` to the crate root 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, + 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;