Skip to content

Commit

Permalink
Auto merge of #96301 - notriddle:notriddle/synthetic-impl-prim, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

rustdoc: make primitive synthetic impls for correct doc module

This improves the accuracy of libcore primitive docs, which was missing the blanket and auto impls for most primitive types. To test this, compare nightly [libcore::str] docs, which lack auto traits like Send, with [std::str] docs, which show them.

[libcore::str]: https://doc.rust-lang.org/nightly/core/primitive.str.html
[libstd::str]: https://doc.rust-lang.org/nightly/std/primitive.str.html

It also avoids getting synthetic impls for primitive types on crates that do not actually show them.

<details>

<summary>Before and After trace logs</summary>

## Before

	[notriddle@deep-thought test-dingus]$ RUSTDOC_LOG=rustdoc=trace rustdoc +nightly test.rs 2>&1 | grep -E 'get_blanket_impls\('
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(Whatever)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(isize)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls([T])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls([u8])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls([T])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls([u8])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(char)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(u128)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(u16)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(i128)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(i16)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(str)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(str)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(f64)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(f64)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(u64)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(u8)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(i64)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(i8)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(*const T)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(*mut T)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(*const [T])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(*mut [T])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls([T; N])
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(bool)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(f32)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(f32)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(u32)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(usize)
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(i32)

## After

	[notriddle@deep-thought test-dingus]$ RUSTDOC_LOG=rustdoc=trace rustdoc +dev test.rs 2>&1 | grep -E 'get_blanket_impls\('
	TRACE rustdoc::clean::blanket_impl get_blanket_impls(Whatever)

</details>
  • Loading branch information
bors committed Apr 22, 2022
2 parents 41ef767 + 2e7b5ab commit 5ffebc2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
}
});

// Also try to inline primitive impls from other crates.
cx.tcx.sess.prof.generic_activity("build_primitive_trait_impls").run(|| {
for def_id in PrimitiveType::all_impls(cx.tcx) {
// Try to inline primitive impls from other crates.
if !def_id.is_local() {
inline::build_impl(cx, None, def_id, None, &mut new_items);

// FIXME(eddyb) is this `doc(hidden)` check needed?
if !cx.tcx.is_doc_hidden(def_id) {
}
}
for (prim, did) in PrimitiveType::primitive_locations(cx.tcx) {
// Do not calculate blanket impl list for docs that are not going to be rendered.
// While the `impl` blocks themselves are only in `libcore`, the module with `doc`
// attached is directly included in `libstd` as well.
if did.is_local() {
for def_id in prim.impls(cx.tcx) {
let impls = get_auto_trait_and_blanket_impls(cx, def_id);
new_items.extend(impls.filter(|i| cx.inlined.insert(i.item_id)));
}
Expand Down

0 comments on commit 5ffebc2

Please sign in to comment.