Skip to content

Commit dfedd33

Browse files
jyn514GuillaumeGomez
authored andcommitted
Fix linkcheck issues
Most of these are because alloc uses `#[lang_item]` to define methods, but core documents primitives before those methods are available. - Fix run-make-fulldeps test I don't know why it assumed it could build core without cargo ... - Fix rustdoc-js-std test For some reason this change made CStr not show up in the results for `str,u8`. Since it still shows up for str, and since it wasn't a great match for that query anyway, I think this is ok to let slide. - Add test that all primitives can be linked to - Enable `doc(primitive)` in `core` as well
1 parent 64fe43c commit dfedd33

File tree

8 files changed

+43
-18
lines changed

8 files changed

+43
-18
lines changed

library/core/src/char/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl char {
2424
/// decoding error.
2525
///
2626
/// It can occur, for example, when giving ill-formed UTF-8 bytes to
27-
/// [`String::from_utf8_lossy`](string/struct.String.html#method.from_utf8_lossy).
27+
/// [`String::from_utf8_lossy`](../std/string/struct.String.html#method.from_utf8_lossy).
2828
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
2929
pub const REPLACEMENT_CHARACTER: char = '\u{FFFD}';
3030

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
#![feature(decl_macro)]
132132
#![feature(doc_cfg)]
133133
#![feature(doc_notable_trait)]
134+
#![cfg_attr(not(bootstrap), feature(doc_primitive))]
134135
#![feature(exhaustive_patterns)]
135136
#![feature(extern_types)]
136137
#![feature(fundamental)]

library/core/src/slice/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,9 +2258,9 @@ impl<T> [T] {
22582258
/// assert!(match r { Ok(1..=4) => true, _ => false, });
22592259
/// ```
22602260
// Lint rustdoc::broken_intra_doc_links is allowed as `slice::sort_by_key` is
2261-
// in crate `alloc`, and as such doesn't exists yet when building `core`.
2262-
// links to downstream crate: #74481. Since primitives are only documented in
2263-
// libstd (#73423), this never leads to broken links in practice.
2261+
// in crate `alloc`, and as such doesn't exists yet when building `core`: #74481.
2262+
// This breaks links when slice is displayed in core, but changing it to use relative links
2263+
// would break when the item is re-exported. So allow the core links to be broken for now.
22642264
#[allow(rustdoc::broken_intra_doc_links)]
22652265
#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
22662266
#[inline]

library/std/src/primitive_docs.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mod prim_bool {}
103103
/// behaviour of the `!` type - expressions with type `!` will coerce into any other type.
104104
///
105105
/// [`u32`]: prim@u32
106-
#[doc = concat!("[`exit`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/process_exit.md")))]
106+
#[doc = concat!("[`exit`]: ", include_str!("../primitive_docs/process_exit.md"))]
107107
///
108108
/// # `!` and generics
109109
///
@@ -188,7 +188,7 @@ mod prim_bool {}
188188
/// because `!` coerces to `Result<!, ConnectionError>` automatically.
189189
///
190190
/// [`String::from_str`]: str::FromStr::from_str
191-
#[doc = concat!("[`String`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/string_string.md")))]
191+
#[doc = concat!("[`String`]: ", include_str!("../primitive_docs/string_string.md"))]
192192
/// [`FromStr`]: str::FromStr
193193
///
194194
/// # `!` and traits
@@ -264,7 +264,7 @@ mod prim_bool {}
264264
/// `impl` for this which simply panics, but the same is true for any type (we could `impl
265265
/// Default` for (eg.) [`File`] by just making [`default()`] panic.)
266266
///
267-
#[doc = concat!("[`File`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/fs_file.md")))]
267+
#[doc = concat!("[`File`]: ", include_str!("../primitive_docs/fs_file.md"))]
268268
/// [`Debug`]: fmt::Debug
269269
/// [`default()`]: Default::default
270270
///
@@ -303,7 +303,7 @@ mod prim_never {}
303303
/// assert_eq!(5, s.len() * std::mem::size_of::<u8>());
304304
/// ```
305305
///
306-
#[doc = concat!("[`String`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/string_string.md")))]
306+
#[doc = concat!("[`String`]: ", include_str!("../primitive_docs/string_string.md"))]
307307
///
308308
/// As always, remember that a human intuition for 'character' might not map to
309309
/// Unicode's definitions. For example, despite looking similar, the 'é'
@@ -495,7 +495,7 @@ mod prim_unit {}
495495
/// [`null_mut`]: ptr::null_mut
496496
/// [`is_null`]: pointer::is_null
497497
/// [`offset`]: pointer::offset
498-
#[doc = concat!("[`into_raw`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/box_into_raw.md")))]
498+
#[doc = concat!("[`into_raw`]: ", include_str!("../primitive_docs/box_into_raw.md"))]
499499
/// [`drop`]: mem::drop
500500
/// [`write`]: ptr::write
501501
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1125,7 +1125,7 @@ mod prim_usize {}
11251125
/// [`std::fmt`]: fmt
11261126
/// ['Pointer`]: fmt::Pointer
11271127
/// [`Hash`]: hash::Hash
1128-
#[doc = concat!("[`ToSocketAddrs`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/net_tosocketaddrs.md")))]
1128+
#[doc = concat!("[`ToSocketAddrs`]: ", include_str!("../primitive_docs/net_tosocketaddrs.md"))]
11291129
///
11301130
/// `&mut T` references get all of the above except `ToSocketAddrs`, plus the following, if `T`
11311131
/// implements that trait:
@@ -1146,10 +1146,10 @@ mod prim_usize {}
11461146
///
11471147
/// [`FusedIterator`]: iter::FusedIterator
11481148
/// [`TrustedLen`]: iter::TrustedLen
1149-
#[doc = concat!("[`Seek`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/io_seek.md")))]
1150-
#[doc = concat!("[`BufRead`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/io_bufread.md")))]
1151-
#[doc = concat!("[`Read`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/io_read.md")))]
1152-
#[doc = concat!("[`io::Write`]: ", include_str!(concat!("../../", env!("CARGO_PKG_NAME"), "/primitive_docs/io_write.md")))]
1149+
#[doc = concat!("[`Seek`]: ", include_str!("../primitive_docs/io_seek.md"))]
1150+
#[doc = concat!("[`BufRead`]: ", include_str!("../primitive_docs/io_bufread.md"))]
1151+
#[doc = concat!("[`Read`]: ", include_str!("../primitive_docs/io_read.md"))]
1152+
#[doc = concat!("[`io::Write`]: ", include_str!("../primitive_docs/io_write.md"))]
11531153
///
11541154
/// Note that due to method call deref coercion, simply calling a trait method will act like they
11551155
/// work on references as well as they do on owned values! The implementations described here are

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ impl PrimitiveType {
17711771
debug!(?crate_num, ?crate_name);
17721772
for &(def_id, prim) in &e.primitives(tcx) {
17731773
// HACK: try to link to std instead where possible
1774-
if crate_name == sym::core && primitive_locations.get(&prim).is_some() {
1774+
if crate_name == sym::core && primitive_locations.contains_key(&prim) {
17751775
continue;
17761776
}
17771777
primitive_locations.insert(prim, def_id);

src/test/rustdoc-js-std/multi-query.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const QUERY = 'str,u8';
22

33
const EXPECTED = {
44
'others': [
5-
{ 'path': 'std', 'name': 'str' },
6-
{ 'path': 'std', 'name': 'u8' },
7-
{ 'path': 'std::ffi', 'name': 'CStr' },
5+
{ 'path': 'std', 'name': 'str', 'href': '../std/primitive.str.html' },
6+
{ 'path': 'std', 'name': 'u8', 'href': '../std/primitive.u8.html' },
7+
{ 'path': 'std', 'name': 'str', 'href': '../std/str/index.html' },
8+
{ 'path': 'std', 'name': 'u8', 'href': '../std/u8/index.html' },
89
],
910
};

src/test/rustdoc/primitive/no_std.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#![no_std]
2+
#![deny(warnings)]
3+
#![deny(rustdoc::broken_intra_doc_links)]
24

35
// @has no_std/fn.foo.html '//a/[@href="{{channel}}/core/primitive.u8.html"]' 'u8'
46
// @has no_std/fn.foo.html '//a/[@href="{{channel}}/core/primitive.u8.html"]' 'primitive link'
57
/// Link to [primitive link][u8]
68
pub fn foo() -> u8 {}
9+
10+
// Test that all primitives can be linked to.
11+
/// [isize] [i8] [i16] [i32] [i64] [i128]
12+
/// [usize] [u8] [u16] [u32] [u64] [u128]
13+
/// [f32] [f64]
14+
/// [char] [bool] [str] [slice] [array] [tuple] [unit]
15+
/// [pointer] [reference] [fn] [never]
16+
pub fn bar() {}

src/tools/linkchecker/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,26 @@ use regex::Regex;
3030
// If at all possible you should use intra-doc links to avoid linkcheck issues. These
3131
// are cases where that does not work
3232
// [(generated_documentation_page, &[broken_links])]
33+
#[rustfmt::skip]
3334
const LINKCHECK_EXCEPTIONS: &[(&str, &[&str])] = &[
3435
// These try to link to std::collections, but are defined in alloc
3536
// https://github.com/rust-lang/rust/issues/74481
3637
("std/collections/btree_map/struct.BTreeMap.html", &["#insert-and-complex-keys"]),
3738
("std/collections/btree_set/struct.BTreeSet.html", &["#insert-and-complex-keys"]),
3839
("alloc/collections/btree_map/struct.BTreeMap.html", &["#insert-and-complex-keys"]),
3940
("alloc/collections/btree_set/struct.BTreeSet.html", &["#insert-and-complex-keys"]),
41+
42+
// These try to link to various things in std, but are defined in core.
43+
// The docs in std::primitive use proper intra-doc links, so these seem fine to special-case.
44+
// Most these are broken because liballoc uses `#[lang_item]` magic to define things on
45+
// primitives that aren't available in core.
46+
("alloc/slice/trait.Join.html", &["#method.join"]),
47+
("alloc/slice/trait.Concat.html", &["#method.concat"]),
48+
("alloc/slice/index.html", &["#method.concat", "#method.join"]),
49+
("alloc/vec/struct.Vec.html", &["#method.sort_by_key", "#method.sort_by_cached_key"]),
50+
("core/primitive.str.html", &["#method.to_ascii_uppercase", "#method.to_ascii_lowercase"]),
51+
("core/primitive.slice.html", &["#method.to_ascii_uppercase", "#method.to_ascii_lowercase",
52+
"#method.sort_by_cached_key", "core/slice::sort_by_key"]),
4053
];
4154

4255
#[rustfmt::skip]

0 commit comments

Comments
 (0)