1+ use crate :: errors:: {
2+ CantEmitMIR , EmojiIdentifier , ErrorWritingDependencies , FerrisIdentifier ,
3+ GeneratedFileConflictsWithDirectory , InputFileWouldBeOverWritten , MixedBinCrate ,
4+ MixedProcMacroCrate , OutDirError , ProcMacroDocWithoutArg , TempsDirError ,
5+ } ;
16use crate :: interface:: { Compiler , Result } ;
27use crate :: proc_macro_decls;
38use crate :: util;
@@ -13,7 +18,6 @@ use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
1318use rustc_hir:: def_id:: StableCrateId ;
1419use rustc_hir:: definitions:: Definitions ;
1520use rustc_lint:: { BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16- use rustc_macros:: SessionDiagnostic ;
1721use rustc_metadata:: creader:: CStore ;
1822use rustc_middle:: arena:: Arena ;
1923use rustc_middle:: dep_graph:: DepGraph ;
@@ -31,7 +35,7 @@ use rustc_session::output::filename_for_input;
3135use rustc_session:: search_paths:: PathKind ;
3236use rustc_session:: { Limit , Session } ;
3337use rustc_span:: symbol:: { sym, Symbol } ;
34- use rustc_span:: { FileName , Span } ;
38+ use rustc_span:: FileName ;
3539use rustc_trait_selection:: traits;
3640use rustc_typeck as typeck;
3741use tracing:: { info, warn} ;
@@ -264,23 +268,6 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
264268 }
265269}
266270
267- #[ derive( SessionDiagnostic ) ]
268- #[ diag( interface:: ferris_identifier) ]
269- struct FerrisIdentifier {
270- #[ primary_span]
271- spans : Vec < Span > ,
272- #[ suggestion( code = "ferris" , applicability = "maybe-incorrect" ) ]
273- first_span : Span ,
274- }
275-
276- #[ derive( SessionDiagnostic ) ]
277- #[ diag( interface:: emoji_identifier) ]
278- struct EmojiIdentifier {
279- #[ primary_span]
280- spans : Vec < Span > ,
281- ident : Symbol ,
282- }
283-
284271/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
285272/// syntax expansion, secondary `cfg` expansion, synthesis of a test
286273/// harness if one is to be provided, injection of a dependency on the
@@ -392,10 +379,10 @@ pub fn configure_and_expand(
392379
393380 if crate_types. len ( ) > 1 {
394381 if is_executable_crate {
395- sess. err ( "cannot mix `bin` crate type with others" ) ;
382+ sess. emit_err ( MixedBinCrate ) ;
396383 }
397384 if is_proc_macro_crate {
398- sess. err ( "cannot mix `proc-macro` crate type with others" ) ;
385+ sess. emit_err ( MixedProcMacroCrate ) ;
399386 }
400387 }
401388
@@ -406,13 +393,7 @@ pub fn configure_and_expand(
406393 // However, we do emit a warning, to let such users know that they should
407394 // start passing '--crate-type proc-macro'
408395 if has_proc_macro_decls && sess. opts . actually_rustdoc && !is_proc_macro_crate {
409- let mut msg = sess. diagnostic ( ) . struct_warn (
410- "Trying to document proc macro crate \
411- without passing '--crate-type proc-macro to rustdoc",
412- ) ;
413-
414- msg. warn ( "The generated documentation may be incorrect" ) ;
415- msg. emit ( ) ;
396+ sess. emit_warning ( ProcMacroDocWithoutArg ) ;
416397 } else {
417398 krate = sess. time ( "maybe_create_a_macro_crate" , || {
418399 let is_test_crate = sess. opts . test ;
@@ -666,11 +647,9 @@ fn write_out_deps(
666647 . emit_artifact_notification ( & deps_filename, "dep-info" ) ;
667648 }
668649 }
669- Err ( e) => sess. fatal ( & format ! (
670- "error writing dependencies to `{}`: {}" ,
671- deps_filename. display( ) ,
672- e
673- ) ) ,
650+ Err ( error) => {
651+ sess. emit_fatal ( ErrorWritingDependencies { path : & deps_filename, error } ) ;
652+ }
674653 }
675654}
676655
@@ -700,29 +679,20 @@ pub fn prepare_outputs(
700679 if let Some ( ref input_path) = compiler. input_path {
701680 if sess. opts . will_create_output_file ( ) {
702681 if output_contains_path ( & output_paths, input_path) {
703- let reported = sess. err ( & format ! (
704- "the input file \" {}\" would be overwritten by the generated \
705- executable",
706- input_path. display( )
707- ) ) ;
682+ let reported = sess. emit_err ( InputFileWouldBeOverWritten { path : input_path } ) ;
708683 return Err ( reported) ;
709684 }
710- if let Some ( dir_path) = output_conflicts_with_dir ( & output_paths) {
711- let reported = sess. err ( & format ! (
712- "the generated executable for the input file \" {}\" conflicts with the \
713- existing directory \" {}\" ",
714- input_path. display( ) ,
715- dir_path. display( )
716- ) ) ;
685+ if let Some ( ref dir_path) = output_conflicts_with_dir ( & output_paths) {
686+ let reported =
687+ sess. emit_err ( GeneratedFileConflictsWithDirectory { input_path, dir_path } ) ;
717688 return Err ( reported) ;
718689 }
719690 }
720691 }
721692
722693 if let Some ( ref dir) = compiler. temps_dir {
723694 if fs:: create_dir_all ( dir) . is_err ( ) {
724- let reported =
725- sess. err ( "failed to find or create the directory specified by `--temps-dir`" ) ;
695+ let reported = sess. emit_err ( TempsDirError ) ;
726696 return Err ( reported) ;
727697 }
728698 }
@@ -735,8 +705,7 @@ pub fn prepare_outputs(
735705 if !only_dep_info {
736706 if let Some ( ref dir) = compiler. output_dir {
737707 if fs:: create_dir_all ( dir) . is_err ( ) {
738- let reported =
739- sess. err ( "failed to find or create the directory specified by `--out-dir`" ) ;
708+ let reported = sess. emit_err ( OutDirError ) ;
740709 return Err ( reported) ;
741710 }
742711 }
@@ -1019,8 +988,8 @@ pub fn start_codegen<'tcx>(
1019988 info ! ( "Post-codegen\n {:?}" , tcx. debug_stats( ) ) ;
1020989
1021990 if tcx. sess . opts . output_types . contains_key ( & OutputType :: Mir ) {
1022- if let Err ( e ) = rustc_mir_transform:: dump_mir:: emit_mir ( tcx, outputs) {
1023- tcx. sess . err ( & format ! ( "could not emit MIR: {}" , e ) ) ;
991+ if let Err ( error ) = rustc_mir_transform:: dump_mir:: emit_mir ( tcx, outputs) {
992+ tcx. sess . emit_err ( CantEmitMIR { error } ) ;
1024993 tcx. sess . abort_if_errors ( ) ;
1025994 }
1026995 }
0 commit comments