Skip to content

Commit e43c200

Browse files
committed
Auto merge of #84030 - jyn514:no-blanket-impls, r=GuillaumeGomez
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. This also adds back a commented-out test; Rustdoc has been able to deal with `impl trait` for almost a year now. r? `@GuillaumeGomez`
2 parents bc66b92 + f67103b commit e43c200

File tree

4 files changed

+16
-53
lines changed

4 files changed

+16
-53
lines changed

Diff for: 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 };

Diff for: 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),

Diff for: src/test/rustdoc-ui/coverage/traits.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// check-pass
33

44
#![feature(trait_alias)]
5+
#![feature(min_type_alias_impl_trait)]
56

67
/// look at this trait right here
78
pub trait ThisTrait {
@@ -16,6 +17,7 @@ pub trait ThisTrait {
1617
}
1718

1819
/// so what happens if we take some struct...
20+
#[derive(Clone)]
1921
pub struct SomeStruct;
2022

2123
/// ...and slap this trait on it?
@@ -29,10 +31,8 @@ impl ThisTrait for SomeStruct {
2931
/// but what about those aliases? i hear they're pretty exotic
3032
pub trait MyAlias = ThisTrait + Send + Sync;
3133

32-
// FIXME(58624): once rustdoc can process opaque `impl Trait` types,
33-
// we need to make sure they're counted
34-
// /// woah, getting all opaque in here
35-
// pub type ThisExists = impl ThisTrait;
36-
//
37-
// /// why don't we get a little more concrete
38-
// pub fn defines() -> ThisExists { SomeStruct {} }
34+
/// woah, getting all opaque in here
35+
pub type ThisExists = impl ThisTrait;
36+
37+
/// why don't we get a little more concrete
38+
pub fn defines() -> ThisExists { SomeStruct {} }

Diff for: src/test/rustdoc-ui/coverage/traits.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4-
| ...st/rustdoc-ui/coverage/traits.rs | 6 | 85.7% | 0 | 0.0% |
4+
| ...st/rustdoc-ui/coverage/traits.rs | 8 | 88.9% | 0 | 0.0% |
55
+-------------------------------------+------------+------------+------------+------------+
6-
| Total | 6 | 85.7% | 0 | 0.0% |
6+
| Total | 8 | 88.9% | 0 | 0.0% |
77
+-------------------------------------+------------+------------+------------+------------+

0 commit comments

Comments
 (0)