Skip to content

Commit 74b1eb3

Browse files
committed
source_span_for_markdown_range: fix utf8 violation
1 parent 642e49b commit 74b1eb3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,12 @@ pub fn source_span_for_markdown_range(
570570
{
571571
// If there is either a match in a previous fragment, or
572572
// multiple matches in this fragment, there is ambiguity.
573-
if match_data.is_none() && !snippet[match_start + 1..].contains(pat) {
573+
// the snippet cannot be zero-sized,
574+
// because it matches the pattern,
575+
// which is checked to not be zero sized.
576+
if match_data.is_none()
577+
&& !snippet.as_bytes().windows(pat.len()).any(|s| s == pat.as_bytes())
578+
{
574579
match_data = Some((i, match_start));
575580
} else {
576581
// Heirustic produced ambiguity, return nothing.

0 commit comments

Comments
 (0)