1
Fork 0

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 .label = this code causes undefined behavior when executed
lint_builtin_asm_labels = avoid using named labels in inline assembly 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::context::{CheckLintNameResult, LintStore};
use crate::late::unerased_lint_store; use crate::late::unerased_lint_store;
use rustc_ast as ast; use rustc_ast as ast;
@ -23,6 +26,8 @@ use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use tracing::debug; use tracing::debug;
use crate::errors::UnknownTool;
fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
let store = unerased_lint_store(tcx); let store = unerased_lint_store(tcx);
let levels = let levels =
@ -485,22 +490,12 @@ impl<'s> LintLevelsBuilder<'s> {
} }
&CheckLintNameResult::NoTool => { &CheckLintNameResult::NoTool => {
let mut err = struct_span_err!( sess.emit_err(UnknownTool {
sess, span: tool_ident.map(|ident| ident.span),
tool_ident.map_or(DUMMY_SP, |ident| ident.span), tool_name: tool_name.unwrap().to_string(),
E0710, lint_name: pprust::path_to_string(&meta_item.path),
"unknown tool name `{}` found in scoped lint: `{}::{}`", is_nightly_build: sess.is_nightly_build().then_some(()),
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();
continue; continue;
} }

View file

@ -36,6 +36,8 @@
#![feature(let_else)] #![feature(let_else)]
#![feature(never_type)] #![feature(never_type)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
// #![deny(rustc::diagnostic_outside_of_impl)]
// #![deny(rustc::untranslatable_diagnostic)]
#[macro_use] #[macro_use]
extern crate rustc_middle; extern crate rustc_middle;
@ -47,6 +49,7 @@ pub mod builtin;
mod context; mod context;
mod early; mod early;
mod enum_intrinsics_non_enums; mod enum_intrinsics_non_enums;
mod errors;
mod expect; mod expect;
pub mod hidden_unicode_codepoints; pub mod hidden_unicode_codepoints;
mod internal; mod internal;