about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-04-20 21:32:01 +0000
committerbors <bors@rust-lang.org>2022-04-20 21:32:01 +0000
commit879aff385a5fe0af78f3d45fd2f0b8762934e41e (patch)
tree325c0c0208780d05a1a7454c41c0b825b34df785
parent51ea9bb29b07d76c5a7167d054b54f4eb7f5b44e (diff)
parentf988f86cdc13f75386ea58bfa11a1b9cd632bac9 (diff)
downloadrust-879aff385a5fe0af78f3d45fd2f0b8762934e41e.tar.gz
rust-879aff385a5fe0af78f3d45fd2f0b8762934e41e.zip
Auto merge of #96187 - GuillaumeGomez:potential-intra-doc-links-filtering, r=notriddle
Prevent `<>` links to be interpreted for intra-doc links

As discussed in [this thread](https://github.com/rust-lang/rust/pull/96135#discussion_r852107956). As mentioned, the intra-doc RFC states that `<>` links shouldn't be potential intra-doc links:  https://rust-lang.github.io/rfcs/1946-intra-rustdoc-links.html#no-autolinks-style.

I renamed `markdown_links` into `potential_intra_doc_markdown_links` to make it more obvious what it's doing.

cc `@petrochenkov`
r? `@notriddle`
-rw-r--r--src/librustdoc/html/markdown.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index eafe6f17d44..b0f7836a834 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1312,7 +1312,19 @@ crate fn markdown_links<R>(md: &str, filter_map: impl Fn(MarkdownLink) -> Option
     let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids, HeadingOffset::H1));
 
     for ev in iter {
-        if let Event::Start(Tag::Link(kind, dest, _)) = ev.0 {
+        if let Event::Start(Tag::Link(
+            // `<>` links cannot be intra-doc links so we skip them.
+            kind @ (LinkType::Inline
+            | LinkType::Reference
+            | LinkType::ReferenceUnknown
+            | LinkType::Collapsed
+            | LinkType::CollapsedUnknown
+            | LinkType::Shortcut
+            | LinkType::ShortcutUnknown),
+            dest,
+            _,
+        )) = ev.0
+        {
             debug!("found link: {dest}");
             let span = span_for_link(&dest, ev.1);
             filter_map(MarkdownLink { kind, link: dest.into_string(), range: span })