19
19
#![ warn( rustc:: internal) ]
20
20
#![ allow( clippy:: collapsible_if, clippy:: collapsible_else_if) ]
21
21
#![ allow( rustc:: potential_query_instability) ]
22
+ #![ deny( rustc:: untranslatable_diagnostic) ]
23
+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
22
24
23
25
extern crate thin_vec;
24
26
#[ macro_use]
@@ -43,6 +45,7 @@ extern crate rustc_driver;
43
45
extern crate rustc_errors;
44
46
extern crate rustc_expand;
45
47
extern crate rustc_feature;
48
+ extern crate rustc_fluent_macro;
46
49
extern crate rustc_hir;
47
50
extern crate rustc_hir_analysis;
48
51
extern crate rustc_hir_pretty;
@@ -74,15 +77,18 @@ use std::env::{self, VarError};
74
77
use std:: io:: { self , IsTerminal } ;
75
78
use std:: process;
76
79
80
+ use errors:: { CouldntGenerateDocumentation , MainError } ;
77
81
use rustc_driver:: abort_on_err;
78
- use rustc_errors:: ErrorGuaranteed ;
82
+ use rustc_errors:: { DiagnosticMessage , ErrorGuaranteed , SubdiagnosticMessage } ;
83
+ use rustc_fluent_macro:: fluent_messages;
79
84
use rustc_interface:: interface;
80
85
use rustc_middle:: ty:: TyCtxt ;
81
86
use rustc_session:: config:: { make_crate_type_option, ErrorOutputType , RustcOptGroup } ;
82
87
use rustc_session:: getopts;
83
88
use rustc_session:: { early_error, early_warn} ;
84
89
85
90
use crate :: clean:: utils:: DOC_RUST_LANG_ORG_CHANNEL ;
91
+ use crate :: errors:: CompilationFailed ;
86
92
87
93
/// A macro to create a FxHashMap.
88
94
///
@@ -108,6 +114,7 @@ mod core;
108
114
mod docfs;
109
115
mod doctest;
110
116
mod error;
117
+ mod errors;
111
118
mod externalfiles;
112
119
mod fold;
113
120
mod formats;
@@ -123,6 +130,8 @@ mod visit;
123
130
mod visit_ast;
124
131
mod visit_lib;
125
132
133
+ fluent_messages ! { "./messages.ftl" }
134
+
126
135
pub fn main ( ) {
127
136
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
128
137
// about jemalloc.
@@ -683,10 +692,7 @@ type MainResult = Result<(), ErrorGuaranteed>;
683
692
fn wrap_return ( diag : & rustc_errors:: Handler , res : Result < ( ) , String > ) -> MainResult {
684
693
match res {
685
694
Ok ( ( ) ) => diag. has_errors ( ) . map_or ( Ok ( ( ) ) , Err ) ,
686
- Err ( err) => {
687
- let reported = diag. struct_err ( err) . emit ( ) ;
688
- Err ( reported)
689
- }
695
+ Err ( error) => Err ( diag. emit_err ( MainError { error } ) ) ,
690
696
}
691
697
}
692
698
@@ -698,15 +704,10 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
698
704
) -> MainResult {
699
705
match formats:: run_format :: < T > ( krate, renderopts, cache, tcx) {
700
706
Ok ( _) => tcx. sess . has_errors ( ) . map_or ( Ok ( ( ) ) , Err ) ,
701
- Err ( e) => {
702
- let mut msg =
703
- tcx. sess . struct_err ( format ! ( "couldn't generate documentation: {}" , e. error) ) ;
704
- let file = e. file . display ( ) . to_string ( ) ;
705
- if !file. is_empty ( ) {
706
- msg. note ( format ! ( "failed to create or modify \" {}\" " , file) ) ;
707
- }
708
- Err ( msg. emit ( ) )
709
- }
707
+ Err ( e) => Err ( tcx. sess . emit_err ( CouldntGenerateDocumentation {
708
+ error : e. error ,
709
+ file : e. file . display ( ) . to_string ( ) ,
710
+ } ) ) ,
710
711
}
711
712
}
712
713
@@ -817,7 +818,7 @@ fn main_args(at_args: &[String]) -> MainResult {
817
818
compiler. enter ( |queries| {
818
819
let mut gcx = abort_on_err ( queries. global_ctxt ( ) , sess) ;
819
820
if sess. diagnostic ( ) . has_errors_or_lint_errors ( ) . is_some ( ) {
820
- sess. fatal ( "Compilation failed, aborting rustdoc" ) ;
821
+ sess. emit_fatal ( CompilationFailed ) ;
821
822
}
822
823
823
824
gcx. enter ( |tcx| {
0 commit comments