Flatten diagnostic structs
This commit is contained in:
parent
e9a5329a6f
commit
67394e7945
@ -3,8 +3,9 @@ use std::borrow::Cow;
|
||||
use rustc_errors::fluent;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
||||
use rustc_session::SessionDiagnostic;
|
||||
use rustc_errors::Handler;
|
||||
use rustc_errors::IntoDiagnostic;
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub(crate) enum UnknownCTargetFeature<'a> {
|
||||
@ -12,27 +13,24 @@ pub(crate) enum UnknownCTargetFeature<'a> {
|
||||
UnknownFeature { feature: &'a str, rust_feature: Option<&'a str> },
|
||||
}
|
||||
|
||||
impl SessionDiagnostic<'_, ()> for UnknownCTargetFeature<'_> {
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
sess: &'_ rustc_session::parse::ParseSess,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
impl IntoDiagnostic<'_, ()> for UnknownCTargetFeature<'_> {
|
||||
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ()> {
|
||||
match self {
|
||||
UnknownCTargetFeature::UnknownFeaturePrefix { feature } => {
|
||||
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
|
||||
let mut diag = sess.struct_warn(fluent::codegen_llvm_unknown_ctarget_feature);
|
||||
diag.set_arg("feature", feature);
|
||||
diag.note(fluent::codegen_llvm::unknown_feature_prefix);
|
||||
diag.note(fluent::codegen_llvm_unknown_feature_prefix);
|
||||
diag
|
||||
}
|
||||
UnknownCTargetFeature::UnknownFeature { feature, rust_feature } => {
|
||||
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
|
||||
let mut diag = sess.struct_warn(fluent::codegen_llvm_unknown_ctarget_feature);
|
||||
diag.set_arg("feature", feature);
|
||||
diag.note(fluent::codegen_llvm::unknown_feature);
|
||||
diag.note(fluent::codegen_llvm_unknown_feature);
|
||||
if let Some(rust_feature) = rust_feature {
|
||||
diag.help(fluent::codegen_llvm::rust_feature);
|
||||
diag.help(fluent::codegen_llvm_rust_feature);
|
||||
diag.set_arg("rust_feature", rust_feature);
|
||||
} else {
|
||||
diag.note(fluent::codegen_llvm::unknown_feature_fill_request);
|
||||
diag.note(fluent::codegen_llvm_unknown_feature_fill_request);
|
||||
}
|
||||
diag
|
||||
}
|
||||
@ -40,81 +38,81 @@ impl SessionDiagnostic<'_, ()> for UnknownCTargetFeature<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::error_creating_import_library)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_error_creating_import_library)]
|
||||
pub(crate) struct ErrorCreatingImportLibrary<'a> {
|
||||
pub lib_name: &'a str,
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::instrument_coverage_requires_llvm_12)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_instrument_coverage_requires_llvm_12)]
|
||||
pub(crate) struct InstrumentCoverageRequiresLLVM12;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::symbol_already_defined)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_symbol_already_defined)]
|
||||
pub(crate) struct SymbolAlreadyDefined<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub symbol_name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::branch_protection_requires_aarch64)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_branch_protection_requires_aarch64)]
|
||||
pub(crate) struct BranchProtectionRequiresAArch64;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::layout_size_overflow)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_layout_size_overflow)]
|
||||
pub(crate) struct LayoutSizeOverflow {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::invalid_minimum_alignment)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_invalid_minimum_alignment)]
|
||||
pub(crate) struct InvalidMinimumAlignment {
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::linkage_const_or_mut_type)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_linkage_const_or_mut_type)]
|
||||
pub(crate) struct LinkageConstOrMutType {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::sanitizer_memtag_requires_mte)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
|
||||
pub(crate) struct SanitizerMemtagRequiresMte;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::archive_build_failure)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_archive_build_failure)]
|
||||
pub(crate) struct ArchiveBuildFailure {
|
||||
pub error: std::io::Error,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::error_writing_def_file)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_error_writing_def_file)]
|
||||
pub(crate) struct ErrorWritingDEFFile {
|
||||
pub error: std::io::Error,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::error_calling_dlltool)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_error_calling_dlltool)]
|
||||
pub(crate) struct ErrorCallingDllTool {
|
||||
pub error: std::io::Error,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::dlltool_fail_import_library)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_dlltool_fail_import_library)]
|
||||
pub(crate) struct DlltoolFailImportLibrary<'a> {
|
||||
pub stdout: Cow<'a, str>,
|
||||
pub stderr: Cow<'a, str>,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_llvm::unknown_archive_kind)]
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_unknown_archive_kind)]
|
||||
pub(crate) struct UnknownArchiveKind<'a> {
|
||||
pub kind: &'a str,
|
||||
}
|
||||
@ -124,21 +122,18 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
|
||||
pub span: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
#[help(codegen_llvm::missing_features)]
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(codegen_llvm_missing_features)]
|
||||
pub(crate) struct MissingFeatures;
|
||||
|
||||
impl SessionDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
sess: &'_ rustc_session::parse::ParseSess,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
|
||||
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
let mut diag = if let Some(span) = self.span {
|
||||
let mut diag = sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable);
|
||||
let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
|
||||
diag.set_span(span);
|
||||
diag
|
||||
} else {
|
||||
sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable)
|
||||
sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable)
|
||||
};
|
||||
diag.set_arg("features", self.features.join(", "));
|
||||
diag
|
||||
|
Loading…
x
Reference in New Issue
Block a user