about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2021-07-21 14:53:13 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2021-08-05 23:08:29 +0200
commit5cf300d695c4ac6e4bdab8fe5c48de6b05b2cd96 (patch)
tree8feb20307f70d640afd84d5b54f0200f74cf0a2a
parent0799528db785e49ad13044aac193b8be2153e202 (diff)
downloadrust-5cf300d695c4ac6e4bdab8fe5c48de6b05b2cd96.tar.gz
rust-5cf300d695c4ac6e4bdab8fe5c48de6b05b2cd96.zip
Remove warnings/errors from compiler when using typeck_body in rustdoc span map builder
-rw-r--r--compiler/rustc_errors/src/lib.rs17
-rw-r--r--compiler/rustc_session/src/session.rs4
-rw-r--r--src/librustdoc/html/render/span_map.rs10
3 files changed, 25 insertions, 6 deletions
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<Diagnostic>,
+
+    /// 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, F: FnOnce() -> 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);
         }
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index 9ab6dbb1ea9..fe87867d299 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -500,6 +500,10 @@ impl Session {
         &self.parse_sess.span_diagnostic
     }
 
+    pub fn with_disabled_diagnostic<T, F: FnOnce() -> T>(&self, f: F) -> T {
+        self.parse_sess.span_diagnostic.with_disabled_diagnostic(f)
+    }
+
     /// Analogous to calling methods on the given `DiagnosticBuilder`, but
     /// deduplicates on lint ID, span (if any), and message for this `Session`
     fn diag_once<'a, 'b>(
diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs
index 390ac88faf0..429673c96e7 100644
--- a/src/librustdoc/html/render/span_map.rs
+++ b/src/librustdoc/html/render/span_map.rs
@@ -181,11 +181,11 @@ impl Visitor<'tcx> for SpanMapVisitor<'tcx> {
                 if let Some(hir_id) = segment.hir_id {
                     let hir = self.tcx.hir();
                     let body_id = hir.enclosing_body_owner(hir_id);
-                    // FIXME: this is showing error messages for parts of the code that are not
-                    // compiled (because of cfg)!
-                    let typeck_results = self.tcx.typeck_body(
-                        hir.maybe_body_owned_by(body_id).expect("a body which isn't a body"),
-                    );
+                    let typeck_results = self.tcx.sess.with_disabled_diagnostic(|| {
+                        self.tcx.typeck_body(
+                            hir.maybe_body_owned_by(body_id).expect("a body which isn't a body"),
+                        )
+                    });
                     if let Some(def_id) = typeck_results.type_dependent_def_id(expr.hir_id) {
                         self.matches.insert(
                             LightSpan::new_from_span(method_span),