1- use crate :: errors:: { EmojiIdentifier , FerrisIdentifier } ;
1+ use crate :: errors:: {
2+ CantEmitMIR , EmojiIdentifier , ErrorWritingDependencies , FerrisIdentifier ,
3+ GeneratedFileConflictsWithDirectory , InputFileWouldBeOverWritten , MixedBinCrate ,
4+ MixedProcMacroCrate , OutDirError , ProcMacroDocWithoutArg , TempsDirError ,
5+ } ;
26use crate :: interface:: { Compiler , Result } ;
37use crate :: proc_macro_decls;
48use crate :: util;
@@ -375,10 +379,10 @@ pub fn configure_and_expand(
375379
376380 if crate_types. len ( ) > 1 {
377381 if is_executable_crate {
378- sess. err ( "cannot mix `bin` crate type with others" ) ;
382+ sess. emit_err ( MixedBinCrate ) ;
379383 }
380384 if is_proc_macro_crate {
381- sess. err ( "cannot mix `proc-macro` crate type with others" ) ;
385+ sess. emit_err ( MixedProcMacroCrate ) ;
382386 }
383387 }
384388
@@ -389,13 +393,7 @@ pub fn configure_and_expand(
389393 // However, we do emit a warning, to let such users know that they should
390394 // start passing '--crate-type proc-macro'
391395 if has_proc_macro_decls && sess. opts . actually_rustdoc && !is_proc_macro_crate {
392- let mut msg = sess. diagnostic ( ) . struct_warn (
393- "Trying to document proc macro crate \
394- without passing '--crate-type proc-macro to rustdoc",
395- ) ;
396-
397- msg. warn ( "The generated documentation may be incorrect" ) ;
398- msg. emit ( ) ;
396+ sess. emit_warning ( ProcMacroDocWithoutArg ) ;
399397 } else {
400398 krate = sess. time ( "maybe_create_a_macro_crate" , || {
401399 let is_test_crate = sess. opts . test ;
@@ -649,11 +647,12 @@ fn write_out_deps(
649647 . emit_artifact_notification ( & deps_filename, "dep-info" ) ;
650648 }
651649 }
652- Err ( e) => sess. fatal ( & format ! (
653- "error writing dependencies to `{}`: {}" ,
654- deps_filename. display( ) ,
655- e
656- ) ) ,
650+ Err ( e) => {
651+ sess. emit_fatal ( ErrorWritingDependencies {
652+ path : ( & deps_filename. display ( ) ) . into ( ) ,
653+ error : ( & e) . into ( ) ,
654+ } ) ;
655+ }
657656 }
658657}
659658
@@ -683,29 +682,23 @@ pub fn prepare_outputs(
683682 if let Some ( ref input_path) = compiler. input_path {
684683 if sess. opts . will_create_output_file ( ) {
685684 if output_contains_path ( & output_paths, input_path) {
686- let reported = sess. err ( & format ! (
687- "the input file \" {}\" would be overwritten by the generated \
688- executable",
689- input_path. display( )
690- ) ) ;
685+ let reported = sess
686+ . emit_err ( InputFileWouldBeOverWritten { path : ( & input_path. display ( ) ) . into ( ) } ) ;
691687 return Err ( reported) ;
692688 }
693689 if let Some ( dir_path) = output_conflicts_with_dir ( & output_paths) {
694- let reported = sess. err ( & format ! (
695- "the generated executable for the input file \" {}\" conflicts with the \
696- existing directory \" {}\" ",
697- input_path. display( ) ,
698- dir_path. display( )
699- ) ) ;
690+ let reported = sess. emit_err ( GeneratedFileConflictsWithDirectory {
691+ input_path : ( & input_path. display ( ) ) . into ( ) ,
692+ dir_path : ( & dir_path. display ( ) ) . into ( ) ,
693+ } ) ;
700694 return Err ( reported) ;
701695 }
702696 }
703697 }
704698
705699 if let Some ( ref dir) = compiler. temps_dir {
706700 if fs:: create_dir_all ( dir) . is_err ( ) {
707- let reported =
708- sess. err ( "failed to find or create the directory specified by `--temps-dir`" ) ;
701+ let reported = sess. emit_err ( TempsDirError ) ;
709702 return Err ( reported) ;
710703 }
711704 }
@@ -718,8 +711,7 @@ pub fn prepare_outputs(
718711 if !only_dep_info {
719712 if let Some ( ref dir) = compiler. output_dir {
720713 if fs:: create_dir_all ( dir) . is_err ( ) {
721- let reported =
722- sess. err ( "failed to find or create the directory specified by `--out-dir`" ) ;
714+ let reported = sess. emit_err ( OutDirError ) ;
723715 return Err ( reported) ;
724716 }
725717 }
@@ -1003,7 +995,7 @@ pub fn start_codegen<'tcx>(
1003995
1004996 if tcx. sess . opts . output_types . contains_key ( & OutputType :: Mir ) {
1005997 if let Err ( e) = rustc_mir_transform:: dump_mir:: emit_mir ( tcx, outputs) {
1006- tcx. sess . err ( & format ! ( "could not emit MIR: {}" , e ) ) ;
998+ tcx. sess . emit_err ( CantEmitMIR { error : ( & e ) . into ( ) } ) ;
1007999 tcx. sess . abort_if_errors ( ) ;
10081000 }
10091001 }
0 commit comments