Skip to content

Commit cf429b0

Browse files
Simplify code for find_raw_urls
1 parent 3205e4d commit cf429b0

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/librustdoc/passes/lint/bare_urls.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,20 @@ fn find_raw_urls(
9393
trace!("looking for raw urls in {text}");
9494
// For now, we only check "full" URLs (meaning, starting with "http://" or "https://").
9595
for match_ in URL_REGEX.find_iter(text) {
96-
let url_range = match_.range();
96+
let mut url_range = match_.range();
97+
url_range.start += range.start;
98+
url_range.end += range.start;
9799
let mut without_brackets = None;
98-
let mut extra_range = 0;
99100
// If the whole text is contained inside `[]`, then we need to replace the brackets and
100101
// not just add `<>`.
101-
if whole_text[..range.start + url_range.start].ends_with('[')
102-
&& range.start + url_range.end <= whole_text.len()
103-
&& whole_text[range.start + url_range.end..].starts_with(']')
102+
if whole_text[..url_range.start].ends_with('[')
103+
&& url_range.end <= whole_text.len()
104+
&& whole_text[url_range.end..].starts_with(']')
104105
{
105-
extra_range = 1;
106+
url_range.start -= 1;
107+
url_range.end += 1;
106108
without_brackets = Some(match_.as_str());
107109
}
108-
f(
109-
cx,
110-
"this URL is not a hyperlink",
111-
Range {
112-
start: range.start + url_range.start - extra_range,
113-
end: range.start + url_range.end + extra_range,
114-
},
115-
without_brackets,
116-
);
110+
f(cx, "this URL is not a hyperlink", url_range, without_brackets);
117111
}
118112
}

0 commit comments

Comments
 (0)