Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc-ui/intra-doc/github-flavored-admonitions.rs
Original file line number Diff line number Diff line change
@@ -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
Loading