mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 14:02:57 +00:00
rustdoc: remove orphaned link on array bracket
This is 682889fb06
, but for arrays instead.
For non-generics, this retains links to the array page, but instead of
trying to link it all, it only links the length part, which distinguishes
arrays from slices.
For generics, the entire thing becomes a link, just like slices.
This commit is contained in:
parent
75d3027fb5
commit
598a02c6ad
@ -1010,15 +1010,25 @@ fn fmt_type<'cx>(
|
||||
write!(f, "]")
|
||||
}
|
||||
},
|
||||
clean::Array(ref t, ref n) => {
|
||||
primitive_link(f, PrimitiveType::Array, "[", cx)?;
|
||||
fmt::Display::fmt(&t.print(cx), f)?;
|
||||
if f.alternate() {
|
||||
primitive_link(f, PrimitiveType::Array, &format!("; {}]", n), cx)
|
||||
} else {
|
||||
primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx)
|
||||
clean::Array(ref t, ref n) => match **t {
|
||||
clean::Generic(name) if !f.alternate() => primitive_link(
|
||||
f,
|
||||
PrimitiveType::Array,
|
||||
&format!("[{name}; {n}]", n = Escape(n)),
|
||||
cx,
|
||||
),
|
||||
_ => {
|
||||
write!(f, "[")?;
|
||||
fmt::Display::fmt(&t.print(cx), f)?;
|
||||
if f.alternate() {
|
||||
write!(f, "; {n}")?;
|
||||
} else {
|
||||
write!(f, "; ")?;
|
||||
primitive_link(f, PrimitiveType::Array, &format!("{n}", n = Escape(n)), cx)?;
|
||||
}
|
||||
write!(f, "]")
|
||||
}
|
||||
}
|
||||
},
|
||||
clean::RawPointer(m, ref t) => {
|
||||
let m = match m {
|
||||
hir::Mutability::Mut => "mut",
|
||||
|
1
src/test/rustdoc/array-links.link_box_generic.html
Normal file
1
src/test/rustdoc/array-links.link_box_generic.html
Normal file
@ -0,0 +1 @@
|
||||
<code>pub fn delta<T>() -> <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a><<a class="primitive" href="{{channel}}/core/primitive.array.html">[T; 1]</a>></code>
|
1
src/test/rustdoc/array-links.link_box_u32.html
Normal file
1
src/test/rustdoc/array-links.link_box_u32.html
Normal file
@ -0,0 +1 @@
|
||||
<code>pub fn gamma() -> <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a><[<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>; <a class="primitive" href="{{channel}}/core/primitive.array.html">1</a>]></code>
|
1
src/test/rustdoc/array-links.link_slice_generic.html
Normal file
1
src/test/rustdoc/array-links.link_slice_generic.html
Normal file
@ -0,0 +1 @@
|
||||
<code>pub fn beta<T>() -> &'static <a class="primitive" href="{{channel}}/core/primitive.array.html">[T; 1]</a></code>
|
1
src/test/rustdoc/array-links.link_slice_u32.html
Normal file
1
src/test/rustdoc/array-links.link_slice_u32.html
Normal file
@ -0,0 +1 @@
|
||||
<code>pub fn alpha() -> &'static [<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>; <a class="primitive" href="{{channel}}/core/primitive.array.html">1</a>]</code>
|
28
src/test/rustdoc/array-links.rs
Normal file
28
src/test/rustdoc/array-links.rs
Normal file
@ -0,0 +1,28 @@
|
||||
#![crate_name = "foo"]
|
||||
#![no_std]
|
||||
|
||||
pub struct MyBox<T: ?Sized>(*const T);
|
||||
|
||||
// @has 'foo/fn.alpha.html'
|
||||
// @snapshot link_slice_u32 - '//pre[@class="rust fn"]/code'
|
||||
pub fn alpha() -> &'static [u32; 1] {
|
||||
loop {}
|
||||
}
|
||||
|
||||
// @has 'foo/fn.beta.html'
|
||||
// @snapshot link_slice_generic - '//pre[@class="rust fn"]/code'
|
||||
pub fn beta<T>() -> &'static [T; 1] {
|
||||
loop {}
|
||||
}
|
||||
|
||||
// @has 'foo/fn.gamma.html'
|
||||
// @snapshot link_box_u32 - '//pre[@class="rust fn"]/code'
|
||||
pub fn gamma() -> MyBox<[u32; 1]> {
|
||||
loop {}
|
||||
}
|
||||
|
||||
// @has 'foo/fn.delta.html'
|
||||
// @snapshot link_box_generic - '//pre[@class="rust fn"]/code'
|
||||
pub fn delta<T>() -> MyBox<[T; 1]> {
|
||||
loop {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user