1
Fork 0

Auto merge of #97842 - notriddle:notriddle/tuple-docs, r=jsha,GuillaumeGomez

Improve the tuple and unit trait docs

* Reduce duplicate impls; show only the `(T,)` and include a sentence saying that there exists ones up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

Here's the new version:

* <https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html>
* <https://notriddle.com/notriddle-rustdoc-test/std/primitive.unit.html>
This commit is contained in:
bors 2022-06-16 11:13:30 +00:00
commit 6ec3993ef4
22 changed files with 467 additions and 111 deletions

View file

@ -805,6 +805,37 @@ impl CheckAttrVisitor<'_> {
true
}
fn check_doc_tuple_variadic(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
match self.tcx.hir().find(hir_id).and_then(|node| match node {
hir::Node::Item(item) => Some(&item.kind),
_ => None,
}) {
Some(ItemKind::Impl(ref i)) => {
if !matches!(&i.self_ty.kind, hir::TyKind::Tup([_])) {
self.tcx
.sess
.struct_span_err(
meta.span(),
"`#[doc(tuple_variadic)]` must be used on the first of a set of tuple trait impls with varying arity",
)
.emit();
return false;
}
}
_ => {
self.tcx
.sess
.struct_span_err(
meta.span(),
"`#[doc(keyword = \"...\")]` can only be used on impl blocks",
)
.emit();
return false;
}
}
true
}
/// Checks `#[doc(inline)]`/`#[doc(no_inline)]` attributes. Returns `true` if valid.
///
/// A doc inlining attribute is invalid if it is applied to a non-`use` item, or
@ -1065,6 +1096,13 @@ impl CheckAttrVisitor<'_> {
is_valid = false
}
sym::tuple_variadic
if !self.check_attr_not_crate_level(meta, hir_id, "tuple_variadic")
|| !self.check_doc_tuple_variadic(meta, hir_id) =>
{
is_valid = false
}
sym::html_favicon_url
| sym::html_logo_url
| sym::html_playground_url
@ -1118,7 +1156,8 @@ impl CheckAttrVisitor<'_> {
| sym::no_inline
| sym::notable_trait
| sym::passes
| sym::plugins => {}
| sym::plugins
| sym::tuple_variadic => {}
sym::test => {
if !self.check_test_attr(meta, hir_id) {