diff options
| author | Michael Howell <michael@notriddle.com> | 2022-06-08 19:26:51 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2022-06-08 19:26:51 -0700 |
| commit | 6950f144cf83d10bc4a304b48488f9f5368cfaae (patch) | |
| tree | cdb01e93a5aa5912f6ef07deef7ba8c622027f67 /src/librustdoc/html | |
| parent | 7a935670055d87e17c381542f4eaab481e8bf17b (diff) | |
| download | rust-6950f144cf83d10bc4a304b48488f9f5368cfaae.tar.gz rust-6950f144cf83d10bc4a304b48488f9f5368cfaae.zip | |
rustdoc: show tuple impls as `impl Trait for (T, ...)`
This commit adds a new unstable attribute, `#[doc(tuple_varadic)]`, that shows a 1-tuple as `(T, ...)` instead of just `(T,)`, and links to a section in the tuple primitive docs that talks about these.
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/format.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index b7789493df6..2f433c2313b 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; } } @@ -1064,7 +1074,11 @@ 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_varadic() || self.kind.is_auto()) { + primitive_link_fragment(f, PrimitiveType::Tuple, &format!("({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)?; |
