Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 791f92c

Browse files
committed
don't emit suggestion if link cannot be located
partial fix for rust-lang#135851
1 parent 854f225 commit 791f92c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/librustdoc/passes/lint/bare_urls.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ use crate::html::markdown::main_body_opts;
1818

1919
pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &str) {
2020
let report_diag = |cx: &DocContext<'_>, msg: &'static str, range: Range<usize>| {
21-
let sp = source_span_for_markdown_range(cx.tcx, dox, &range, &item.attrs.doc_strings)
22-
.unwrap_or_else(|| item.attr_span(cx.tcx));
21+
let maybe_sp = source_span_for_markdown_range(cx.tcx, dox, &range, &item.attrs.doc_strings);
22+
let sp = maybe_sp.unwrap_or_else(|| item.attr_span(cx.tcx));
2323
cx.tcx.node_span_lint(crate::lint::BARE_URLS, hir_id, sp, |lint| {
2424
lint.primary_message(msg)
25-
.note("bare URLs are not automatically turned into clickable links")
26-
.multipart_suggestion(
25+
.note("bare URLs are not automatically turned into clickable links");
26+
// the fallback of using the item span is suitible for
27+
// highlighting where the error is, but not for placing the < and >
28+
if let Some(sp) = maybe_sp {
29+
lint.multipart_suggestion(
2730
"use an automatic link instead",
2831
vec![
2932
(sp.shrink_to_lo(), "<".to_string()),
3033
(sp.shrink_to_hi(), ">".to_string()),
3134
],
3235
Applicability::MachineApplicable,
3336
);
37+
}
3438
});
3539
};
3640

0 commit comments

Comments
 (0)