Skip to content

Commit 53fabd3

Browse files
committed
UPDATE - migrate base.rs to new diagnostics infrastructure
1 parent 36db030 commit 53fabd3

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

compiler/rustc_codegen_ssa/src/base.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::back::write::{
55
submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen,
66
};
77
use crate::common::{IntPredicate, RealPredicate, TypeKind};
8+
use crate::errors;
89
use crate::meth;
910
use crate::mir;
1011
use crate::mir::operand::OperandValue;
@@ -452,10 +453,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
452453
let Some(llfn) = cx.declare_c_main(llfty) else {
453454
// FIXME: We should be smart and show a better diagnostic here.
454455
let span = cx.tcx().def_span(rust_main_def_id);
455-
cx.sess()
456-
.struct_span_err(span, "entry symbol `main` declared multiple times")
457-
.help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead")
458-
.emit();
456+
cx.sess().emit_err(errors::MultipleMainFunctions { span });
459457
cx.sess().abort_if_errors();
460458
bug!();
461459
};
@@ -596,8 +594,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
596594
&metadata,
597595
&exported_symbols::metadata_symbol_name(tcx),
598596
);
599-
if let Err(err) = std::fs::write(&file_name, data) {
600-
tcx.sess.fatal(&format!("error writing metadata object file: {}", err));
597+
if let Err(error) = std::fs::write(&file_name, data) {
598+
tcx.sess.emit_fatal(errors::MetadataObjectFileWrite { error });
601599
}
602600
Some(CompiledModule {
603601
name: metadata_cgu_name,
@@ -816,11 +814,7 @@ impl CrateInfo {
816814
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
817815
let windows_subsystem = subsystem.map(|subsystem| {
818816
if subsystem != sym::windows && subsystem != sym::console {
819-
tcx.sess.fatal(&format!(
820-
"invalid windows subsystem `{}`, only \
821-
`windows` and `console` are allowed",
822-
subsystem
823-
));
817+
tcx.sess.emit_fatal(errors::InvalidWindowsSubsystem { subsystem });
824818
}
825819
subsystem.to_string()
826820
});

compiler/rustc_codegen_ssa/src/errors.rs

+20
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,23 @@ pub struct ReadFileError {
534534
#[derive(Diagnostic)]
535535
#[diag(codegen_ssa_unsupported_link_self_contained)]
536536
pub struct UnsupportedLinkSelfContained;
537+
538+
#[derive(Diagnostic)]
539+
#[diag(codegen_ssa_multiple_main_functions)]
540+
#[help]
541+
pub struct MultipleMainFunctions {
542+
#[primary_span]
543+
pub span: Span,
544+
}
545+
546+
#[derive(Diagnostic)]
547+
#[diag(codegen_ssa_metadata_object_file_write)]
548+
pub struct MetadataObjectFileWrite {
549+
pub error: Error,
550+
}
551+
552+
#[derive(Diagnostic)]
553+
#[diag(codegen_ssa_invalid_windows_subsystem)]
554+
pub struct InvalidWindowsSubsystem {
555+
pub subsystem: Symbol,
556+
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,10 @@ codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {erro
186186
codegen_ssa_read_file = failed to read file: {message}
187187
188188
codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target
189+
190+
codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple times
191+
.help = did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead
192+
193+
codegen_ssa_metadata_object_file_write = error writing metadata object file: {$error}
194+
195+
codegen_ssa_invalid_windows_subsystem = invalid windows subsystem `{$subsystem}`, only `windows` and `console` are allowed

0 commit comments

Comments
 (0)