1
+ use crate :: errors:: {
2
+ CantEmitMIR , EmojiIdentifier , ErrorWritingDependencies , FerrisIdentifier ,
3
+ GeneratedFileConflictsWithDirectory , InputFileWouldBeOverWritten , MixedBinCrate ,
4
+ MixedProcMacroCrate , OutDirError , ProcMacroDocWithoutArg , TempsDirError ,
5
+ } ;
1
6
use crate :: interface:: { Compiler , Result } ;
2
7
use crate :: proc_macro_decls;
3
8
use crate :: util;
@@ -13,7 +18,6 @@ use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
13
18
use rustc_hir:: def_id:: StableCrateId ;
14
19
use rustc_hir:: definitions:: Definitions ;
15
20
use rustc_lint:: { BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16
- use rustc_macros:: SessionDiagnostic ;
17
21
use rustc_metadata:: creader:: CStore ;
18
22
use rustc_middle:: arena:: Arena ;
19
23
use rustc_middle:: dep_graph:: DepGraph ;
@@ -31,7 +35,7 @@ use rustc_session::output::filename_for_input;
31
35
use rustc_session:: search_paths:: PathKind ;
32
36
use rustc_session:: { Limit , Session } ;
33
37
use rustc_span:: symbol:: { sym, Symbol } ;
34
- use rustc_span:: { FileName , Span } ;
38
+ use rustc_span:: FileName ;
35
39
use rustc_trait_selection:: traits;
36
40
use rustc_typeck as typeck;
37
41
use tracing:: { info, warn} ;
@@ -264,23 +268,6 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
264
268
}
265
269
}
266
270
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
-
284
271
/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
285
272
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
286
273
/// harness if one is to be provided, injection of a dependency on the
@@ -392,10 +379,10 @@ pub fn configure_and_expand(
392
379
393
380
if crate_types. len ( ) > 1 {
394
381
if is_executable_crate {
395
- sess. err ( "cannot mix `bin` crate type with others" ) ;
382
+ sess. emit_err ( MixedBinCrate ) ;
396
383
}
397
384
if is_proc_macro_crate {
398
- sess. err ( "cannot mix `proc-macro` crate type with others" ) ;
385
+ sess. emit_err ( MixedProcMacroCrate ) ;
399
386
}
400
387
}
401
388
@@ -406,13 +393,7 @@ pub fn configure_and_expand(
406
393
// However, we do emit a warning, to let such users know that they should
407
394
// start passing '--crate-type proc-macro'
408
395
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 ) ;
416
397
} else {
417
398
krate = sess. time ( "maybe_create_a_macro_crate" , || {
418
399
let is_test_crate = sess. opts . test ;
@@ -666,11 +647,9 @@ fn write_out_deps(
666
647
. emit_artifact_notification ( & deps_filename, "dep-info" ) ;
667
648
}
668
649
}
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
+ }
674
653
}
675
654
}
676
655
@@ -700,29 +679,20 @@ pub fn prepare_outputs(
700
679
if let Some ( ref input_path) = compiler. input_path {
701
680
if sess. opts . will_create_output_file ( ) {
702
681
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 } ) ;
708
683
return Err ( reported) ;
709
684
}
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 } ) ;
717
688
return Err ( reported) ;
718
689
}
719
690
}
720
691
}
721
692
722
693
if let Some ( ref dir) = compiler. temps_dir {
723
694
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 ) ;
726
696
return Err ( reported) ;
727
697
}
728
698
}
@@ -735,8 +705,7 @@ pub fn prepare_outputs(
735
705
if !only_dep_info {
736
706
if let Some ( ref dir) = compiler. output_dir {
737
707
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 ) ;
740
709
return Err ( reported) ;
741
710
}
742
711
}
@@ -1019,8 +988,8 @@ pub fn start_codegen<'tcx>(
1019
988
info ! ( "Post-codegen\n {:?}" , tcx. debug_stats( ) ) ;
1020
989
1021
990
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 } ) ;
1024
993
tcx. sess . abort_if_errors ( ) ;
1025
994
}
1026
995
}
0 commit comments