]> git.lizzy.rs Git - rust.git/commitdiff
Add -Z dont-buffer-diagnostics, a way to force NLL to immediately emit its diagnostics.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Sat, 15 Sep 2018 04:27:55 +0000 (06:27 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Mon, 17 Sep 2018 12:30:01 +0000 (14:30 +0200)
This is mainly intended for `rustc` developers who want to see a
diagnostic in its original context in the control flow.  Two uses
cases for that are:

 * `-Z treat-err-as-bug` which then allows extraction of a stack-trace to the origin of the error
   (a case that is so important that we make that flag imply this one, effectively).

 * `RUST_LOG=... rustc`, in which case it is often useful to see the logging statements that
   occurred immediately prior to the point where the diagnostic was signalled.

Drive-by: Added some documentation pointing future devs at
HandlerFlags, and documented the fields of `HandlerFlags` itself.

src/librustc/session/config.rs
src/librustc/session/mod.rs
src/librustc_errors/diagnostic_builder.rs
src/librustc_errors/lib.rs

index 2a9732bf02c98616acee6bf36ba8baadf1f387a3..25698129d82b38cee1f933003e9e50894a1d37b3 100644 (file)
@@ -1331,6 +1331,8 @@ fn parse_cross_lang_lto(slot: &mut CrossLangLto, v: Option<&str>) -> bool {
         "disable user provided type assertion in NLL"),
     nll_dont_emit_read_for_match: bool = (false, parse_bool, [UNTRACKED],
         "in match codegen, do not include ReadForMatch statements (used by mir-borrowck)"),
+    dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
+        "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting)."),
     polonius: bool = (false, parse_bool, [UNTRACKED],
         "enable polonius-based borrow-checker"),
     codegen_time_graph: bool = (false, parse_bool, [UNTRACKED],
index 619262abb0bf5f5c749840bfbe481960a4701dff..52e1ab477038d9b1906991f8dd285be0d7b7a9ab 100644 (file)
@@ -1012,6 +1012,7 @@ pub fn build_session_with_source_map(
     let can_emit_warnings = !(warnings_allow || cap_lints_allow);
 
     let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
+    let dont_buffer_diagnostics = sopts.debugging_opts.dont_buffer_diagnostics;
     let report_delayed_bugs = sopts.debugging_opts.report_delayed_bugs;
 
     let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
@@ -1059,6 +1060,7 @@ pub fn build_session_with_source_map(
             can_emit_warnings,
             treat_err_as_bug,
             report_delayed_bugs,
+            dont_buffer_diagnostics,
             external_macro_backtrace,
             ..Default::default()
         },
index 1b34898b99084e20f6ddf15b46080f1666d3d8fe..5e962a4af32f6de741db62fcb5748ba3f522ff8b 100644 (file)
 use syntax_pos::{MultiSpan, Span};
 
 /// Used for emitting structured error messages and other diagnostic information.
+///
+/// If there is some state in a downstream crate you would like to
+/// access in the methods of `DiagnosticBuilder` here, consider
+/// extending `HandlerFlags`, accessed via `self.handler.flags`.
 #[must_use]
 #[derive(Clone)]
 pub struct DiagnosticBuilder<'a> {
@@ -89,8 +93,14 @@ pub fn emit(&mut self) {
         self.cancel();
     }
 
-    /// Buffers the diagnostic for later emission.
-    pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
+    /// Buffers the diagnostic for later emission, unless handler
+    /// has disabled such buffering.
+    pub fn buffer(mut self, buffered_diagnostics: &mut Vec<Diagnostic>) {
+        if self.handler.flags.dont_buffer_diagnostics || self.handler.flags.treat_err_as_bug {
+            self.emit();
+            return;
+        }
+
         // We need to use `ptr::read` because `DiagnosticBuilder`
         // implements `Drop`.
         let diagnostic;
index 3582c2359c8b9f653f5ed5d27148f2845e18e801..d0ea6fba5ebb31ac60e59d098f9d1383d58fb681 100644 (file)
@@ -303,9 +303,20 @@ fn default_track_diagnostic(_: &Diagnostic) {}
 
 #[derive(Default)]
 pub struct HandlerFlags {
+    /// If false, warning-level lints are suppressed.
+    /// (rustc: see `--allow warnings` and `--cap-lints`)
     pub can_emit_warnings: bool,
+    /// If true, error-level diagnostics are upgraded to bug-level.
+    /// (rustc: see `-Z treat-err-as-bug`)
     pub treat_err_as_bug: bool,
+    /// If true, immediately emit diagnostics that would otherwise be buffered.
+    /// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
+    pub dont_buffer_diagnostics: bool,
+    /// If true, immediately print bugs registered with `delay_span_bug`.
+    /// (rustc: see `-Z report-delayed-bugs`)
     pub report_delayed_bugs: bool,
+    /// show macro backtraces even for non-local macros.
+    /// (rustc: see `-Z external-macro-backtrace`)
     pub external_macro_backtrace: bool,
 }