migrate: UnknownTool error to SessionDiagnostic

This commit is contained in:
Rejyr 2022-08-19 15:50:38 -04:00
parent ee8c31e64d
commit d197c1eb5b
4 changed files with 30 additions and 16 deletions

View File

@ -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

View File

@ -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<()>,
}

View File

@ -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::{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 @@ pub(crate) fn push(
}
&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;
}

View File

@ -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 @@
mod context;
mod early;
mod enum_intrinsics_non_enums;
mod errors;
mod expect;
pub mod hidden_unicode_codepoints;
mod internal;