Rustdoc: include crate name in links for local primitives#121490
Merged
bors merged 1 commit intorust-lang:masterfrom Feb 24, 2024
Merged
Rustdoc: include crate name in links for local primitives#121490bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Collaborator
Contributor
Author
|
cc @notriddle |
Contributor
To avoid making the regular standard library docs bigger, could this be done based on when match m.primitive_locations.get(&prim) {
Some(&def_id) if def_id.is_local() && cx.current.is_empty() => {
write!(
f,
"<a class=\"primitive\" href=\"{}/primitive.{}.html{fragment}\">",
ExternalCrate { crate_num: def_id.krate }.name(cx.tcx()),
prim.as_sym()
)?;
needs_termination = true;
}
Some(&def_id) if def_id.is_local() => {
write!(
f,
"<a class=\"primitive\" href=\"{}primitive.{}.html{fragment}\">",
"../".repeat(cx.current.len() - 1),
prim.as_sym()
)?;
needs_termination = true;
} |
Contributor
Author
Thanks for the suggestion. I'll make the change. |
147a678 to
4722344
Compare
Contributor
Author
Done |
This comment has been minimized.
This comment has been minimized.
notriddle
reviewed
Feb 24, 2024
It makes the link easier to use in cases in which the path of the page where it will be embedded is not known beforehand such as when we generate impls dynamically from `register_type_impls` method in `main.js` Earlier for local primitives we would generate a path that was relative to the current page depth passed in `cx.current` . e.g if the current page was `std::simd::prelude::Simd` the generated path would be `../../primitive.<prim>.html` After this change the path will first take you to the the wesite root and add the crate name. e.g. for `std::simd::prelude::Simd` the path now will be `../../../std/primitive.<prim>.html`
4722344 to
e0bfa5c
Compare
Contributor
|
@bors r+ rollup |
Collaborator
Collaborator
|
🌲 The tree is currently closed for pull requests below priority 50. This pull request will be tested once the tree is reopened. |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 24, 2024
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#121435 (Account for RPITIT in E0310 explicit lifetime constraint suggestion) - rust-lang#121490 (Rustdoc: include crate name in links for local primitives) - rust-lang#121520 (delay cloning of iterator items) - rust-lang#121522 (check that simd_insert/extract indices are in-bounds) - rust-lang#121531 (Ignore less tests in debug builds) - rust-lang#121539 (compiler/rustc_target/src/spec/base/apple/tests.rs: Avoid unnecessary large move) - rust-lang#121542 (update stdarch) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 24, 2024
Rollup merge of rust-lang#121490 - gurry:121106-broken-usize-link-in-docs, r=notriddle Rustdoc: include crate name in links for local primitives Fixes rust-lang#121106. This change makes links to primitives easier to use when the path of the page where they will be embedded is not known beforehand such as when we generate impls dynamically from the `register_type_impls` method in `main.js`, which is exactly what is happening in rust-lang#121106. An example to show the effect of this change: earlier, if the current page in `cx.current` inside `primitive_link_fragment()` was `std::simd::prelude::Simd` the generated path would be `../../primitive.<prim>.html`. Now it would be `../../../std/primitive.<prim>.html` instead. A side effect of the change is that local primitive links _everywhere_ will now contain the crate name, even outside of the dynamic situation mentioned above. I'm not sure if there are any major downsides of that other than making the links a bit longer. Ideally I wanted to restrict this behaviour change to only the dynamic cases. We could have achieved that by passing an additional bool arg to `primitive_link_fragment()`, but it felt awkward to do so. Any alternative suggestions are welcome.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 27, 2024
…06, r=GuillaumeGomez Add test case for primitive links in alias js Follow up rust-lang#121490 CC rust-lang#121106
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 27, 2024
…06, r=GuillaumeGomez Add test case for primitive links in alias js Follow up rust-lang#121490 CC rust-lang#121106
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 27, 2024
…06, r=GuillaumeGomez Add test case for primitive links in alias js Follow up rust-lang#121490 CC rust-lang#121106
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
Feb 28, 2024
…06, r=GuillaumeGomez Add test case for primitive links in alias js Follow up rust-lang#121490 CC rust-lang#121106
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
Feb 28, 2024
…06, r=GuillaumeGomez Add test case for primitive links in alias js Follow up rust-lang#121490 CC rust-lang#121106
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 28, 2024
Rollup merge of rust-lang#121572 - notriddle:notriddle/test-case-121106, r=GuillaumeGomez Add test case for primitive links in alias js Follow up rust-lang#121490 CC rust-lang#121106
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #121106.
This change makes links to primitives easier to use when the path of the page where they will be embedded is not known beforehand such as when we generate impls dynamically from the
register_type_implsmethod inmain.js, which is exactly what is happening in #121106.An example to show the effect of this change: earlier, if the current page in
cx.currentinsideprimitive_link_fragment()wasstd::simd::prelude::Simdthe generated path would be../../primitive.<prim>.html. Now it would be../../../std/primitive.<prim>.htmlinstead.A side effect of the change is that local primitive links everywhere will now contain the crate name, even outside of the dynamic situation mentioned above. I'm not sure if there are any major downsides of that other than making the links a bit longer. Ideally I wanted to restrict this behaviour change to only the dynamic cases. We could have achieved that by passing an additional bool arg to
primitive_link_fragment(), but it felt awkward to do so. Any alternative suggestions are welcome.