-
Notifications
You must be signed in to change notification settings - Fork 13.8k
rustdoc: Strip broken links in summaries #79781
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1035,7 +1035,14 @@ fn markdown_summary_with_limit(md: &str, length_limit: usize) -> (String, bool) | |||
*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` | ||||
// if/when you update this one. They have to be duplicated because of a typesystem thing. | ||||
let mut broken_link_callback = | ||||
|broken_link: BrokenLink<'_>| Some(("#".into(), broken_link.reference.to_owned().into())); | ||||
|
// Replace intra-doc links and remove disambiguators from shortcut links (`[fn@f]`). |
[]
style links.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
fn markdown_summary_with_limit(
md: &str,
length_limit: usize,
broken_link_callback: Option<F>,
) -> (String, bool)
where
F: 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.