about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorRoccoDev <roccodev.business@gmail.com>2020-03-11 16:30:09 +0100
committerRoccoDev <roccodev.business@gmail.com>2020-04-11 16:15:24 +0200
commitb85c64c3ea147cadc6014fdea710718a8a153b6b (patch)
tree2a0cb385a81db48176799ebb1707dd6d60fc96c9 /src/librustc_errors
parent1f3b65921effc08ea1171bdbbcad70765ecacb22 (diff)
rustc: Add a warning count upon completion
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/lib.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 204fea58c95..55eb9fd566d 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -312,6 +312,9 @@ struct HandlerInner {
     /// The stashed diagnostics count towards the total error count.
     /// When `.abort_if_errors()` is called, these are also emitted.
     stashed_diagnostics: FxIndexMap<(Span, StashKey), Diagnostic>,
+
+    /// The warning count, used for a recap upon finishing
+    deduplicated_warn_count: usize,
 }
 
 /// A key denoting where from a diagnostic was stashed.
@@ -414,6 +417,7 @@ impl Handler {
                 flags,
                 err_count: 0,
                 deduplicated_err_count: 0,
+                deduplicated_warn_count: 0,
                 emitter,
                 delayed_span_bugs: Vec::new(),
                 taught_diagnostics: Default::default(),
@@ -439,6 +443,7 @@ impl Handler {
         let mut inner = self.inner.borrow_mut();
         inner.err_count = 0;
         inner.deduplicated_err_count = 0;
+        inner.deduplicated_warn_count = 0;
 
         // actually free the underlying memory (which `clear` would not do)
         inner.delayed_span_bugs = Default::default();
@@ -745,6 +750,8 @@ impl HandlerInner {
             self.emitter.emit_diagnostic(diagnostic);
             if diagnostic.is_error() {
                 self.deduplicated_err_count += 1;
+            } else if diagnostic.level == Warning {
+                self.deduplicated_warn_count += 1;
             }
         }
         if diagnostic.is_error() {
@@ -763,8 +770,13 @@ impl HandlerInner {
     fn print_error_count(&mut self, registry: &Registry) {
         self.emit_stashed_diagnostics();
 
-        let s = match self.deduplicated_err_count {
-            0 => return,
+        let warnings = match self.deduplicated_warn_count {
+            0 => String::new(),
+            1 => "1 warning emitted".to_string(),
+            count => format!("{} warnings emitted", count),
+        };
+        let errors = match self.deduplicated_err_count {
+            0 => String::new(),
             1 => "aborting due to previous error".to_string(),
             count => format!("aborting due to {} previous errors", count),
         };
@@ -772,7 +784,16 @@ impl HandlerInner {
             return;
         }
 
-        let _ = self.fatal(&s);
+        match (errors.len(), warnings.len()) {
+            (0, 0) => return,
+            (0, _) => self.emit_diagnostic(&Diagnostic::new(Level::Warning, &warnings)),
+            (_, 0) => {
+                let _ = self.fatal(&errors);
+            }
+            (_, _) => {
+                let _ = self.fatal(&format!("{}; {}", &errors, &warnings));
+            }
+        }
 
         let can_show_explain = self.emitter.should_show_explain();
         let are_there_diagnostics = !self.emitted_diagnostic_codes.is_empty();