diff options
| author | bors <bors@rust-lang.org> | 2022-06-16 11:13:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-16 11:13:30 +0000 |
| commit | 6ec3993ef4a4eb72bc20477fe9a4d92acd53f2c6 (patch) | |
| tree | 64623290e8e88fc28d678a5b928dc9595fcbcea0 /src/librustdoc/html/format.rs | |
| parent | d40f24e956a698e47a209541031c4045acc5a684 (diff) | |
| parent | f1d24beb6805e4d16d472964518c576421f8c009 (diff) | |
| download | rust-6ec3993ef4a4eb72bc20477fe9a4d92acd53f2c6.tar.gz rust-6ec3993ef4a4eb72bc20477fe9a4d92acd53f2c6.zip | |
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>
Diffstat (limited to 'src/librustdoc/html/format.rs')
| -rw-r--r-- | src/librustdoc/html/format.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 394db2d0cda..0c0920ae63e 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -714,6 +714,16 @@ fn primitive_link( name: &str, cx: &Context<'_>, ) -> fmt::Result { + primitive_link_fragment(f, prim, name, "", cx) +} + +fn primitive_link_fragment( + f: &mut fmt::Formatter<'_>, + prim: clean::PrimitiveType, + name: &str, + fragment: &str, + cx: &Context<'_>, +) -> fmt::Result { let m = &cx.cache(); let mut needs_termination = false; if !f.alternate() { @@ -723,7 +733,7 @@ fn primitive_link( let len = if len == 0 { 0 } else { len - 1 }; write!( f, - "<a class=\"primitive\" href=\"{}primitive.{}.html\">", + "<a class=\"primitive\" href=\"{}primitive.{}.html{fragment}\">", "../".repeat(len), prim.as_sym() )?; @@ -754,7 +764,7 @@ fn primitive_link( }; if let Some(mut loc) = loc { loc.push_fmt(format_args!("primitive.{}.html", prim.as_sym())); - write!(f, "<a class=\"primitive\" href=\"{}\">", loc.finish())?; + write!(f, "<a class=\"primitive\" href=\"{}{fragment}\">", loc.finish())?; needs_termination = true; } } @@ -1039,7 +1049,13 @@ impl clean::Impl { write!(f, " for ")?; } - if let Some(ty) = self.kind.as_blanket_ty() { + if let clean::Type::Tuple(types) = &self.for_ && + let [clean::Type::Generic(name)] = &types[..] && + (self.kind.is_tuple_variadic() || self.kind.is_auto()) { + // Hardcoded anchor library/core/src/primitive_docs.rs + // Link should match `# Trait implementations` + primitive_link_fragment(f, PrimitiveType::Tuple, &format!("({name}₁, {name}₂, …, {name}ₙ)"), "#trait-implementations-1", cx)?; + } else if let Some(ty) = self.kind.as_blanket_ty() { fmt_type(ty, f, use_absolute, cx)?; } else { fmt_type(&self.for_, f, use_absolute, cx)?; |
