Skip to content

rustdoc: Strip broken links in summaries - #79781

Closed
camelid wants to merge 1 commit into
rust-lang:masterfrom
camelid:summary-render-intra-doc
Closed

rustdoc: Strip broken links in summaries#79781
camelid wants to merge 1 commit into
rust-lang:masterfrom
camelid:summary-render-intra-doc

Conversation

@camelid

@camelidcamelid commented Dec 7, 2020

Copy link
Copy Markdown
Member

The primary reason to do this is because intra-doc links are treated as
"broken" in the summary since the resolution context is not available.
Previously, search results with intra-doc links would look like:

This method returns an [Ordering]

but now they look like:

This method returns an Ordering

as search results with regular links do.

The one drawback I can see is if people are using [ and ] literally,
but I think that case is much rarer than using intra-doc links, and they
can and should escape the brackets with a backslash or use inline code.
Plus, this is just for summaries.

r? @jyn514

@camelidcamelid added A-markdown-parsing Area: Markdown parsing for doc-comments A-rustdoc-search Area: Rustdoc's search feature C-enhancement Category: An issue proposing an enhancement or a PR with one. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Dec 7, 2020
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 7, 2020
@camelid

Copy link
Copy Markdown
MemberAuthor

Before

image

After

image

@camelid

Copy link
Copy Markdown
MemberAuthor

Before

image

After

image

@camelid
camelidforce-pushed the summary-render-intra-doc branch from 0bbe443 to d32c804CompareDecember 7, 2020 04:43
@jyn514jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 7, 2020
Comment threadsrc/librustdoc/html/markdown.rs Outdated
Comment threadsrc/librustdoc/html/markdown.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This treats every broken link as valid, right? Can we instead use the same logic as for intra-doc links and only replace it if it was resolved?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Well we could, but we’d have to thread the intra-doc link information through somehow. If you would like me to do that, could you give me some instructions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This info is available from item.attrs.links: https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/struct.Attributes.html#structfield.links. It looks like that's not currently threaded through to short_markdown_summary, but everywhere that calls summary calls it on an Item. I'd suggest making this a method on Item instead and calling item.short_markdown_summary() instead, which gives you access to all the info on the item.

See

// Replace intra-doc links and remove disambiguators from shortcut links (`[fn@f]`).
for an example of actually using the link - I don't expect this to be as complicated since it's just stripping the link altogether, and only for [] style links.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Hmm, will I then I have to duplicate broken_link_callback as a closure after all?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see why? You're stripping the links in both cases, right?

@camelidcamelidFeb 16, 2021

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

It's been a while since we last discussed this. It looks like the last thing we talked about is letting their be a little duplication and moving the summary functions to be on Item?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

It's coming back to me now: The reason I temporarily abandoned this is because I was having trouble with the lifetimes of the callback for the summary functions not on Item. I think it might have been the dreaded higher-ranked subtype error. I'll post the error if/when I get it.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So I tried this type signature:

fnmarkdown_summary_with_limit(md:&str,length_limit:usize,broken_link_callback:Option<F>,) -> (String,bool)whereF:for<'a>FnMut(BrokenLink<'_>) -> Option<(CowStr<'a>,CowStr<'a>)>,{/* ... */}

but that gives a bunch of errors like:

error[E0582]: binding for associated type `Output` references lifetime `'a`, which does not appear in the trait input types
--> src/librustdoc/html/markdown.rs:1030:41
|
1030 | F: for<'a> FnMut(BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What are the correct lifetimes? I feel like this needs higher-ranked lifetimes (which I added) but as you can see it doesn't work. I need to communicate to the compiler that the return type lifetimes are totally unrelated from the input lifetimes.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@jyn514 friendly ping :)

If you need to focus on other stuff, don't worry about looking at this now, but you seemed eager to get this working.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Try F: FnMut(BrokenLink<'_>) -> Option<(CowStr<'static>, CowStr<'static>)>. That has the same meaning without introducing a new lifetime.

@jyn514

Copy link
Copy Markdown
Member

Also, please add a test for this.

@camelid
camelidforce-pushed the summary-render-intra-doc branch from 4d130d0 to 3f685a7CompareDecember 8, 2020 21:39
@camelid

Copy link
Copy Markdown
MemberAuthor

Hmm, why did I mark this PR as blocked?

@jyn514jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 30, 2020
@jyn514

Copy link
Copy Markdown
Member

@camelid friendly ping :) I think this would be a nice feature to have, happy to help out if you need it.

@camelid

Copy link
Copy Markdown
MemberAuthor

Yeah, I've been trying to catch up on my S-waiting-on-author PRs. This one is on my list :)

The primary reason to do this is because intra-doc links are treated as
"broken" in the summary since the resolution context is not available.
Previously, search results with intra-doc links would look like:
> This method returns an \[`Ordering`\]
but now they look like:
> This method returns an `Ordering`
as search results with regular links do.
The one drawback I can see is if people are using `[` and `]` literally,
but I think that case is much rarer than using intra-doc links, and they
can and should escape the brackets with a backslash or use inline code.
Plus, this is just for summaries.
@camelid
camelidforce-pushed the summary-render-intra-doc branch from 3f685a7 to 6c9a580CompareFebruary 16, 2021 06:20
@camelid

Copy link
Copy Markdown
MemberAuthor

Starting with a rebase.

@camelid

Copy link
Copy Markdown
MemberAuthor

Oops, looks like my rebase included some changes... oh well 😅

@camelid

Copy link
Copy Markdown
MemberAuthor

Weird, I used git range-diff master @{u} HEAD and it showed no changes:

1: d32c80467db ! 1: 6c9a5805b0c rustdoc: Strip broken links in summaries
@@ Commit message
## src/librustdoc/html/markdown.rs ##
@@ src/librustdoc/html/markdown.rs: fn push(s: &mut String, text_length: &mut usize, text: &str) {
*text_length += text.len();
- };
+ }
- 'outer: for event in Parser::new_ext(md, summary_opts()) {
+ // NOTE: Make sure to update the same variable in `plain_text_summary`
2: 3f685a724e9 < -: ----------- Deduplicate broken-link callback

@camelidcamelid added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 16, 2021
@jyn514

Copy link
Copy Markdown
Member

I think this is waiting on #79781 (comment). If I'm wrong, feel free to ping me for a review :)

@rustbot label: -S-waiting-on-review +S-waiting-on-author

@rustbotrustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 23, 2021
@camelid

Copy link
Copy Markdown
MemberAuthor

This is blocked on getting a new pulldown-cmark release that includes your lifetimes fix. @rustbot label: -S-waiting-on-author +S-blocked

@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 24, 2021
@rustbotrustbot added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 24, 2021
@camelidcamelid added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 12, 2021
@camelidcamelid added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels May 28, 2021
@jyn514

Copy link
Copy Markdown
Member

@camelid can you test this with a git dependency to make sure that actually fixes it? It seems silly to wait all this time if it doesn't actually affect the error.

@jyn514jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jul 2, 2021
@camelid

Copy link
Copy Markdown
MemberAuthor

Actually, it looks like this was fixed in the meantime by #86451! (Although that's only for HTML summaries; plain text summaries that are used for alt-text have not yet been fixed.) I'll close this then.

@camelidcamelid closed this Aug 9, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-markdown-parsingArea: Markdown parsing for doc-commentsA-rustdoc-searchArea: Rustdoc's search featureC-enhancementCategory: An issue proposing an enhancement or a PR with one.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-rustdocRelevant 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.

4 participants

@camelid@jyn514@rust-highfive@rustbot