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/clean | |
| 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/clean')
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 5 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index a82abe66926..d8f6a9c3ff0 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -500,7 +500,11 @@ pub(crate) fn build_impl( for_, items: trait_items, polarity, - kind: ImplKind::Normal, + kind: if utils::has_doc_flag(tcx, did, sym::tuple_varadic) { + ImplKind::TupleVaradic + } else { + ImplKind::Normal + }, }), box merged_attrs, cx, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f3070fb35f1..b15ef424cb6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1999,7 +1999,11 @@ fn clean_impl<'tcx>( for_, items, polarity: tcx.impl_polarity(def_id), - kind: ImplKind::Normal, + kind: if utils::has_doc_flag(tcx, def_id.to_def_id(), sym::tuple_varadic) { + ImplKind::TupleVaradic + } else { + ImplKind::Normal + }, }); Item::from_hir_id_and_parts(hir_id, None, kind, cx) }; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 4605793d0df..95c84e68b83 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2394,6 +2394,7 @@ impl Impl { pub(crate) enum ImplKind { Normal, Auto, + TupleVaradic, Blanket(Box<Type>), } @@ -2406,6 +2407,10 @@ impl ImplKind { matches!(self, ImplKind::Blanket(_)) } + pub(crate) fn is_tuple_varadic(&self) -> bool { + matches!(self, ImplKind::TupleVaradic) + } + pub(crate) fn as_blanket_ty(&self) -> Option<&Type> { match self { ImplKind::Blanket(ty) => Some(ty), |
