UPDATE - migrate base.rs to new diagnostics infrastructure

This commit is contained in:
Jhonny Bill Mena 2022-11-16 20:08:14 -05:00
parent 739d68a76e
commit 82cf6f204a
3 changed files with 32 additions and 11 deletions

View File

@ -5,6 +5,7 @@
submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen, submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen,
}; };
use crate::common::{IntPredicate, RealPredicate, TypeKind}; use crate::common::{IntPredicate, RealPredicate, TypeKind};
use crate::errors;
use crate::meth; use crate::meth;
use crate::mir; use crate::mir;
use crate::mir::operand::OperandValue; use crate::mir::operand::OperandValue;
@ -451,10 +452,7 @@ fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let Some(llfn) = cx.declare_c_main(llfty) else { let Some(llfn) = cx.declare_c_main(llfty) else {
// FIXME: We should be smart and show a better diagnostic here. // FIXME: We should be smart and show a better diagnostic here.
let span = cx.tcx().def_span(rust_main_def_id); let span = cx.tcx().def_span(rust_main_def_id);
cx.sess() cx.sess().emit_err(errors::MultipleMainFunctions { span });
.struct_span_err(span, "entry symbol `main` declared multiple times")
.help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead")
.emit();
cx.sess().abort_if_errors(); cx.sess().abort_if_errors();
bug!(); bug!();
}; };
@ -595,8 +593,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
&metadata, &metadata,
&exported_symbols::metadata_symbol_name(tcx), &exported_symbols::metadata_symbol_name(tcx),
); );
if let Err(err) = std::fs::write(&file_name, data) { if let Err(error) = std::fs::write(&file_name, data) {
tcx.sess.fatal(&format!("error writing metadata object file: {}", err)); tcx.sess.emit_fatal(errors::MetadataObjectFileWrite { error });
} }
Some(CompiledModule { Some(CompiledModule {
name: metadata_cgu_name, name: metadata_cgu_name,
@ -815,11 +813,7 @@ pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo {
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem); let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
let windows_subsystem = subsystem.map(|subsystem| { let windows_subsystem = subsystem.map(|subsystem| {
if subsystem != sym::windows && subsystem != sym::console { if subsystem != sym::windows && subsystem != sym::console {
tcx.sess.fatal(&format!( tcx.sess.emit_fatal(errors::InvalidWindowsSubsystem { subsystem });
"invalid windows subsystem `{}`, only \
`windows` and `console` are allowed",
subsystem
));
} }
subsystem.to_string() subsystem.to_string()
}); });

View File

@ -555,3 +555,23 @@ pub struct ExpectedUsedSymbol {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)]
#[diag(codegen_ssa_multiple_main_functions)]
#[help]
pub struct MultipleMainFunctions {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(codegen_ssa_metadata_object_file_write)]
pub struct MetadataObjectFileWrite {
pub error: Error,
}
#[derive(Diagnostic)]
#[diag(codegen_ssa_invalid_windows_subsystem)]
pub struct InvalidWindowsSubsystem {
pub subsystem: Symbol,
}

View File

@ -194,3 +194,10 @@ codegen_ssa_unknown_archive_kind =
Don't know how to build archive of type: {$kind} Don't know how to build archive of type: {$kind}
codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)` codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`
codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple times
.help = did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead
codegen_ssa_metadata_object_file_write = error writing metadata object file: {$error}
codegen_ssa_invalid_windows_subsystem = invalid windows subsystem `{$subsystem}`, only `windows` and `console` are allowed