Skip to content

Commit 9f0c165

Browse files
committed
Port symbol_already_defined error
1 parent 4c625dc commit 9f0c165

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

compiler/rustc_codegen_llvm/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_errors::fluent;
22
use rustc_errors::DiagnosticBuilder;
33
use rustc_macros::SessionDiagnostic;
44
use rustc_session::SessionDiagnostic;
5+
use rustc_span::Span;
56

67
pub(crate) enum UnknownCTargetFeature<'a> {
78
UnknownFeaturePrefix { feature: &'a str },
@@ -46,3 +47,11 @@ pub(crate) struct ErrorCreatingImportLibrary<'a> {
4647
#[derive(SessionDiagnostic)]
4748
#[diag(codegen_llvm::instrument_coverage_requires_llvm_12)]
4849
pub(crate) struct InstrumentCoverageRequiresLLVM12;
50+
51+
#[derive(SessionDiagnostic)]
52+
#[diag(codegen_llvm::SymbolAlreadyDefined)]
53+
pub(crate) struct SymbolAlreadyDefined<'a> {
54+
#[primary_span]
55+
pub span: Span,
56+
pub symbol_name: &'a str,
57+
}

compiler/rustc_codegen_llvm/src/mono_item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> {
2525
let llty = self.layout_of(ty).llvm_type(self);
2626

2727
let g = self.define_global(symbol_name, llty).unwrap_or_else(|| {
28-
self.sess().span_fatal(
29-
self.tcx.def_span(def_id),
30-
&format!("symbol `{}` is already defined", symbol_name),
31-
)
28+
self.sess().emit_fatal(SymbolAlreadyDefined { span: self.tcx.def_span(def_id), symbol_name })
3229
});
3330

3431
unsafe {

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

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ codegen_llvm_error_creating_import_library =
1818
1919
codegen_llvm_instrument_coverage_requires_llvm_12 =
2020
rustc option `-C instrument-coverage` requires LLVM 12 or higher.
21+
22+
codegen_llvm_symbol_already_defined =
23+
symbol `{$symbol_name}` is already defined

0 commit comments

Comments
 (0)