Rename DecorateLint as LintDiagnostic.

To match `derive(LintDiagnostic)`.
This commit is contained in:
Nicholas Nethercote 2024-03-08 12:03:51 +11:00
parent 541d7cc65c
commit e9f0d9be0e
16 changed files with 54 additions and 54 deletions

View File

@ -168,7 +168,7 @@ pub(super) fn lint<'tcx, 'mir, L>(
lint: &'static rustc_session::lint::Lint,
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
) where
L: for<'a> rustc_errors::DecorateLint<'a, ()>,
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
{
let (span, frames) = get_span_and_frames(tcx, machine);

View File

@ -193,8 +193,8 @@ fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
#[rustc_diagnostic_item = "DecorateLint"]
pub trait DecorateLint<'a, G: EmissionGuarantee> {
#[rustc_diagnostic_item = "LintDiagnostic"]
pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
/// Decorate and emit a lint.
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);

View File

@ -37,8 +37,8 @@
pub use codes::*;
pub use diagnostic::{
BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner,
DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort, IntoDiagArg, StringPart, Subdiag,
BugAbort, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner, DiagStyledString,
Diagnostic, EmissionGuarantee, FatalAbort, IntoDiagArg, LintDiagnostic, StringPart, Subdiag,
SubdiagMessageOp, Subdiagnostic,
};
pub use diagnostic_impls::{

View File

@ -186,7 +186,7 @@ lint_deprecated_lint_name =
.help = change it to {$replace}
lint_diag_out_of_impl =
diagnostics should only be created in `Diagnostic`/`Subdiagnostic` impls
diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
lint_drop_glue =
types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped

View File

@ -44,7 +44,7 @@
use rustc_ast::visit::{FnCtxt, FnKind};
use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust::{self, expr_to_string};
use rustc_errors::{Applicability, DecorateLint, MultiSpan};
use rustc_errors::{Applicability, LintDiagnostic, MultiSpan};
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
@ -327,7 +327,7 @@ fn report_unsafe(
&self,
cx: &EarlyContext<'_>,
span: Span,
decorate: impl for<'a> DecorateLint<'a, ()>,
decorate: impl for<'a> LintDiagnostic<'a, ()>,
) {
// This comes from a macro that has `#[allow_internal_unsafe]`.
if span.allows_unsafe() {

View File

@ -21,7 +21,7 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync;
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{DecorateLint, Diag, DiagMessage, MultiSpan};
use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan};
use rustc_feature::Features;
use rustc_hir as hir;
use rustc_hir::def::Res;
@ -563,13 +563,13 @@ fn opt_span_lint<S: Into<MultiSpan>>(
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
);
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
/// typically generated by `#[derive(LintDiagnostic)]`).
fn emit_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: S,
decorator: impl for<'a> DecorateLint<'a, ()>,
decorator: impl for<'a> LintDiagnostic<'a, ()>,
) {
self.opt_span_lint(lint, Some(span), decorator.msg(), |diag| {
decorator.decorate_lint(diag);
@ -590,9 +590,9 @@ fn span_lint<S: Into<MultiSpan>>(
self.opt_span_lint(lint, Some(span), msg, decorate);
}
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
/// generated by `#[derive(LintDiagnostic)]`).
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> DecorateLint<'a, ()>) {
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> LintDiagnostic<'a, ()>) {
self.opt_span_lint(lint, None as Option<Span>, decorator.msg(), |diag| {
decorator.decorate_lint(diag);
});

View File

@ -352,14 +352,14 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
declare_tool_lint! {
/// The `diagnostic_outside_of_impl` lint detects calls to functions annotated with
/// `#[rustc_lint_diagnostics]` that are outside an `Diagnostic`, `Subdiagnostic`, or
/// `DecorateLint` impl, or a `#[derive(Diagnostic)]`, `#[derive(Subdiagnostic)]`,
/// `#[derive(DecorateLint)]` expansion.
/// `LintDiagnostic` impl, or a `#[derive(Diagnostic)]`, `#[derive(Subdiagnostic)]`,
/// `#[derive(LintDiagnostic)]` expansion.
///
/// More details on diagnostics implementations can be found
/// [here](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html).
pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL,
Deny,
"prevent creation of diagnostics outside of `Diagnostic`/`Subdiagnostic` impls",
"prevent diagnostic creation outside of `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls",
report_in_external_macro: true
}
@ -455,7 +455,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
}
// Calls to `#[rustc_lint_diagnostics]`-marked functions should only occur:
// - inside an impl of `Diagnostic`, `Subdiagnostic`, or `DecorateLint`, or
// - inside an impl of `Diagnostic`, `Subdiagnostic`, or `LintDiagnostic`, or
// - inside a parent function that is itself marked with `#[rustc_lint_diagnostics]`.
//
// Otherwise, emit a `DIAGNOSTIC_OUTSIDE_OF_IMPL` lint.
@ -467,7 +467,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
&& let Impl { of_trait: Some(of_trait), .. } = impl_
&& let Some(def_id) = of_trait.trait_def_id()
&& let Some(name) = cx.tcx.get_diagnostic_name(def_id)
&& matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint)
&& matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::LintDiagnostic)
{
is_inside_appropriate_impl = true;
break;

View File

@ -16,7 +16,7 @@
use rustc_ast as ast;
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::{DecorateLint, Diag, DiagMessage, MultiSpan};
use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan};
use rustc_feature::{Features, GateIssue};
use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor};
@ -1119,7 +1119,7 @@ pub fn emit_span_lint(
&self,
lint: &'static Lint,
span: MultiSpan,
decorate: impl for<'a> DecorateLint<'a, ()>,
decorate: impl for<'a> LintDiagnostic<'a, ()>,
) {
let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| {
@ -1128,7 +1128,7 @@ pub fn emit_span_lint(
}
#[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> LintDiagnostic<'a, ()>) {
let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {
decorate.decorate_lint(lint);

View File

@ -5,8 +5,8 @@
use crate::errors::RequestedLevel;
use crate::fluent_generated as fluent;
use rustc_errors::{
codes::*, Applicability, DecorateLint, Diag, DiagMessage, DiagStyledString, EmissionGuarantee,
SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
codes::*, Applicability, Diag, DiagMessage, DiagStyledString, EmissionGuarantee,
LintDiagnostic, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
};
use rustc_hir::def_id::DefId;
use rustc_macros::{LintDiagnostic, Subdiagnostic};
@ -136,7 +136,7 @@ pub struct BuiltinMissingDebugImpl<'a> {
}
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> {
impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.arg("debug", self.tcx.def_path_str(self.def_id));
}
@ -241,7 +241,7 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
pub session: &'a Session,
}
impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.span_label(self.label, fluent::lint_label);
rustc_session::parse::add_feature_diagnostics(
@ -423,7 +423,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
pub tcx: TyCtxt<'a>,
}
impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("ty", self.ty);
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
@ -1159,7 +1159,7 @@ pub struct NonFmtPanicUnused {
}
// Used because of two suggestions based on one Option<Span>
impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("count", self.count);
diag.note(fluent::lint_note);
@ -1397,7 +1397,7 @@ pub struct DropTraitConstraintsDiag<'a> {
}
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("predicate", self.predicate);
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
@ -1414,7 +1414,7 @@ pub struct DropGlue<'a> {
}
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
}
@ -1689,7 +1689,7 @@ pub struct ImproperCTypes<'a> {
}
// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("ty", self.ty);
diag.arg("desc", self.desc);
@ -1832,7 +1832,7 @@ pub enum UnusedDefSuggestion {
}
// Needed because of def_path_str
impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("pre", self.pre);
diag.arg("post", self.post);
@ -1915,7 +1915,7 @@ pub struct AsyncFnInTraitDiag {
pub sugg: Option<Vec<(Span, String)>>,
}
impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag {
impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.note(fluent::lint_note);
if let Some(sugg) = self.sugg {

View File

@ -153,7 +153,7 @@ pub(crate) fn into_tokens(self) -> TokenStream {
});
let mut imp = structure.gen_impl(quote! {
gen impl<'__a> rustc_errors::DecorateLint<'__a, ()> for @Self {
gen impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for @Self {
#[track_caller]
fn decorate_lint<'__b>(
self,

View File

@ -43,7 +43,7 @@
#[cfg(parallel_compiler)]
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{DecorateLint, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, MultiSpan};
use rustc_errors::{Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, LintDiagnostic, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
@ -2129,7 +2129,7 @@ pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
T::collect_and_apply(iter, |xs| self.mk_bound_variable_kinds(xs))
}
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
/// typically generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_node_span_lint(
@ -2137,7 +2137,7 @@ pub fn emit_node_span_lint(
lint: &'static Lint,
hir_id: HirId,
span: impl Into<MultiSpan>,
decorator: impl for<'a> DecorateLint<'a, ()>,
decorator: impl for<'a> LintDiagnostic<'a, ()>,
) {
let msg = decorator.msg();
let (level, src) = self.lint_level_at_node(lint, hir_id);
@ -2163,14 +2163,14 @@ pub fn node_span_lint(
lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate);
}
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
/// generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_node_lint(
self,
lint: &'static Lint,
id: HirId,
decorator: impl for<'a> DecorateLint<'a, ()>,
decorator: impl for<'a> LintDiagnostic<'a, ()>,
) {
self.node_lint(lint, id, decorator.msg(), |diag| {
decorator.decorate_lint(diag);

View File

@ -1,8 +1,8 @@
use std::borrow::Cow;
use rustc_errors::{
codes::*, Applicability, DecorateLint, Diag, DiagArgValue, DiagCtxt, DiagMessage, Diagnostic,
EmissionGuarantee, Level,
codes::*, Applicability, Diag, DiagArgValue, DiagCtxt, DiagMessage, Diagnostic,
EmissionGuarantee, Level, LintDiagnostic,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails};
@ -181,7 +181,7 @@ pub(crate) struct UnsafeOpInUnsafeFn {
pub suggest_unsafe_block: Option<(Span, Span, Span)>,
}
impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
impl<'a> LintDiagnostic<'a, ()> for UnsafeOpInUnsafeFn {
#[track_caller]
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
let desc = diag.dcx.eagerly_translate_to_string(self.details.label(), [].into_iter());
@ -215,7 +215,7 @@ pub(crate) enum AssertLintKind {
UnconditionalPanic,
}
impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint<P> {
impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
let message = self.assert_kind.diagnostic_message();
self.assert_kind.add_args(&mut |name, value| {
@ -269,7 +269,7 @@ pub(crate) struct MustNotSupend<'tcx, 'a> {
}
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> {
impl<'a> LintDiagnostic<'a, ()> for MustNotSupend<'_, '_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.span_label(self.yield_sp, fluent::_subdiag::label);
if let Some(reason) = self.reason {

View File

@ -97,7 +97,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
lint_name: "non_exhaustive_omitted_patterns",
};
use rustc_errors::DecorateLint;
use rustc_errors::LintDiagnostic;
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().unwrap().span, "");
err.primary_message(decorator.msg());
decorator.decorate_lint(&mut err);

View File

@ -183,7 +183,6 @@
DebugStruct,
Decodable,
Decoder,
DecorateLint,
Default,
Deref,
DiagMessage,
@ -242,6 +241,7 @@
Layout,
Left,
LinkedList,
LintDiagnostic,
LintPass,
LocalKey,
Mutex,

View File

@ -14,7 +14,7 @@
extern crate rustc_span;
use rustc_errors::{
DecorateLint, Diag, DiagCtxt, DiagInner, DiagMessage, Diagnostic, EmissionGuarantee, Level,
Diag, DiagCtxt, DiagInner, DiagMessage, Diagnostic, EmissionGuarantee, Level, LintDiagnostic,
SubdiagMessageOp, Subdiagnostic,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
@ -78,9 +78,9 @@ fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
}
}
pub struct UntranslatableInDecorateLint;
pub struct UntranslatableInLintDiagnostic;
impl<'a> DecorateLint<'a, ()> for UntranslatableInDecorateLint {
impl<'a> LintDiagnostic<'a, ()> for UntranslatableInLintDiagnostic {
fn decorate_lint<'b, >(self, diag: &'b mut Diag<'a, ()>) {
diag.note("untranslatable diagnostic");
//~^ ERROR diagnostics should be created using translatable messages
@ -91,9 +91,9 @@ fn msg(&self) -> DiagMessage {
}
}
pub struct TranslatableInDecorateLint;
pub struct TranslatableInLintDiagnostic;
impl<'a> DecorateLint<'a, ()> for TranslatableInDecorateLint {
impl<'a> LintDiagnostic<'a, ()> for TranslatableInLintDiagnostic {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.note(crate::fluent_generated::no_crate_note);
}
@ -105,10 +105,10 @@ fn msg(&self) -> DiagMessage {
pub fn make_diagnostics<'a>(dcx: &'a DiagCtxt) {
let _diag = dcx.struct_err(crate::fluent_generated::no_crate_example);
//~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic` impls
//~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
let _diag = dcx.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic` impls
//~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages
}

View File

@ -22,7 +22,7 @@ error: diagnostics should be created using translatable messages
LL | diag.note("untranslatable diagnostic");
| ^^^^
error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic` impls
error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
--> $DIR/diagnostics.rs:107:21
|
LL | let _diag = dcx.struct_err(crate::fluent_generated::no_crate_example);
@ -34,7 +34,7 @@ note: the lint level is defined here
LL | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic` impls
error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
--> $DIR/diagnostics.rs:110:21
|
LL | let _diag = dcx.struct_err("untranslatable diagnostic");