Skip to content

Commit 3728e95

Browse files
committed
Port diagnostics created by Handler
1 parent 67394e7 commit 3728e95

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::back::write::{self, save_temp_bitcode, DiagnosticHandlers};
2+
use crate::errors::DynamicLinkingWithLTO;
23
use crate::llvm::{self, build_string};
34
use crate::{LlvmCodegenBackend, ModuleLlvm};
45
use object::read::archive::ArchiveFile;
@@ -90,13 +91,7 @@ fn prepare_lto(
9091
}
9192

9293
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
93-
diag_handler
94-
.struct_err("cannot prefer dynamic linking when performing LTO")
95-
.note(
96-
"only 'staticlib', 'bin', and 'cdylib' outputs are \
97-
supported with LTO",
98-
)
99-
.emit();
94+
diag_handler.emit_err(DynamicLinkingWithLTO);
10095
return Err(FatalError);
10196
}
10297

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ pub(crate) struct UnknownArchiveKind<'a> {
117117
pub kind: &'a str,
118118
}
119119

120+
#[derive(Diagnostic)]
121+
#[diag(codegen_llvm_dynamic_linking_with_lto)]
122+
#[note]
123+
pub(crate) struct DynamicLinkingWithLTO;
124+
125+
#[derive(Diagnostic)]
126+
#[diag(codegen_llvm_fail_parsing_target_machine_config_to_target_machine)]
127+
pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {
128+
pub error: String,
129+
}
130+
120131
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
121132
pub features: &'a [&'a str],
122133
pub span: Option<Span>,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#![feature(iter_intersperse)]
1313
#![recursion_limit = "256"]
1414
#![allow(rustc::potential_query_instability)]
15+
#![deny(rustc::untranslatable_diagnostic)]
16+
#![deny(rustc::diagnostic_outside_of_impl)]
1517

1618
#[macro_use]
1719
extern crate rustc_macros;
@@ -20,6 +22,7 @@ extern crate tracing;
2022

2123
use back::write::{create_informational_target_machine, create_target_machine};
2224

25+
use errors::FailParsingTargetMachineConfigToTargetMachine;
2326
pub use llvm_util::target_features;
2427
use rustc_ast::expand::allocator::AllocatorKind;
2528
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
@@ -413,7 +416,7 @@ impl ModuleLlvm {
413416
let tm = match (cgcx.tm_factory)(tm_factory_config) {
414417
Ok(m) => m,
415418
Err(e) => {
416-
handler.struct_err(&e).emit();
419+
handler.emit_err(FailParsingTargetMachineConfigToTargetMachine { error: e });
417420
return Err(FatalError);
418421
}
419422
};

compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ codegen_llvm_target_feature_disable_or_enable =
5757
5858
codegen_llvm_missing_features =
5959
add the missing features in a `target_feature` attribute
60+
61+
codegen_llvm_dynamic_linking_with_lto =
62+
cannot prefer dynamic linking when performing LTO
63+
.note = only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
64+
65+
codegen_llvm_fail_parsing_target_machine_config_to_target_machine =
66+
failed to parse target machine config to target machine: {$error}

0 commit comments

Comments
 (0)