Skip to content

Commit 1fd22fc

Browse files
authored
Rollup merge of rust-lang#76689 - jyn514:update-pulldown, r=GuillaumeGomez
Upgrade to pulldown-cmark 0.8.0 Thanks to marcusklaas' hard work in pulldown-cmark/pulldown-cmark#469, this fixes a lot of rustdoc bugs! - Get rid of unnecessary `RefCell` - Fix duplicate warnings for broken implicit reference link - Remove unnecessary copy of links Closes rust-lang#73264, closes rust-lang#76687. r? @euclio I'm not sure if the switch away from `locate` fixes any open bugs - euclio mentioned some in pulldown-cmark/pulldown-cmark#165, but I didn't see any related issues open for rustdoc. Let me know if I missed one.
2 parents 69ac076 + 6f2e1c6 commit 1fd22fc

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

Cargo.lock

+14-3
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ dependencies = [
534534
"if_chain",
535535
"itertools 0.9.0",
536536
"lazy_static",
537-
"pulldown-cmark",
537+
"pulldown-cmark 0.7.2",
538538
"quine-mc_cluskey",
539539
"quote",
540540
"regex-syntax",
@@ -1853,7 +1853,7 @@ dependencies = [
18531853
"log",
18541854
"memchr",
18551855
"open",
1856-
"pulldown-cmark",
1856+
"pulldown-cmark 0.7.2",
18571857
"regex",
18581858
"serde",
18591859
"serde_derive",
@@ -2511,6 +2511,17 @@ dependencies = [
25112511
"unicase",
25122512
]
25132513

2514+
[[package]]
2515+
name = "pulldown-cmark"
2516+
version = "0.8.0"
2517+
source = "registry+https://github.com/rust-lang/crates.io-index"
2518+
checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
2519+
dependencies = [
2520+
"bitflags",
2521+
"memchr",
2522+
"unicase",
2523+
]
2524+
25142525
[[package]]
25152526
name = "punycode"
25162527
version = "0.4.1"
@@ -4122,7 +4133,7 @@ dependencies = [
41224133
"expect-test",
41234134
"itertools 0.9.0",
41244135
"minifier",
4125-
"pulldown-cmark",
4136+
"pulldown-cmark 0.8.0",
41264137
"rustc-rayon",
41274138
"serde",
41284139
"serde_json",

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
path = "lib.rs"
99

1010
[dependencies]
11-
pulldown-cmark = { version = "0.7", default-features = false }
11+
pulldown-cmark = { version = "0.8", default-features = false }
1212
minifier = "0.0.33"
1313
rayon = { version = "0.3.0", package = "rustc-rayon" }
1414
serde = { version = "1.0", features = ["derive"] }

src/librustdoc/html/markdown.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_session::lint;
2727
use rustc_span::edition::Edition;
2828
use rustc_span::Span;
2929
use std::borrow::Cow;
30-
use std::cell::RefCell;
3130
use std::collections::VecDeque;
3231
use std::default::Default;
3332
use std::fmt::Write;
@@ -39,7 +38,7 @@ use crate::doctest;
3938
use crate::html::highlight;
4039
use crate::html::toc::TocBuilder;
4140

42-
use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, Options, Parser, Tag};
41+
use pulldown_cmark::{html, BrokenLink, CodeBlockKind, CowStr, Event, Options, Parser, Tag};
4342

4443
#[cfg(test)]
4544
mod tests;
@@ -931,15 +930,17 @@ impl Markdown<'_> {
931930
if md.is_empty() {
932931
return String::new();
933932
}
934-
let replacer = |_: &str, s: &str| {
935-
if let Some(link) = links.iter().find(|link| &*link.original_text == s) {
936-
Some((link.href.clone(), link.new_text.clone()))
933+
let mut replacer = |broken_link: BrokenLink<'_>| {
934+
if let Some(link) =
935+
links.iter().find(|link| &*link.original_text == broken_link.reference)
936+
{
937+
Some((link.href.as_str().into(), link.new_text.as_str().into()))
937938
} else {
938939
None
939940
}
940941
};
941942

942-
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&replacer));
943+
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer));
943944

944945
let mut s = String::with_capacity(md.len() * 3 / 2);
945946

@@ -1009,9 +1010,11 @@ impl MarkdownSummaryLine<'_> {
10091010
return String::new();
10101011
}
10111012

1012-
let replacer = |_: &str, s: &str| {
1013-
if let Some(link) = links.iter().find(|link| &*link.original_text == s) {
1014-
Some((link.href.clone(), link.new_text.clone()))
1013+
let mut replacer = |broken_link: BrokenLink<'_>| {
1014+
if let Some(link) =
1015+
links.iter().find(|link| &*link.original_text == broken_link.reference)
1016+
{
1017+
Some((link.href.as_str().into(), link.new_text.as_str().into()))
10151018
} else {
10161019
None
10171020
}
@@ -1020,7 +1023,7 @@ impl MarkdownSummaryLine<'_> {
10201023
let p = Parser::new_with_broken_link_callback(
10211024
md,
10221025
Options::ENABLE_STRIKETHROUGH,
1023-
Some(&replacer),
1026+
Some(&mut replacer),
10241027
);
10251028

10261029
let mut s = String::new();
@@ -1067,7 +1070,7 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
10671070
}
10681071

10691072
let mut links = vec![];
1070-
let shortcut_links = RefCell::new(vec![]);
1073+
let mut shortcut_links = vec![];
10711074

10721075
{
10731076
let locate = |s: &str| unsafe {
@@ -1084,11 +1087,13 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
10841087
}
10851088
};
10861089

1087-
let push = |_: &str, s: &str| {
1088-
shortcut_links.borrow_mut().push((s.to_owned(), locate(s)));
1090+
let mut push = |link: BrokenLink<'_>| {
1091+
// FIXME: use `link.span` instead of `locate`
1092+
// (doing it now includes the `[]` as well as the text)
1093+
shortcut_links.push((link.reference.to_owned(), locate(link.reference)));
10891094
None
10901095
};
1091-
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&push));
1096+
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut push));
10921097

10931098
// There's no need to thread an IdMap through to here because
10941099
// the IDs generated aren't going to be emitted anywhere.
@@ -1106,8 +1111,7 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
11061111
}
11071112
}
11081113

1109-
let mut shortcut_links = shortcut_links.into_inner();
1110-
links.extend(shortcut_links.drain(..));
1114+
links.append(&mut shortcut_links);
11111115

11121116
links
11131117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-pass
2+
3+
// regression test for #73264
4+
// should only give one error
5+
/// docs [label][with#anchor#error]
6+
//~^ WARNING multiple anchors
7+
pub struct S;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: `with#anchor#error` contains multiple anchors
2+
--> $DIR/intra-link-double-anchor.rs:5:18
3+
|
4+
LL | /// docs [label][with#anchor#error]
5+
| ^^^^^^^^^^^^^^^^^ contains invalid anchor
6+
|
7+
= note: `#[warn(broken_intra_doc_links)]` on by default
8+
9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)