Skip to content

Commit 40ca352

Browse files
committed
rustdoc: Don't generate blanket impls when running --show-coverage
get_blanket_impls is the slowest part of rustdoc, and the coverage pass completely ignores blanket impls. This stops running it at all, and also removes some unnecessary checks in `calculate_doc_coverage` that ignored the impl anyway. We don't currently measure --show-coverage in perf.rlo, but I tested this locally on cargo and it brought the time down from 2.9 to 1.6 seconds.
1 parent 69e1d22 commit 40ca352

File tree

3 files changed

+8
-44
lines changed

3 files changed

+8
-44
lines changed

src/librustdoc/passes/calculate_doc_coverage.rs

+7-43
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::passes::Pass;
77
use rustc_lint::builtin::MISSING_DOCS;
88
use rustc_middle::lint::LintLevelSource;
99
use rustc_session::lint;
10-
use rustc_span::symbol::sym;
1110
use rustc_span::FileName;
1211
use serde::Serialize;
1312

@@ -193,48 +192,13 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
193192
// don't count items in stripped modules
194193
return Some(i);
195194
}
196-
clean::ImportItem(..) | clean::ExternCrateItem { .. } => {
197-
// docs on `use` and `extern crate` statements are not displayed, so they're not
198-
// worth counting
199-
return Some(i);
200-
}
201-
clean::ImplItem(ref impl_)
202-
if i.attrs
203-
.other_attrs
204-
.iter()
205-
.any(|item| item.has_name(sym::automatically_derived))
206-
|| impl_.synthetic
207-
|| impl_.blanket_impl.is_some() =>
208-
{
209-
// built-in derives get the `#[automatically_derived]` attribute, and
210-
// synthetic/blanket impls are made up by rustdoc and can't be documented
211-
// FIXME(misdreavus): need to also find items that came out of a derive macro
212-
return Some(i);
213-
}
214-
clean::ImplItem(ref impl_) => {
215-
let filename = i.span.filename(self.ctx.sess());
216-
if let Some(ref tr) = impl_.trait_ {
217-
debug!(
218-
"impl {:#} for {:#} in {}",
219-
tr.print(&self.ctx.cache, self.ctx.tcx),
220-
impl_.for_.print(&self.ctx.cache, self.ctx.tcx),
221-
filename,
222-
);
223-
224-
// don't count trait impls, the missing-docs lint doesn't so we shouldn't
225-
// either
226-
return Some(i);
227-
} else {
228-
// inherent impls *can* be documented, and those docs show up, but in most
229-
// cases it doesn't make sense, as all methods on a type are in one single
230-
// impl block
231-
debug!(
232-
"impl {:#} in {}",
233-
impl_.for_.print(&self.ctx.cache, self.ctx.tcx),
234-
filename
235-
);
236-
}
237-
}
195+
// docs on `use` and `extern crate` statements are not displayed, so they're not
196+
// worth counting
197+
clean::ImportItem(..) | clean::ExternCrateItem { .. } => {}
198+
// Don't count trait impls, the missing-docs lint doesn't so we shouldn't either.
199+
// Inherent impls *can* be documented, and those docs show up, but in most cases it
200+
// doesn't make sense, as all methods on a type are in one single impl block
201+
clean::ImplItem(_) => {}
238202
_ => {
239203
let has_docs = !i.attrs.doc_strings.is_empty();
240204
let mut tests = Tests { found_tests: 0 };

src/librustdoc/passes/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ crate const DEFAULT_PASSES: &[ConditionalPass] = &[
110110

111111
/// The list of default passes run when `--doc-coverage` is passed to rustdoc.
112112
crate const COVERAGE_PASSES: &[ConditionalPass] = &[
113-
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
114113
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
115114
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
116115
ConditionalPass::always(CALCULATE_DOC_COVERAGE),

src/test/rustdoc-ui/coverage/traits.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub trait ThisTrait {
1616
}
1717

1818
/// so what happens if we take some struct...
19+
#[derive(Clone)]
1920
pub struct SomeStruct;
2021

2122
/// ...and slap this trait on it?

0 commit comments

Comments
 (0)