From 5cf300d695c4ac6e4bdab8fe5c48de6b05b2cd96 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 21 Jul 2021 14:53:13 +0200 Subject: Remove warnings/errors from compiler when using typeck_body in rustdoc span map builder --- compiler/rustc_errors/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 993a7c2c162..fc0924ac5f9 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -342,6 +342,9 @@ struct HandlerInner { deduplicated_warn_count: usize, future_breakage_diagnostics: Vec, + + /// If set to `true`, no warning or error will be emitted. + quiet: bool, } /// A key denoting where from a diagnostic was stashed. @@ -456,10 +459,19 @@ impl Handler { emitted_diagnostics: Default::default(), stashed_diagnostics: Default::default(), future_breakage_diagnostics: Vec::new(), + quiet: false, }), } } + pub fn with_disabled_diagnostic T>(&self, f: F) -> T { + let prev = self.inner.borrow_mut().quiet; + self.inner.borrow_mut().quiet = true; + let ret = f(); + self.inner.borrow_mut().quiet = prev; + ret + } + // This is here to not allow mutation of flags; // as of this writing it's only used in tests in librustc_middle. pub fn can_emit_warnings(&self) -> bool { @@ -818,7 +830,7 @@ impl HandlerInner { } fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) { - if diagnostic.cancelled() { + if diagnostic.cancelled() || self.quiet { return; } @@ -1035,6 +1047,9 @@ impl HandlerInner { } fn delay_as_bug(&mut self, diagnostic: Diagnostic) { + if self.quiet { + return; + } if self.flags.report_delayed_bugs { self.emit_diagnostic(&diagnostic); } -- cgit 1.4.1-3-g733a5