Skip to content

Commit 73e1459

Browse files
rustdoc: Fix LinkReplacer link matching
1 parent 26c9868 commit 73e1459

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
382382
Some(Event::Code(text)) => {
383383
trace!("saw code {}", text);
384384
if let Some(link) = self.shortcut_link {
385-
trace!("original text was {}", link.original_text);
386385
// NOTE: this only replaces if the code block is the *entire* text.
387386
// If only part of the link has code highlighting, the disambiguator will not be removed.
388387
// e.g. [fn@`f`]
@@ -391,8 +390,11 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
391390
// So we could never be sure we weren't replacing too much:
392391
// [fn@my_`f`unc] is treated the same as [my_func()] in that pass.
393392
//
394-
// NOTE: &[1..len() - 1] is to strip the backticks
395-
if **text == link.original_text[1..link.original_text.len() - 1] {
393+
// NOTE: .get(1..len() - 1) is to strip the backticks
394+
if let Some(link) = self.links.iter().find(|l| {
395+
l.href == link.href
396+
&& Some(&**text) == l.original_text.get(1..l.original_text.len() - 1)
397+
}) {
396398
debug!("replacing {} with {}", text, link.new_text);
397399
*text = CowStr::Borrowed(&link.new_text);
398400
}
@@ -403,9 +405,10 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
403405
Some(Event::Text(text)) => {
404406
trace!("saw text {}", text);
405407
if let Some(link) = self.shortcut_link {
406-
trace!("original text was {}", link.original_text);
407408
// NOTE: same limitations as `Event::Code`
408-
if **text == *link.original_text {
409+
if let Some(link) =
410+
self.links.iter().find(|l| l.href == link.href && **text == l.original_text)
411+
{
409412
debug!("replacing {} with {}", text, link.new_text);
410413
*text = CowStr::Borrowed(&link.new_text);
411414
}

0 commit comments

Comments
 (0)