Skip to content

Commit

Permalink
Unrolled build for rust-lang#118989
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#118989 - compiler-errors:lint-decorator-2, r=WaffleLapkin

Simplify lint decorator derive too

See last commit, since this is stacked on top of rust-lang#118727.

r? WaffleLapkin
  • Loading branch information
rust-timer authored Dec 16, 2023
2 parents 5c927ab + 108bec6 commit 4492c19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 68 deletions.
5 changes: 1 addition & 4 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ where
#[rustc_diagnostic_item = "DecorateLint"]
pub trait DecorateLint<'a, G: EmissionGuarantee> {
/// Decorate and emit a lint.
fn decorate_lint<'b>(
self,
diag: &'b mut DiagnosticBuilder<'a, G>,
) -> &'b mut DiagnosticBuilder<'a, G>;
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, G>);

fn msg(&self) -> DiagnosticMessage;
}
Expand Down
56 changes: 11 additions & 45 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ pub struct BuiltinMissingDebugImpl<'a> {

// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("debug", self.tcx.def_path_str(self.def_id));
diag
}

fn msg(&self) -> DiagnosticMessage {
Expand Down Expand Up @@ -243,17 +239,13 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
}

impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.span_label(self.label, fluent::lint_label);
rustc_session::parse::add_feature_diagnostics(
diag,
self.parse_sess,
sym::async_fn_track_caller,
);
diag
}

fn msg(&self) -> DiagnosticMessage {
Expand Down Expand Up @@ -433,10 +425,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
}

impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("ty", self.ty);
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
Expand All @@ -447,7 +436,6 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
);
}
self.sub.add_to_diagnostic(diag);
diag
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down Expand Up @@ -1159,10 +1147,7 @@ pub struct NonFmtPanicUnused {

// Used because of two suggestions based on one Option<Span>
impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("count", self.count);
diag.note(fluent::lint_note);
if let Some(span) = self.suggestion {
Expand All @@ -1179,7 +1164,6 @@ impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
Applicability::MachineApplicable,
);
}
diag
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down Expand Up @@ -1358,12 +1342,9 @@ pub struct DropTraitConstraintsDiag<'a> {

// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("predicate", self.predicate);
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id));
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand All @@ -1378,11 +1359,8 @@ pub struct DropGlue<'a> {

// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id));
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down Expand Up @@ -1655,10 +1633,7 @@ pub struct ImproperCTypes<'a> {

// Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("ty", self.ty);
diag.set_arg("desc", self.desc);
diag.span_label(self.label, fluent::lint_label);
Expand All @@ -1669,7 +1644,6 @@ impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
if let Some(note) = self.span_note {
diag.span_note(note, fluent::lint_note);
}
diag
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down Expand Up @@ -1802,10 +1776,7 @@ pub enum UnusedDefSuggestion {

// Needed because of def_path_str
impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("pre", self.pre);
diag.set_arg("post", self.post);
diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id));
Expand All @@ -1816,7 +1787,6 @@ impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
if let Some(sugg) = self.suggestion {
diag.subdiagnostic(sugg);
}
diag
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down Expand Up @@ -1889,15 +1859,11 @@ pub struct AsyncFnInTraitDiag {
}

impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.note(fluent::lint_note);
if let Some(sugg) = self.sugg {
diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
}
diag
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ impl<'a> LintDiagnosticDerive<'a> {
fn decorate_lint<'__b>(
self,
#diag: &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()>
) -> &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()> {
) {
use rustc_errors::IntoDiagnosticArg;
#implementation
#implementation;
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down
20 changes: 3 additions & 17 deletions compiler/rustc_mir_transform/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ pub(crate) struct UnsafeOpInUnsafeFn {

impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
#[track_caller]
fn decorate_lint<'b>(
self,
diag: &'b mut DiagnosticBuilder<'a, ()>,
) -> &'b mut DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
let handler = diag.handler().expect("lint should not yet be emitted");
let desc = handler.eagerly_translate_to_string(self.details.label(), [].into_iter());
diag.set_arg("details", desc);
Expand All @@ -198,8 +195,6 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
Applicability::MaybeIncorrect,
);
}

diag
}

fn msg(&self) -> DiagnosticMessage {
Expand All @@ -213,19 +208,14 @@ pub(crate) enum AssertLint<P> {
}

impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint<P> {
fn decorate_lint<'b>(
self,
diag: &'b mut DiagnosticBuilder<'a, ()>,
) -> &'b mut DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
let span = self.span();
let assert_kind = self.panic();
let message = assert_kind.diagnostic_message();
assert_kind.add_args(&mut |name, value| {
diag.set_arg(name, value);
});
diag.span_label(span, message);

diag
}

fn msg(&self) -> DiagnosticMessage {
Expand Down Expand Up @@ -284,10 +274,7 @@ pub(crate) struct MustNotSupend<'tcx, 'a> {

// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.span_label(self.yield_sp, fluent::_subdiag::label);
if let Some(reason) = self.reason {
diag.subdiagnostic(reason);
Expand All @@ -296,7 +283,6 @@ impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> {
diag.set_arg("pre", self.pre);
diag.set_arg("def_path", self.tcx.def_path_str(self.def_id));
diag.set_arg("post", self.post);
diag
}

fn msg(&self) -> rustc_errors::DiagnosticMessage {
Expand Down

0 comments on commit 4492c19

Please sign in to comment.