Skip to content

Commit 15fbe61

Browse files
committed
rustdoc: update to pulldown-cmark 0.11
1 parent b8d7dd8 commit 15fbe61

File tree

8 files changed

+94
-81
lines changed

8 files changed

+94
-81
lines changed

Cargo.lock

+14-7
Original file line numberDiff line numberDiff line change
@@ -3123,25 +3123,26 @@ dependencies = [
31233123

31243124
[[package]]
31253125
name = "pulldown-cmark"
3126-
version = "0.9.6"
3126+
version = "0.10.3"
31273127
source = "registry+https://github.com/rust-lang/crates.io-index"
3128-
checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b"
3128+
checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993"
31293129
dependencies = [
31303130
"bitflags 2.5.0",
3131+
"getopts",
31313132
"memchr",
3133+
"pulldown-cmark-escape 0.10.1",
31323134
"unicase",
31333135
]
31343136

31353137
[[package]]
31363138
name = "pulldown-cmark"
3137-
version = "0.10.3"
3139+
version = "0.11.0"
31383140
source = "registry+https://github.com/rust-lang/crates.io-index"
3139-
checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993"
3141+
checksum = "8746739f11d39ce5ad5c2520a9b75285310dbfe78c541ccf832d38615765aec0"
31403142
dependencies = [
31413143
"bitflags 2.5.0",
3142-
"getopts",
31433144
"memchr",
3144-
"pulldown-cmark-escape",
3145+
"pulldown-cmark-escape 0.11.0",
31453146
"unicase",
31463147
]
31473148

@@ -3151,6 +3152,12 @@ version = "0.10.1"
31513152
source = "registry+https://github.com/rust-lang/crates.io-index"
31523153
checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3"
31533154

3155+
[[package]]
3156+
name = "pulldown-cmark-escape"
3157+
version = "0.11.0"
3158+
source = "registry+https://github.com/rust-lang/crates.io-index"
3159+
checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
3160+
31543161
[[package]]
31553162
name = "pulldown-cmark-to-cmark"
31563163
version = "13.0.0"
@@ -4604,7 +4611,7 @@ name = "rustc_resolve"
46044611
version = "0.0.0"
46054612
dependencies = [
46064613
"bitflags 2.5.0",
4607-
"pulldown-cmark 0.9.6",
4614+
"pulldown-cmark 0.11.0",
46084615
"rustc_arena",
46094616
"rustc_ast",
46104617
"rustc_ast_pretty",

compiler/rustc_resolve/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9-
pulldown-cmark = { version = "0.9.6", default-features = false }
9+
pulldown-cmark = { version = "0.11", features = ["html"], default-features = false }
1010
rustc_arena = { path = "../rustc_arena" }
1111
rustc_ast = { path = "../rustc_ast" }
1212
rustc_ast_pretty = { path = "../rustc_ast_pretty" }

compiler/rustc_resolve/src/rustdoc.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use pulldown_cmark::{BrokenLink, CowStr, Event, LinkType, Options, Parser, Tag};
1+
use pulldown_cmark::{
2+
BrokenLink, BrokenLinkCallback, CowStr, Event, LinkType, Options, Parser, Tag,
3+
};
24
use rustc_ast as ast;
35
use rustc_ast::util::comments::beautify_doc_string;
46
use rustc_data_structures::fx::FxHashMap;
@@ -427,7 +429,9 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
427429

428430
while let Some(event) = event_iter.next() {
429431
match event {
430-
Event::Start(Tag::Link(link_type, dest, _)) if may_be_doc_link(link_type) => {
432+
Event::Start(Tag::Link { link_type, dest_url, title: _, id: _ })
433+
if may_be_doc_link(link_type) =>
434+
{
431435
if matches!(
432436
link_type,
433437
LinkType::Inline
@@ -441,7 +445,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
441445
}
442446
}
443447

444-
links.push(preprocess_link(&dest));
448+
links.push(preprocess_link(&dest_url));
445449
}
446450
_ => {}
447451
}
@@ -451,8 +455,8 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
451455
}
452456

453457
/// Collects additional data of link.
454-
fn collect_link_data<'input, 'callback>(
455-
event_iter: &mut Parser<'input, 'callback>,
458+
fn collect_link_data<'input, F: BrokenLinkCallback<'input>>(
459+
event_iter: &mut Parser<'input, F>,
456460
) -> Option<Box<str>> {
457461
let mut display_text: Option<String> = None;
458462
let mut append_text = |text: CowStr<'_>| {

src/librustdoc/html/markdown.rs

+54-57
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ use crate::html::render::small_url_encode;
5454
use crate::html::toc::TocBuilder;
5555

5656
use pulldown_cmark::{
57-
html, BrokenLink, CodeBlockKind, CowStr, Event, LinkType, OffsetIter, Options, Parser, Tag,
57+
html, BrokenLink, BrokenLinkCallback, CodeBlockKind, CowStr, Event, LinkType, OffsetIter,
58+
Options, Parser, Tag, TagEnd,
5859
};
5960

6061
#[cfg(test)]
@@ -230,7 +231,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
230231
let mut original_text = String::new();
231232
for event in &mut self.inner {
232233
match event {
233-
Event::End(Tag::CodeBlock(..)) => break,
234+
Event::End(TagEnd::CodeBlock) => break,
234235
Event::Text(ref s) => {
235236
original_text.push_str(s);
236237
}
@@ -359,16 +360,17 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
359360
match &mut event {
360361
// This is a shortcut link that was resolved by the broken_link_callback: `[fn@f]`
361362
// Remove any disambiguator.
362-
Some(Event::Start(Tag::Link(
363+
Some(Event::Start(Tag::Link {
363364
// [fn@f] or [fn@f][]
364-
LinkType::ShortcutUnknown | LinkType::CollapsedUnknown,
365-
dest,
365+
link_type: LinkType::ShortcutUnknown | LinkType::CollapsedUnknown,
366+
dest_url,
366367
title,
367-
))) => {
368-
debug!("saw start of shortcut link to {dest} with title {title}");
368+
..
369+
})) => {
370+
debug!("saw start of shortcut link to {dest_url} with title {title}");
369371
// If this is a shortcut link, it was resolved by the broken_link_callback.
370372
// So the URL will already be updated properly.
371-
let link = self.links.iter().find(|&link| *link.href == **dest);
373+
let link = self.links.iter().find(|&link| *link.href == **dest_url);
372374
// Since this is an external iterator, we can't replace the inner text just yet.
373375
// Store that we saw a link so we know to replace it later.
374376
if let Some(link) = link {
@@ -381,16 +383,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
381383
}
382384
}
383385
// Now that we're done with the shortcut link, don't replace any more text.
384-
Some(Event::End(Tag::Link(
385-
LinkType::ShortcutUnknown | LinkType::CollapsedUnknown,
386-
dest,
387-
_,
388-
))) => {
389-
debug!("saw end of shortcut link to {dest}");
390-
if self.links.iter().any(|link| *link.href == **dest) {
391-
assert!(self.shortcut_link.is_some(), "saw closing link without opening tag");
392-
self.shortcut_link = None;
393-
}
386+
Some(Event::End(TagEnd::Link)) if self.shortcut_link.is_some() => {
387+
debug!("saw end of shortcut link");
388+
self.shortcut_link = None;
394389
}
395390
// Handle backticks in inline code blocks, but only if we're in the middle of a shortcut link.
396391
// [`fn@f`]
@@ -433,9 +428,11 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
433428
}
434429
// If this is a link, but not a shortcut link,
435430
// replace the URL, since the broken_link_callback was not called.
436-
Some(Event::Start(Tag::Link(_, dest, title))) => {
437-
if let Some(link) = self.links.iter().find(|&link| *link.original_text == **dest) {
438-
*dest = CowStr::Borrowed(link.href.as_ref());
431+
Some(Event::Start(Tag::Link { dest_url, title, .. })) => {
432+
if let Some(link) =
433+
self.links.iter().find(|&link| *link.original_text == **dest_url)
434+
{
435+
*dest_url = CowStr::Borrowed(link.href.as_ref());
439436
if title.is_empty() && !link.tooltip.is_empty() {
440437
*title = CowStr::Borrowed(link.tooltip.as_ref());
441438
}
@@ -477,9 +474,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for TableWrapper<'a, I> {
477474
self.stored_events.push_back(Event::Start(Tag::Table(t)));
478475
Event::Html(CowStr::Borrowed("<div>"))
479476
}
480-
Event::End(Tag::Table(t)) => {
477+
Event::End(TagEnd::Table) => {
481478
self.stored_events.push_back(Event::Html(CowStr::Borrowed("</div>")));
482-
Event::End(Tag::Table(t))
479+
Event::End(TagEnd::Table)
483480
}
484481
e => e,
485482
})
@@ -519,11 +516,11 @@ impl<'a, 'b, 'ids, I: Iterator<Item = SpannedEvent<'a>>> Iterator
519516
}
520517

521518
let event = self.inner.next();
522-
if let Some((Event::Start(Tag::Heading(level, _, _)), _)) = event {
519+
if let Some((Event::Start(Tag::Heading { level, .. }), _)) = event {
523520
let mut id = String::new();
524521
for event in &mut self.inner {
525522
match &event.0 {
526-
Event::End(Tag::Heading(..)) => break,
523+
Event::End(TagEnd::Heading(_)) => break,
527524
Event::Text(text) | Event::Code(text) => {
528525
id.extend(text.chars().filter_map(slugify));
529526
self.buf.push_back(event);
@@ -566,27 +563,27 @@ impl<'a, I: Iterator<Item = Event<'a>>> SummaryLine<'a, I> {
566563
}
567564
}
568565

569-
fn check_if_allowed_tag(t: &Tag<'_>) -> bool {
566+
fn check_if_allowed_tag(t: &TagEnd) -> bool {
570567
matches!(
571568
t,
572-
Tag::Paragraph
573-
| Tag::Emphasis
574-
| Tag::Strong
575-
| Tag::Strikethrough
576-
| Tag::Link(..)
577-
| Tag::BlockQuote
569+
TagEnd::Paragraph
570+
| TagEnd::Emphasis
571+
| TagEnd::Strong
572+
| TagEnd::Strikethrough
573+
| TagEnd::Link
574+
| TagEnd::BlockQuote
578575
)
579576
}
580577

581-
fn is_forbidden_tag(t: &Tag<'_>) -> bool {
578+
fn is_forbidden_tag(t: &TagEnd) -> bool {
582579
matches!(
583580
t,
584-
Tag::CodeBlock(_)
585-
| Tag::Table(_)
586-
| Tag::TableHead
587-
| Tag::TableRow
588-
| Tag::TableCell
589-
| Tag::FootnoteDefinition(_)
581+
TagEnd::CodeBlock
582+
| TagEnd::Table
583+
| TagEnd::TableHead
584+
| TagEnd::TableRow
585+
| TagEnd::TableCell
586+
| TagEnd::FootnoteDefinition
590587
)
591588
}
592589

@@ -604,12 +601,12 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
604601
let mut is_start = true;
605602
let is_allowed_tag = match event {
606603
Event::Start(ref c) => {
607-
if is_forbidden_tag(c) {
604+
if is_forbidden_tag(&c.to_end()) {
608605
self.skipped_tags += 1;
609606
return None;
610607
}
611608
self.depth += 1;
612-
check_if_allowed_tag(c)
609+
check_if_allowed_tag(&c.to_end())
613610
}
614611
Event::End(ref c) => {
615612
if is_forbidden_tag(c) {
@@ -633,7 +630,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
633630
if is_start {
634631
Some(Event::Start(Tag::Paragraph))
635632
} else {
636-
Some(Event::End(Tag::Paragraph))
633+
Some(Event::End(TagEnd::Paragraph))
637634
}
638635
} else {
639636
Some(event)
@@ -679,7 +676,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> {
679676
Some((Event::Start(Tag::FootnoteDefinition(def)), _)) => {
680677
let mut content = Vec::new();
681678
for (event, _) in &mut self.inner {
682-
if let Event::End(Tag::FootnoteDefinition(..)) = event {
679+
if let Event::End(TagEnd::FootnoteDefinition) = event {
683680
break;
684681
}
685682
content.push(event);
@@ -696,7 +693,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> {
696693
for (mut content, id) in v {
697694
write!(ret, "<li id=\"fn{id}\">").unwrap();
698695
let mut is_paragraph = false;
699-
if let Some(&Event::End(Tag::Paragraph)) = content.last() {
696+
if let Some(&Event::End(TagEnd::Paragraph)) = content.last() {
700697
content.pop();
701698
is_paragraph = true;
702699
}
@@ -806,7 +803,7 @@ pub(crate) fn find_codes<T: doctest::DoctestVisitor>(
806803
tests.visit_test(text, block_info, line);
807804
prev_offset = offset.start;
808805
}
809-
Event::Start(Tag::Heading(level, _, _)) => {
806+
Event::Start(Tag::Heading { level, .. }) => {
810807
register_header = Some(level as u32);
811808
}
812809
Event::Text(ref s) if register_header.is_some() => {
@@ -1432,7 +1429,7 @@ impl MarkdownItemInfo<'_> {
14321429

14331430
// Treat inline HTML as plain text.
14341431
let p = p.map(|event| match event.0 {
1435-
Event::Html(text) => (Event::Text(text), event.1),
1432+
Event::Html(text) | Event::InlineHtml(text) => (Event::Text(text), event.1),
14361433
_ => event,
14371434
});
14381435

@@ -1442,7 +1439,7 @@ impl MarkdownItemInfo<'_> {
14421439
let p = Footnotes::new(p);
14431440
let p = TableWrapper::new(p.map(|(ev, _)| ev));
14441441
let p = p.filter(|event| {
1445-
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph))
1442+
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph))
14461443
});
14471444
html::push_html(&mut s, p);
14481445

@@ -1472,7 +1469,7 @@ impl MarkdownSummaryLine<'_> {
14721469
let mut s = String::new();
14731470

14741471
let without_paragraphs = LinkReplacer::new(&mut summary, links).filter(|event| {
1475-
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph))
1472+
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph))
14761473
});
14771474

14781475
html::push_html(&mut s, without_paragraphs);
@@ -1544,8 +1541,8 @@ fn markdown_summary_with_limit(
15441541
_ => {}
15451542
},
15461543
Event::End(tag) => match tag {
1547-
Tag::Emphasis | Tag::Strong => buf.close_tag(),
1548-
Tag::Paragraph | Tag::Heading(..) => return ControlFlow::Break(()),
1544+
TagEnd::Emphasis | TagEnd::Strong => buf.close_tag(),
1545+
TagEnd::Paragraph | TagEnd::Heading(_) => return ControlFlow::Break(()),
15491546
_ => {}
15501547
},
15511548
Event::HardBreak | Event::SoftBreak => buf.push(" ")?,
@@ -1605,8 +1602,8 @@ pub(crate) fn plain_text_summary(md: &str, link_names: &[RenderedLink]) -> Strin
16051602
}
16061603
Event::HardBreak | Event::SoftBreak => s.push(' '),
16071604
Event::Start(Tag::CodeBlock(..)) => break,
1608-
Event::End(Tag::Paragraph) => break,
1609-
Event::End(Tag::Heading(..)) => break,
1605+
Event::End(TagEnd::Paragraph) => break,
1606+
Event::End(TagEnd::Heading(..)) => break,
16101607
_ => (),
16111608
}
16121609
}
@@ -1765,7 +1762,7 @@ pub(crate) fn markdown_links<'md, R>(
17651762

17661763
while let Some((event, span)) = event_iter.next() {
17671764
match event {
1768-
Event::Start(Tag::Link(link_type, dest, _)) if may_be_doc_link(link_type) => {
1765+
Event::Start(Tag::Link { link_type, dest_url, .. }) if may_be_doc_link(link_type) => {
17691766
let range = match link_type {
17701767
// Link is pulled from the link itself.
17711768
LinkType::ReferenceUnknown | LinkType::ShortcutUnknown => {
@@ -1775,7 +1772,7 @@ pub(crate) fn markdown_links<'md, R>(
17751772
LinkType::Inline => span_for_offset_backward(span, b'(', b')'),
17761773
// Link is pulled from elsewhere in the document.
17771774
LinkType::Reference | LinkType::Collapsed | LinkType::Shortcut => {
1778-
span_for_link(&dest, span)
1775+
span_for_link(&dest_url, span)
17791776
}
17801777
LinkType::Autolink | LinkType::Email => unreachable!(),
17811778
};
@@ -1795,7 +1792,7 @@ pub(crate) fn markdown_links<'md, R>(
17951792

17961793
if let Some(link) = preprocess_link(MarkdownLink {
17971794
kind: link_type,
1798-
link: dest.into_string(),
1795+
link: dest_url.into_string(),
17991796
display_text,
18001797
range,
18011798
}) {
@@ -1810,8 +1807,8 @@ pub(crate) fn markdown_links<'md, R>(
18101807
}
18111808

18121809
/// Collects additional data of link.
1813-
fn collect_link_data<'input, 'callback>(
1814-
event_iter: &mut OffsetIter<'input, 'callback>,
1810+
fn collect_link_data<'input, F: BrokenLinkCallback<'input>>(
1811+
event_iter: &mut OffsetIter<'input, F>,
18151812
) -> Option<String> {
18161813
let mut display_text: Option<String> = None;
18171814
let mut append_text = |text: CowStr<'_>| {

0 commit comments

Comments
 (0)