From 4ee2d0351a67e382f56a85eaeada0b7c773f0691 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 31 Oct 2021 21:05:09 -0700 Subject: [PATCH] Fix FIXMEs in `rustdoc::html::sources` One of the FIXMEs is irrelevant since that code is only run if `include_sources` is set. I fixed the other FIXME. --- src/librustdoc/html/sources.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 0a9f9741d7bd..30ec592ba23d 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -85,8 +85,6 @@ impl DocVisitor for LocalSourcesCollector<'_, '_> { fn visit_item(&mut self, item: &clean::Item) { self.add_local_source(item); - // FIXME: if `include_sources` isn't set and DocFolder didn't require consuming the crate by value, - // we could return None here without having to walk the rest of the crate. self.visit_item_recur(item) } } @@ -102,6 +100,10 @@ struct SourceCollector<'a, 'tcx> { impl DocVisitor for SourceCollector<'_, '_> { fn visit_item(&mut self, item: &clean::Item) { + if !self.cx.include_sources { + return; + } + let tcx = self.cx.tcx(); let span = item.span(tcx); let sess = tcx.sess; @@ -109,7 +111,7 @@ impl DocVisitor for SourceCollector<'_, '_> { // If we're not rendering sources, there's nothing to do. // If we're including source files, and we haven't seen this file yet, // then we need to render it out to the filesystem. - if self.cx.include_sources && is_real_and_local(span, sess) { + if is_real_and_local(span, sess) { let filename = span.filename(sess); let span = span.inner(); let pos = sess.source_map().lookup_source_file(span.lo()); @@ -134,8 +136,7 @@ impl DocVisitor for SourceCollector<'_, '_> { } }; } - // FIXME: if `include_sources` isn't set and DocFolder didn't require consuming the crate by value, - // we could return None here without having to walk the rest of the crate. + self.visit_item_recur(item) } }