Skip to content

Commit 67394e7

Browse files
committed
Flatten diagnostic structs
1 parent e9a5329 commit 67394e7

File tree

1 file changed

+43
-48
lines changed

1 file changed

+43
-48
lines changed

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,118 +3,116 @@ use std::borrow::Cow;
33
use rustc_errors::fluent;
44
use rustc_errors::DiagnosticBuilder;
55
use rustc_errors::ErrorGuaranteed;
6-
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
7-
use rustc_session::SessionDiagnostic;
6+
use rustc_errors::Handler;
7+
use rustc_errors::IntoDiagnostic;
8+
use rustc_macros::{Diagnostic, Subdiagnostic};
89
use rustc_span::Span;
910

1011
pub(crate) enum UnknownCTargetFeature<'a> {
1112
UnknownFeaturePrefix { feature: &'a str },
1213
UnknownFeature { feature: &'a str, rust_feature: Option<&'a str> },
1314
}
1415

15-
impl SessionDiagnostic<'_, ()> for UnknownCTargetFeature<'_> {
16-
fn into_diagnostic(
17-
self,
18-
sess: &'_ rustc_session::parse::ParseSess,
19-
) -> DiagnosticBuilder<'_, ()> {
16+
impl IntoDiagnostic<'_, ()> for UnknownCTargetFeature<'_> {
17+
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ()> {
2018
match self {
2119
UnknownCTargetFeature::UnknownFeaturePrefix { feature } => {
22-
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
20+
let mut diag = sess.struct_warn(fluent::codegen_llvm_unknown_ctarget_feature);
2321
diag.set_arg("feature", feature);
24-
diag.note(fluent::codegen_llvm::unknown_feature_prefix);
22+
diag.note(fluent::codegen_llvm_unknown_feature_prefix);
2523
diag
2624
}
2725
UnknownCTargetFeature::UnknownFeature { feature, rust_feature } => {
28-
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
26+
let mut diag = sess.struct_warn(fluent::codegen_llvm_unknown_ctarget_feature);
2927
diag.set_arg("feature", feature);
30-
diag.note(fluent::codegen_llvm::unknown_feature);
28+
diag.note(fluent::codegen_llvm_unknown_feature);
3129
if let Some(rust_feature) = rust_feature {
32-
diag.help(fluent::codegen_llvm::rust_feature);
30+
diag.help(fluent::codegen_llvm_rust_feature);
3331
diag.set_arg("rust_feature", rust_feature);
3432
} else {
35-
diag.note(fluent::codegen_llvm::unknown_feature_fill_request);
33+
diag.note(fluent::codegen_llvm_unknown_feature_fill_request);
3634
}
3735
diag
3836
}
3937
}
4038
}
4139
}
4240

43-
#[derive(SessionDiagnostic)]
44-
#[diag(codegen_llvm::error_creating_import_library)]
41+
#[derive(Diagnostic)]
42+
#[diag(codegen_llvm_error_creating_import_library)]
4543
pub(crate) struct ErrorCreatingImportLibrary<'a> {
4644
pub lib_name: &'a str,
4745
pub error: String,
4846
}
4947

50-
#[derive(SessionDiagnostic)]
51-
#[diag(codegen_llvm::instrument_coverage_requires_llvm_12)]
48+
#[derive(Diagnostic)]
49+
#[diag(codegen_llvm_instrument_coverage_requires_llvm_12)]
5250
pub(crate) struct InstrumentCoverageRequiresLLVM12;
5351

54-
#[derive(SessionDiagnostic)]
55-
#[diag(codegen_llvm::symbol_already_defined)]
52+
#[derive(Diagnostic)]
53+
#[diag(codegen_llvm_symbol_already_defined)]
5654
pub(crate) struct SymbolAlreadyDefined<'a> {
5755
#[primary_span]
5856
pub span: Span,
5957
pub symbol_name: &'a str,
6058
}
6159

62-
#[derive(SessionDiagnostic)]
63-
#[diag(codegen_llvm::branch_protection_requires_aarch64)]
60+
#[derive(Diagnostic)]
61+
#[diag(codegen_llvm_branch_protection_requires_aarch64)]
6462
pub(crate) struct BranchProtectionRequiresAArch64;
6563

