Skip to content

Commit b7e18ca

Browse files
committed
De-genericize some IntoDiagnostic impls.
These impls are all needed for just a single `IntoDiagnostic` type, not a family of them. Note that `ErrorGuaranteed` is the default type parameter for `IntoDiagnostic`.
1 parent d51b3db commit b7e18ca

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

compiler/rustc_builtin_macros/src/errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{
2-
AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, Handler, IntoDiagnostic, MultiSpan,
2+
AddToDiagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan,
33
SingleLabelManySpans,
44
};
55
use rustc_macros::{Diagnostic, Subdiagnostic};
@@ -446,9 +446,9 @@ pub(crate) struct EnvNotDefinedWithUserMessage {
446446
}
447447

448448
// Hand-written implementation to support custom user messages.
449-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage {
449+
impl<'a> IntoDiagnostic<'a> for EnvNotDefinedWithUserMessage {
450450
#[track_caller]
451-
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
451+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
452452
#[expect(
453453
rustc::untranslatable_diagnostic,
454454
reason = "cannot translate user-provided messages"
@@ -801,8 +801,8 @@ pub(crate) struct AsmClobberNoReg {
801801
pub(crate) clobbers: Vec<Span>,
802802
}
803803

804-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
805-
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
804+
impl<'a> IntoDiagnostic<'a> for AsmClobberNoReg {
805+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
806806
let mut diag =
807807
handler.struct_diagnostic(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
808808
diag.set_span(self.spans.clone());

compiler/rustc_codegen_llvm/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::Path;
55
use crate::fluent_generated as fluent;
66
use rustc_data_structures::small_c_str::SmallCStr;
77
use rustc_errors::{
8-
DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
8+
DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, FatalError, Handler, IntoDiagnostic,
99
};
1010
use rustc_macros::{Diagnostic, Subdiagnostic};
1111
use rustc_span::Span;
@@ -101,9 +101,9 @@ pub(crate) struct DynamicLinkingWithLTO;
101101

102102
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
103103

104-
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
105-
fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, G> {
106-
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(handler);
104+
impl IntoDiagnostic<'_, FatalError> for ParseTargetMachineConfig<'_> {
105+
fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, FatalError> {
106+
let diag: DiagnosticBuilder<'_, FatalError> = self.0.into_diagnostic(handler);
107107
let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message");
108108
let message = handler.eagerly_translate_to_string(message.clone(), diag.args());
109109

compiler/rustc_mir_transform/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22

33
use rustc_errors::{
44
Applicability, DecorateLint, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage,
5-
EmissionGuarantee, Handler, IntoDiagnostic,
5+
EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
66
};
77
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
88
use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails};
@@ -62,9 +62,9 @@ pub(crate) struct RequiresUnsafe {
6262
// so we need to eagerly translate the label here, which isn't supported by the derive API
6363
// We could also exhaustively list out the primary messages for all unsafe violations,
6464
// but this would result in a lot of duplication.
65-
impl<'sess, G: EmissionGuarantee> IntoDiagnostic<'sess, G> for RequiresUnsafe {
65+
impl<'sess> IntoDiagnostic<'sess> for RequiresUnsafe {
6666
#[track_caller]
67-
fn into_diagnostic(self, handler: &'sess Handler) -> DiagnosticBuilder<'sess, G> {
67+
fn into_diagnostic(self, handler: &'sess Handler) -> DiagnosticBuilder<'sess, ErrorGuaranteed> {
6868
let mut diag = handler.struct_diagnostic(fluent::mir_transform_requires_unsafe);
6969
diag.code(rustc_errors::DiagnosticId::Error("E0133".to_string()));
7070
diag.set_span(self.span);

compiler/rustc_parse/src/errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22

33
use rustc_ast::token::Token;
44
use rustc_ast::{Path, Visibility};
5-
use rustc_errors::{AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
5+
use rustc_errors::{AddToDiagnostic, Applicability, ErrorGuaranteed, IntoDiagnostic};
66
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_session::errors::ExprParenthesesNeeded;
88
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
@@ -1038,12 +1038,12 @@ pub(crate) struct ExpectedIdentifier {
10381038
pub help_cannot_start_number: Option<HelpIdentifierStartsWithNumber>,
10391039
}
10401040

1041-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
1041+
impl<'a> IntoDiagnostic<'a> for ExpectedIdentifier {
10421042
#[track_caller]
10431043
fn into_diagnostic(
10441044
self,
10451045
handler: &'a rustc_errors::Handler,
1046-
) -> rustc_errors::DiagnosticBuilder<'a, G> {
1046+
) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
10471047
let token_descr = TokenDescription::from_token(&self.token);
10481048

10491049
let mut diag = handler.struct_diagnostic(match token_descr {
@@ -1095,12 +1095,12 @@ pub(crate) struct ExpectedSemi {
10951095
pub sugg: ExpectedSemiSugg,
10961096
}
10971097

1098-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
1098+
impl<'a> IntoDiagnostic<'a> for ExpectedSemi {
10991099
#[track_caller]
11001100
fn into_diagnostic(
11011101
self,
11021102
handler: &'a rustc_errors::Handler,
1103-
) -> rustc_errors::DiagnosticBuilder<'a, G> {
1103+
) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
11041104
let token_descr = TokenDescription::from_token(&self.token);
11051105

11061106
let mut diag = handler.struct_diagnostic(match token_descr {

compiler/rustc_session/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::num::NonZeroU32;
33
use crate::parse::ParseSess;
44
use rustc_ast::token;
55
use rustc_ast::util::literal::LitError;
6-
use rustc_errors::{error_code, DiagnosticMessage, EmissionGuarantee, IntoDiagnostic, MultiSpan};
6+
use rustc_errors::{error_code, DiagnosticMessage, ErrorGuaranteed, IntoDiagnostic, MultiSpan};
77
use rustc_macros::Diagnostic;
88
use rustc_span::{BytePos, Span, Symbol};
99
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
@@ -13,12 +13,12 @@ pub struct FeatureGateError {
1313
pub explain: DiagnosticMessage,
1414
}
1515

16-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for FeatureGateError {
16+
impl<'a> IntoDiagnostic<'a> for FeatureGateError {
1717
#[track_caller]
1818
fn into_diagnostic(
1919
self,
2020
handler: &'a rustc_errors::Handler,
21-
) -> rustc_errors::DiagnosticBuilder<'a, G> {
21+
) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
2222
let mut diag = handler.struct_diagnostic(self.explain);
2323
diag.set_span(self.span);
2424
diag.code(error_code!(E0658));

0 commit comments

Comments
 (0)