| 
 | 1 | +use std::borrow::Cow;  | 
 | 2 | + | 
 | 3 | +use rustc_errors::fluent;  | 
 | 4 | +use rustc_errors::DiagnosticBuilder;  | 
 | 5 | +use rustc_errors::ErrorGuaranteed;  | 
 | 6 | +use rustc_errors::Handler;  | 
 | 7 | +use rustc_errors::IntoDiagnostic;  | 
 | 8 | +use rustc_macros::{Diagnostic, Subdiagnostic};  | 
 | 9 | +use rustc_span::Span;  | 
 | 10 | + | 
 | 11 | +#[derive(Diagnostic)]  | 
 | 12 | +#[diag(codegen_llvm_unknown_ctarget_feature_prefix)]  | 
 | 13 | +#[note]  | 
 | 14 | +pub(crate) struct UnknownCTargetFeaturePrefix<'a> {  | 
 | 15 | +    pub feature: &'a str,  | 
 | 16 | +}  | 
 | 17 | + | 
 | 18 | +#[derive(Diagnostic)]  | 
 | 19 | +#[diag(codegen_llvm_unknown_ctarget_feature)]  | 
 | 20 | +#[note]  | 
 | 21 | +pub(crate) struct UnknownCTargetFeature<'a> {  | 
 | 22 | +    pub feature: &'a str,  | 
 | 23 | +    #[subdiagnostic]  | 
 | 24 | +    pub rust_feature: PossibleFeature<'a>,  | 
 | 25 | +}  | 
 | 26 | + | 
 | 27 | +#[derive(Subdiagnostic)]  | 
 | 28 | +pub(crate) enum PossibleFeature<'a> {  | 
 | 29 | +    #[help(possible_feature)]  | 
 | 30 | +    Some { rust_feature: &'a str },  | 
 | 31 | +    #[help(consider_filing_feature_request)]  | 
 | 32 | +    None,  | 
 | 33 | +}  | 
 | 34 | + | 
 | 35 | +#[derive(Diagnostic)]  | 
 | 36 | +#[diag(codegen_llvm_error_creating_import_library)]  | 
 | 37 | +pub(crate) struct ErrorCreatingImportLibrary<'a> {  | 
 | 38 | +    pub lib_name: &'a str,  | 
 | 39 | +    pub error: String,  | 
 | 40 | +}  | 
 | 41 | + | 
 | 42 | +#[derive(Diagnostic)]  | 
 | 43 | +#[diag(codegen_llvm_instrument_coverage_requires_llvm_12)]  | 
 | 44 | +pub(crate) struct InstrumentCoverageRequiresLLVM12;  | 
 | 45 | + | 
 | 46 | +#[derive(Diagnostic)]  | 
 | 47 | +#[diag(codegen_llvm_symbol_already_defined)]  | 
 | 48 | +pub(crate) struct SymbolAlreadyDefined<'a> {  | 
 | 49 | +    #[primary_span]  | 
 | 50 | +    pub span: Span,  | 
 | 51 | +    pub symbol_name: &'a str,  | 
 | 52 | +}  | 
 | 53 | + | 
 | 54 | +#[derive(Diagnostic)]  | 
 | 55 | +#[diag(codegen_llvm_branch_protection_requires_aarch64)]  | 
 | 56 | +pub(crate) struct BranchProtectionRequiresAArch64;  | 
 | 57 | + | 
 | 58 | +#[derive(Diagnostic)]  | 
 | 59 | +#[diag(codegen_llvm_invalid_minimum_alignment)]  | 
 | 60 | +pub(crate) struct InvalidMinimumAlignment {  | 
 | 61 | +    pub err: String,  | 
 | 62 | +}  | 
 | 63 | + | 
 | 64 | +#[derive(Diagnostic)]  | 
 | 65 | +#[diag(codegen_llvm_linkage_const_or_mut_type)]  | 
 | 66 | +pub(crate) struct LinkageConstOrMutType {  | 
 | 67 | +    #[primary_span]  | 
 | 68 | +    pub span: Span,  | 
 | 69 | +}  | 
 | 70 | + | 
 | 71 | +#[derive(Diagnostic)]  | 
 | 72 | +#[diag(codegen_llvm_sanitizer_memtag_requires_mte)]  | 
 | 73 | +pub(crate) struct SanitizerMemtagRequiresMte;  | 
 | 74 | + | 
 | 75 | +#[derive(Diagnostic)]  | 
 | 76 | +#[diag(codegen_llvm_archive_build_failure)]  | 
 | 77 | +pub(crate) struct ArchiveBuildFailure {  | 
 | 78 | +    pub error: std::io::Error,  | 
 | 79 | +}  | 
 | 80 | + | 
 | 81 | +#[derive(Diagnostic)]  | 
 | 82 | +#[diag(codegen_llvm_error_writing_def_file)]  | 
 | 83 | +pub(crate) struct ErrorWritingDEFFile {  | 
 | 84 | +    pub error: std::io::Error,  | 
 | 85 | +}  | 
 | 86 | + | 
 | 87 | +#[derive(Diagnostic)]  | 
 | 88 | +#[diag(codegen_llvm_error_calling_dlltool)]  | 
 | 89 | +pub(crate) struct ErrorCallingDllTool {  | 
 | 90 | +    pub error: std::io::Error,  | 
 | 91 | +}  | 
 | 92 | + | 
 | 93 | +#[derive(Diagnostic)]  | 
 | 94 | +#[diag(codegen_llvm_dlltool_fail_import_library)]  | 
 | 95 | +pub(crate) struct DlltoolFailImportLibrary<'a> {  | 
 | 96 | +    pub stdout: Cow<'a, str>,  | 
 | 97 | +    pub stderr: Cow<'a, str>,  | 
 | 98 | +}  | 
 | 99 | + | 
 | 100 | +#[derive(Diagnostic)]  | 
 | 101 | +#[diag(codegen_llvm_unknown_archive_kind)]  | 
 | 102 | +pub(crate) struct UnknownArchiveKind<'a> {  | 
 | 103 | +    pub kind: &'a str,  | 
 | 104 | +}  | 
 | 105 | + | 
 | 106 | +#[derive(Diagnostic)]  | 
 | 107 | +#[diag(codegen_llvm_dynamic_linking_with_lto)]  | 
 | 108 | +#[note]  | 
 | 109 | +pub(crate) struct DynamicLinkingWithLTO;  | 
 | 110 | + | 
 | 111 | +#[derive(Diagnostic)]  | 
 | 112 | +#[diag(codegen_llvm_fail_parsing_target_machine_config_to_target_machine)]  | 
 | 113 | +pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {  | 
 | 114 | +    pub error: String,  | 
 | 115 | +}  | 
 | 116 | + | 
 | 117 | +pub(crate) struct TargetFeatureDisableOrEnable<'a> {  | 
 | 118 | +    pub features: &'a [&'a str],  | 
 | 119 | +    pub span: Option<Span>,  | 
 | 120 | +    pub missing_features: Option<MissingFeatures>,  | 
 | 121 | +}  | 
 | 122 | + | 
 | 123 | +#[derive(Subdiagnostic)]  | 
 | 124 | +#[help(codegen_llvm_missing_features)]  | 
 | 125 | +pub(crate) struct MissingFeatures;  | 
 | 126 | + | 
 | 127 | +impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {  | 
 | 128 | +    fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {  | 
 | 129 | +        let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);  | 
 | 130 | +        if let Some(span) = self.span {  | 
 | 131 | +            diag.set_span(span);  | 
 | 132 | +        };  | 
 | 133 | +        if let Some(missing_features) = self.missing_features {  | 
 | 134 | +            diag.subdiagnostic(missing_features);  | 
 | 135 | +        }  | 
 | 136 | +        diag.set_arg("features", self.features.join(", "));  | 
 | 137 | +        diag  | 
 | 138 | +    }  | 
 | 139 | +}  | 
0 commit comments