diff options
| author | binarycat <binarycat@envs.net> | 2025-08-04 14:06:19 -0500 |
|---|---|---|
| committer | binarycat <binarycat@envs.net> | 2025-08-11 10:50:44 -0500 |
| commit | c022ed99274b6d8d243fcaac0450080e90e4c079 (patch) | |
| tree | 46da7a175ea87d40e8d5731e4fb3426de6ed886a | |
| parent | e1b9081e699065badfc1a9419ec9566e5c8615c4 (diff) | |
| download | rust-c022ed99274b6d8d243fcaac0450080e90e4c079.tar.gz rust-c022ed99274b6d8d243fcaac0450080e90e4c079.zip | |
don't emit rustdoc::broken_intra_doc_links for stuff like [!NOTE]
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links.rs | 16 | ||||
| -rw-r--r-- | tests/rustdoc-ui/intra-doc/github-flavored-admonitions.rs | 6 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index c9fa3a4837f..8b51066bf2f 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,22 @@ 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; } + // If we have an intra-doc link starting with `!` (which isn't `[!]` because this is the never type), we ignore it + // as it is never valid. + // + // The case is common enough because of cases like `#[doc = include_str!("../README.md")]` which often + // uses GitHub-flavored Markdown (GFM) admonitions, such as `[!NOTE]`. + if is_shortcut_style + && let Some(suffix) = ori_link.link.strip_prefix('!') + && !suffix.is_empty() + && suffix.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-admonitions.rs b/tests/rustdoc-ui/intra-doc/github-flavored-admonitions.rs new file mode 100644 index 00000000000..d5fa72eb993 --- /dev/null +++ b/tests/rustdoc-ui/intra-doc/github-flavored-admonitions.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 |
