From fa095a836486cd2e39ce64071ca72cee601bfc32 Mon Sep 17 00:00:00 2001 From: binarycat Date: Mon, 4 Aug 2025 14:06:19 -0500 Subject: [PATCH] don't emit rustdoc::broken_intra_doc_links for stuff like [!NOTE] --- .../passes/collect_intra_doc_links.rs | 19 +++++++++++++++++-- .../intra-doc/github-flavored-blockquote.rs | 6 ++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/rustdoc-ui/intra-doc/github-flavored-blockquote.rs diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index c9fa3a4837f29..3ac0e4cb2d1de 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -997,6 +997,7 @@ fn preprocess_link( } }; + let is_shortcut_style = ori_link.kind == LinkType::ShortcutUnknown; // If there's no backticks, be lenient and revert to the old behavior. // This is to prevent churn by linting on stuff that isn't meant to be a link. // only shortcut links have simple enough syntax that they @@ -1013,11 +1014,25 @@ fn preprocess_link( // | has backtick | never ignore | never ignore | // | no backtick | ignore if url-like | never ignore | // |-------------------------------------------------------| - let ignore_urllike = - can_be_url || (ori_link.kind == LinkType::ShortcutUnknown && !ori_link.link.contains('`')); + let ignore_urllike = can_be_url || (is_shortcut_style && !ori_link.link.contains('`')); if ignore_urllike && should_ignore_link(path_str) { return None; } + // ignore github flavored markdown special blockquotes, + // such as [!NOTE] and [!IMPORTANT] + // + // rustdoc does not support github-flavored markdown, + // however it is a common pattern to add #[doc = include_str!("../README.md")] to the root of a crate, + // so we want to at least accept github-flavored markdown, even if it doesn't render perfectly. + // + // we do allow [!] as a link to the never type. + if is_shortcut_style + && ori_link.link.starts_with('!') + && ori_link.link.len() > 1 + && ori_link.link[1..].chars().all(|c| c.is_ascii_alphabetic()) + { + return None; + } // Strip generics from the path. let path_str = match strip_generics_from_path(path_str) { diff --git a/tests/rustdoc-ui/intra-doc/github-flavored-blockquote.rs b/tests/rustdoc-ui/intra-doc/github-flavored-blockquote.rs new file mode 100644 index 0000000000000..d5fa72eb993f9 --- /dev/null +++ b/tests/rustdoc-ui/intra-doc/github-flavored-blockquote.rs @@ -0,0 +1,6 @@ +// regression test for https://github.com/rust-lang/rust/issues/141866 +//@ check-pass +#![deny(rustdoc::broken_intra_doc_links)] + +//! > [!NOTE] +//! > This should not cause any warnings