Skip to content

Commit 82cf6f2

Browse files
committed
UPDATE - migrate base.rs to new diagnostics infrastructure
1 parent 739d68a commit 82cf6f2

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 5 additions & 11 deletions
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;
@@ -451,10 +452,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
451452
let Some(llfn) = cx.declare_c_main(llfty) else {
452453
// FIXME: We should be smart and show a better diagnostic here.
453454
let span = cx.tcx().def_span(rust_main_def_id);
454-
cx.sess()
455-
.struct_span_err(span, "entry symbol `main` declared multiple times")
456-
.help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead")
457-
.emit();
455+
cx.sess().emit_err(errors::MultipleMainFunctions { span });
458456
cx.sess().abort_if_errors();
459457
bug!();
460458
};
@@ -595,8 +593,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
595593
&metadata,
596594
&exported_symbols::metadata_symbol_name(tcx),
597595
);
598-
if let Err(err) = std::fs::write(&file_name, data) {
599-
tcx.sess.fatal(&format!("error writing metadata object file: {}", err));
596+
if let Err(error) = std::fs::write(&file_name, data) {
597+
tcx.sess.emit_fatal(errors::MetadataObjectFileWrite { error });
600598
}
601599
Some(CompiledModule {
602600
name: metadata_cgu_name,
@@ -815,11 +813,7 @@ impl CrateInfo {
815813
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
816814
let windows_subsystem = subsystem.map(|subsystem| {
817815
if subsystem != sym::windows && subsystem != sym::console {
818-
tcx.sess.fatal(&format!(
819-
"invalid windows subsystem `{}`, only \
820-
`windows` and `console` are allowed",
821-
subsystem
822-
));
816+
tcx.sess.emit_fatal(errors::InvalidWindowsSubsystem { subsystem });
823817
}
824818
subsystem.to_string()
825819
});

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,23 @@ pub struct ExpectedUsedSymbol {
555555
#[primary_span]
556556
pub span: Span,
557557
}
558+
559+
#[derive(Diagnostic)]
560+
#[diag(codegen_ssa_multiple_main_functions)]
561+
#[help]
562+
pub struct MultipleMainFunctions {
563+
#[primary_span]
564+
pub span: Span,
565+
}
566+
567+
#[derive(Diagnostic)]
568+
#[diag(codegen_ssa_metadata_object_file_write)]
569+
pub struct MetadataObjectFileWrite {
570+
pub error: Error,
571+
}
572+
573+
#[derive(Diagnostic)]
574+
#[diag(codegen_ssa_invalid_windows_subsystem)]
575+
pub struct InvalidWindowsSubsystem {
576+
pub subsystem: Symbol,
577+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,10 @@ codegen_ssa_unknown_archive_kind =
194194
Don't know how to build archive of type: {$kind}
195195
196196
codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`
197+
198+
codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple times
199+
.help = did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead
200+
201+
codegen_ssa_metadata_object_file_write = error writing metadata object file: {$error}
202+
203+
codegen_ssa_invalid_windows_subsystem = invalid windows subsystem `{$subsystem}`, only `windows` and `console` are allowed

0 commit comments

Comments
 (0)