Skip to content

Commit

Permalink
Add test case for #trait-implementations-1 link
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Jun 11, 2022
1 parent 3fd1664 commit c148755
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ mod prim_str {}
///
/// For more about tuples, see [the book](../book/ch03-02-data-types.html#the-tuple-type).
///
// Hardcoded anchor in src/librustdoc/html/format.rs
// linked to as `#trait-implementations-1`
/// # Trait implementations
///
/// In this documentation the shorthand `(T, ...)` is used to represent tuples of varying length.
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ mod prim_str {}
///
/// For more about tuples, see [the book](../book/ch03-02-data-types.html#the-tuple-type).
///
// Hardcoded anchor in src/librustdoc/html/format.rs
// linked to as `#trait-implementations-1`
/// # Trait implementations
///
/// In this documentation the shorthand `(T, ...)` is used to represent tuples of varying length.
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ impl clean::Impl {
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}, ...)"), "#trait-implementations-1", cx)?;
} else if let Some(ty) = self.kind.as_blanket_ty() {
fmt_type(ty, f, use_absolute, cx)?;
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc/primitive-tuple-auto-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@
// @has - '//div[@id="synthetic-implementations-list"]//h3' 'Sync'
#[doc(primitive = "tuple")]
/// this is a test!
///
// Hardcoded anchor to header written in library/core/src/primitive_docs.rs
// @has - '//h2[@id="trait-implementations-1"]' 'Trait implementations'
/// # Trait implementations
///
/// This header is hard-coded in the HTML format linking for `#[doc(tuple_variadics)]`.
/// To make sure it gets linked correctly, we need to make sure the hardcoded anchor
/// in the code matches what rustdoc generates for the header.
mod tuple_prim {}

0 comments on commit c148755

Please sign in to comment.