Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Remove GetDefId #90154

Merged
merged 10 commits into from
Oct 27, 2021
Merged

rustdoc: Remove GetDefId #90154

merged 10 commits into from
Oct 27, 2021

Conversation

camelid
Copy link
Member

@camelid camelid commented Oct 22, 2021

See the individual commit messages for details.

r? @jyn514

Based on looking at the source code, it looks like the `did` needs to be
for an impl, not functions in an impl.
@camelid camelid added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 22, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 making this not a trait is an excellent idea, thanks for spotting this :)

src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
@@ -374,7 +374,7 @@ crate fn build_impl(
// Only inline impl if the implementing type is
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(did) = for_.def_id() {
if let Some(did) = for_.def_id_full(&cx.cache) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something in this commit broke the linkchecker, not sure exactly which change. Maybe try reverting them one at a time until you find what went wrong? If you could write a test for it that would be amazing ❤️ but I won't block on that.

Copy link
Member Author

@camelid camelid Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, this is so great. My commit "broke" the linkchecker — because some impls that should have been shown on str's page were not because def_id_full was not being used, and they have stuff like this, which are interpreted as links by the linkchecker:

image

I'll update those docs to use inline code. EDIT: Instead, I just escaped the brackets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now :)

It was only used in one place, so it seems better to use ordinary
functions.
Now that it's only implemented for `Type`, using inherent methods
instead means that imports are no longer necessary. Also, `GetDefId` is
only meant to be used with `Type`, so it shouldn't be a trait.
In general, it should be preferred over `Type::def_id()`. See each
method's docs for more.
The old name was confusing because it's easy to assume that using
`def_id()` is fine, but in some situations it's incorrect. In general,
`def_id_full()` should be preferred, so `def_id_full()` should have a
shorter name. That will happen in the next commit.
It should be preferred over `def_id_no_primitives()`, so it should have
a shorter name. I also put it before `def_id_no_primitives()` so that it
shows up first in the docs.
@camelid camelid force-pushed the remove-getdefid branch 2 times, most recently from 8c6f07a to f801ac3 Compare October 22, 2021 20:29
@camelid
Copy link
Member Author

camelid commented Oct 22, 2021

Hmm, I guess the linkchecker really doesn't like seeing brackets in the HTML. Why does it even check for broken intra-doc links; doesn't rustdoc do that?

@camelid
Copy link
Member Author

camelid commented Oct 22, 2021

I'll just add to the exceptions list for now since there are almost identical exceptions there already.

My change to use `Type::def_id()` (formerly `Type::def_id_full()`) in
more places caused some docs to show up that used to be missed by
rustdoc. Those docs contained unescaped square brackets, which triggered
linkcheck errors. This commit escapes the square brackets and adds this
particular instance to the linkcheck exception list.
@jyn514
Copy link
Member

jyn514 commented Oct 27, 2021

Why does it even check for broken intra-doc links; doesn't rustdoc do that?

Rustdoc has been buggy in the past, this helped catch quite a lot of links when it was introduced. I don't have a link to the PR offhand.

@@ -234,7 +234,7 @@ unsafe impl SliceIndex<str> for ops::Range<usize> {
/// Implements substring slicing with syntax `&self[.. end]` or `&mut
/// self[.. end]`.
///
/// Returns a slice of the given string from the byte range [`0`, `end`).
/// Returns a slice of the given string from the byte range \[0, `end`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead just surround the whole range with backticks? That seems like it would look nicer when displayed too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially was going to do that, but then I realized that closed ranges might look like arrays instead, which could be confusing: [0, end]. I was also leaning on the side of having the docs be displayed the same way as before. In addition, based on the pre-existing link-check exceptions, it seems that the [0, end] style is the "standard" way to write it.

All that said, I'm fine either way, so I can change them if you would prefer.

@jyn514
Copy link
Member

jyn514 commented Oct 27, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Oct 27, 2021

📌 Commit 3ad0834 has been approved by jyn514

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 27, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 27, 2021
…askrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#90154 (rustdoc: Remove `GetDefId`)
 - rust-lang#90232 (rustdoc: Use TTF based font instead of OTF for CJK glyphs to improve readability)
 - rust-lang#90278 (rustdoc: use better highlighting for *const, *mut, and &mut)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e3eebfe into rust-lang:master Oct 27, 2021
@rustbot rustbot added this to the 1.58.0 milestone Oct 27, 2021
@camelid camelid deleted the remove-getdefid branch October 27, 2021 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants