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
+ } ;
2
6
use crate :: interface:: { Compiler , Result } ;
3
7
use crate :: proc_macro_decls;
4
8
use crate :: util;
@@ -375,10 +379,10 @@ pub fn configure_and_expand(
375
379
376
380
if crate_types. len ( ) > 1 {
377
381
if is_executable_crate {
378
- sess. err ( "cannot mix `bin` crate type with others" ) ;
382
+ sess. emit_err ( MixedBinCrate ) ;
379
383
}
380
384
if is_proc_macro_crate {
381
- sess. err ( "cannot mix `proc-macro` crate type with others" ) ;
385
+ sess. emit_err ( MixedProcMacroCrate ) ;
382
386
}
383
387
}
384
388
@@ -389,13 +393,7 @@ pub fn configure_and_expand(
389
393
// However, we do emit a warning, to let such users know that they should
390
394
// start passing '--crate-type proc-macro'
391
395
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 ) ;
399
397
} else {
400
398
krate = sess. time ( "maybe_create_a_macro_crate" , || {
401
399
let is_test_crate = sess. opts . test ;
@@ -649,11 +647,12 @@ fn write_out_deps(
649
647
. emit_artifact_notification ( & deps_filename, "dep-info" ) ;
650
648
}
651
649
}
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
+ }
657
656
}
658
657
}
659
658
@@ -683,29 +682,23 @@ pub fn prepare_outputs(
683
682
if let Some ( ref input_path) = compiler. input_path {
684
683
if sess. opts . will_create_output_file ( ) {
685
684
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 ( ) } ) ;
691
687
return Err ( reported) ;
692
688
}
693
689
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
+ } ) ;
700
694
return Err ( reported) ;
701
695
}
702
696
}
703
697
}
704
698
705
699
if let Some ( ref dir) = compiler. temps_dir {
706
700
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 ) ;
709
702
return Err ( reported) ;
710
703
}
711
704
}
@@ -718,8 +711,7 @@ pub fn prepare_outputs(
718
711
if !only_dep_info {
719
712
if let Some ( ref dir) = compiler. output_dir {
720
713
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 ) ;
723
715
return Err ( reported) ;
724
716
}
725
717
}
@@ -1003,7 +995,7 @@ pub fn start_codegen<'tcx>(
1003
995
1004
996
if tcx. sess . opts . output_types . contains_key ( & OutputType :: Mir ) {
1005
997
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 ( ) } ) ;
1007
999
tcx. sess . abort_if_errors ( ) ;
1008
1000
}
1009
1001
}
0 commit comments