66-
#[derive(SessionDiagnostic)]
67-
#[diag(codegen_llvm::layout_size_overflow)]
64+
#[derive(Diagnostic)]
65+
#[diag(codegen_llvm_layout_size_overflow)]
6866
pub(crate) struct LayoutSizeOverflow {
6967
#[primary_span]
7068
pub span: Span,
7169
pub error: String,
7270
}
7371

74-
#[derive(SessionDiagnostic)]
75-
#[diag(codegen_llvm::invalid_minimum_alignment)]
72+
#[derive(Diagnostic)]
73+
#[diag(codegen_llvm_invalid_minimum_alignment)]
7674
pub(crate) struct InvalidMinimumAlignment {
7775
pub err: String,
7876
}
7977

80-
#[derive(SessionDiagnostic)]
81-
#[diag(codegen_llvm::linkage_const_or_mut_type)]
78+
#[derive(Diagnostic)]
79+
#[diag(codegen_llvm_linkage_const_or_mut_type)]
8280
pub(crate) struct LinkageConstOrMutType {
8381
#[primary_span]
8482
pub span: Span,
8583
}
8684

87-
#[derive(SessionDiagnostic)]
88-
#[diag(codegen_llvm::sanitizer_memtag_requires_mte)]
85+
#[derive(Diagnostic)]
86+
#[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
8987
pub(crate) struct SanitizerMemtagRequiresMte;
9088

91-
#[derive(SessionDiagnostic)]
92-
#[diag(codegen_llvm::archive_build_failure)]
89+
#[derive(Diagnostic)]
90+
#[diag(codegen_llvm_archive_build_failure)]
9391
pub(crate) struct ArchiveBuildFailure {
9492
pub error: std::io::Error,
9593
}
9694

97-
#[derive(SessionDiagnostic)]
98-
#[diag(codegen_llvm::error_writing_def_file)]
95+
#[derive(Diagnostic)]
96+
#[diag(codegen_llvm_error_writing_def_file)]
9997
pub(crate) struct ErrorWritingDEFFile {
10098
pub error: std::io::Error,
10199
}
102100

103-
#[derive(SessionDiagnostic)]
104-
#[diag(codegen_llvm::error_calling_dlltool)]
101+
#[derive(Diagnostic)]
102+
#[diag(codegen_llvm_error_calling_dlltool)]
105103
pub(crate) struct ErrorCallingDllTool {
106104
pub error: std::io::Error,
107105
}
108106

109-
#[derive(SessionDiagnostic)]
110-
#[diag(codegen_llvm::dlltool_fail_import_library)]
107+
#[derive(Diagnostic)]
108+
#[diag(codegen_llvm_dlltool_fail_import_library)]
111109
pub(crate) struct DlltoolFailImportLibrary<'a> {
112110
pub stdout: Cow<'a, str>,
113111
pub stderr: Cow<'a, str>,
114112
}
115113

116-
#[derive(SessionDiagnostic)]
117-
#[diag(codegen_llvm::unknown_archive_kind)]
114+
#[derive(Diagnostic)]
115+
#[diag(codegen_llvm_unknown_archive_kind)]
118116
pub(crate) struct UnknownArchiveKind<'a> {
119117
pub kind: &'a str,
120118
}
@@ -124,21 +122,18 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
124122
pub span: Option<Span>,
125123
}
126124

127-
#[derive(SessionSubdiagnostic)]
128-
#[help(codegen_llvm::missing_features)]
125+
#[derive(Subdiagnostic)]
126+
#[help(codegen_llvm_missing_features)]
129127
pub(crate) struct MissingFeatures;
130128

131-
impl SessionDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
132-
fn into_diagnostic(
133-
self,
134-
sess: &'_ rustc_session::parse::ParseSess,
135-
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
129+
impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
130+
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
136131
let mut diag = if let Some(span) = self.span {
137-
let mut diag = sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable);
132+
let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
138133
diag.set_span(span);
139134
diag
140135
} else {
141-
sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable)
136+
sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable)
142137
};
143138
diag.set_arg("features", self.features.join(", "));
144139
diag

0 commit comments

Comments
 (0)