Skip to content

Commit a09b688

Browse files
committed
don't emit rustdoc::broken_intra_doc_links for stuff like [!NOTE]
1 parent e1b9081 commit a09b688

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

library/std/benches/path.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,10 @@ fn bench_hash_path_long(b: &mut test::Bencher) {
112112

113113
black_box(hasher.finish());
114114
}
115+
116+
#[bench]
117+
fn bench_path_starts_with(b: &mut test::Bencher) {
118+
let path = Path::new("a/b/c/d/././e//f/g/");
119+
let prefix = "a/b//c/d/e";
120+
b.iter(|| black_box(path).starts_with(black_box(prefix)));
121+
}

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ fn preprocess_link(
997997
}
998998
};
999999

1000+
let is_shortcut_style = ori_link.kind == LinkType::ShortcutUnknown;
10001001
// If there's no backticks, be lenient and revert to the old behavior.
10011002
// This is to prevent churn by linting on stuff that isn't meant to be a link.
10021003
// only shortcut links have simple enough syntax that they
@@ -1013,11 +1014,25 @@ fn preprocess_link(
10131014
// | has backtick | never ignore | never ignore |
10141015
// | no backtick | ignore if url-like | never ignore |
10151016
// |-------------------------------------------------------|
1016-
let ignore_urllike =
1017-
can_be_url || (ori_link.kind == LinkType::ShortcutUnknown && !ori_link.link.contains('`'));
1017+
let ignore_urllike = can_be_url || (is_shortcut_style && !ori_link.link.contains('`'));
10181018
if ignore_urllike && should_ignore_link(path_str) {
10191019
return None;
10201020
}
1021+
// ignore github flavored markdown special blockquotes,
1022+
// such as [!NOTE] and [!IMPORTANT]
1023+
//
1024+
// rustdoc does not support github-flavored markdown,
1025+
// however it is a common pattern to add #[doc = include_str!("../README.md")] to the root of a crate,
1026+
// so we want to at least accept github-flavored markdown, even if it doesn't render perfectly.
1027+
//
1028+
// we do allow [!] as a link to the never type.
1029+
if is_shortcut_style
1030+
&& ori_link.link.starts_with('!')
1031+
&& ori_link.link.len() > 1
1032+
&& ori_link.link[1..].chars().all(|c| c.is_ascii_alphabetic())
1033+
{
1034+
return None;
1035+
}
10211036

10221037
// Strip generics from the path.
10231038
let path_str = match strip_generics_from_path(path_str) {

0 commit comments

Comments
 (0)