Auto merge of #96301 - notriddle:notriddle/synthetic-impl-prim, r=GuillaumeGomez

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>
This commit is contained in:
bors 2022-04-22 16:47:13 +00:00
commit 5ffebc2cb3

View File

@ -43,14 +43,19 @@
}
});
// 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)));
}