Skip to content

Commit d197c1e

Browse files
committed
migrate: UnknownTool error to SessionDiagnostic
1 parent ee8c31e commit d197c1e

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,6 @@ lint_builtin_deref_nullptr = dereferencing a null pointer
393393
.label = this code causes undefined behavior when executed
394394
395395
lint_builtin_asm_labels = avoid using named labels in inline assembly
396+
397+
lint_unknown_tool = unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`
398+
.help = add `#![register_tool({$tool_name})]` to the crate root

compiler/rustc_lint/src/errors.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::Span;
3+
4+
#[derive(SessionDiagnostic)]
5+
#[error(lint::unknown_tool, code = "E0710")]
6+
pub struct UnknownTool {
7+
#[primary_span]
8+
pub span: Option<Span>,
9+
pub tool_name: String,
10+
pub lint_name: String,
11+
#[help]
12+
pub is_nightly_build: Option<()>,
13+
}

compiler/rustc_lint/src/levels.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// #![deny(rustc::diagnostic_outside_of_impl)]
2+
// #![deny(rustc::untranslatable_diagnostic)]
3+
//
14
use crate::context::{CheckLintNameResult, LintStore};
25
use crate::late::unerased_lint_store;
36
use rustc_ast as ast;
@@ -23,6 +26,8 @@ use rustc_span::symbol::{sym, Symbol};
2326
use rustc_span::{Span, DUMMY_SP};
2427
use tracing::debug;
2528

29+
use crate::errors::UnknownTool;
30+
2631
fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
2732
let store = unerased_lint_store(tcx);
2833
let levels =
@@ -485,22 +490,12 @@ impl<'s> LintLevelsBuilder<'s> {
485490
}
486491

487492
&CheckLintNameResult::NoTool => {
488-
let mut err = struct_span_err!(
489-
sess,
490-
tool_ident.map_or(DUMMY_SP, |ident| ident.span),
491-
E0710,
492-
"unknown tool name `{}` found in scoped lint: `{}::{}`",
493-
tool_name.unwrap(),
494-
tool_name.unwrap(),
495-
pprust::path_to_string(&meta_item.path),
496-
);
497-
if sess.is_nightly_build() {
498-
err.help(&format!(
499-
"add `#![register_tool({})]` to the crate root",
500-
tool_name.unwrap()
501-
));
502-
}
503-
err.emit();
493+
sess.emit_err(UnknownTool {
494+
span: tool_ident.map(|ident| ident.span),
495+
tool_name: tool_name.unwrap().to_string(),
496+
lint_name: pprust::path_to_string(&meta_item.path),
497+
is_nightly_build: sess.is_nightly_build().then_some(()),
498+
});
504499
continue;
505500
}
506501

compiler/rustc_lint/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#![feature(let_else)]
3737
#![feature(never_type)]
3838
#![recursion_limit = "256"]
39+
// #![deny(rustc::diagnostic_outside_of_impl)]
40+
// #![deny(rustc::untranslatable_diagnostic)]
3941

4042
#[macro_use]
4143
extern crate rustc_middle;
@@ -47,6 +49,7 @@ pub mod builtin;
4749
mod context;
4850
mod early;
4951
mod enum_intrinsics_non_enums;
52+
mod errors;
5053
mod expect;
5154
pub mod hidden_unicode_codepoints;
5255
mod internal;

0 commit comments

Comments
 (0)