1
Fork 0

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

@ -44,7 +44,7 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree};
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 @@ impl UnsafeCode {
&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 crate::passes::{EarlyLintPassObject, LateLintPassObject};
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 @@ pub trait LintContext {
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 @@ pub trait LintContext {
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 @@ declare_tool_lint! {
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 @@ impl LateLintPass<'_> for Diagnostics {
}
// 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 @@ impl LateLintPass<'_> for Diagnostics {
&& 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 crate::{
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 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
&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 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
}
#[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 std::num::NonZero;
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 {