Skip to content

Commit ad096d1

Browse files
committed
Dedup a rustdoc diagnostic construction
1 parent 74e35d2 commit ad096d1

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -458,26 +458,18 @@ fn resolution_failure(
458458
link_range: Option<Range<usize>>,
459459
) {
460460
let sp = span_of_attrs(attrs);
461-
let msg = format!("`[{}]` cannot be resolved, ignoring it...", path_str);
462461

463-
let mut diag = if let Some(link_range) = link_range {
462+
let mut diag = cx.tcx.struct_span_lint_node(
463+
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
464+
NodeId::from_u32(0),
465+
sp,
466+
&format!("`[{}]` cannot be resolved, ignoring it...", path_str),
467+
);
468+
if let Some(link_range) = link_range {
464469
if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) {
465-
let mut diag = cx.tcx.struct_span_lint_node(
466-
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
467-
NodeId::from_u32(0),
468-
sp,
469-
&msg,
470-
);
470+
diag.set_span(sp);
471471
diag.span_label(sp, "cannot be resolved, ignoring");
472-
diag
473472
} else {
474-
let mut diag = cx.tcx.struct_span_lint_node(
475-
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
476-
NodeId::from_u32(0),
477-
sp,
478-
&msg,
479-
);
480-
481473
// blah blah blah\nblah\nblah [blah] blah blah\nblah blah
482474
// ^ ~~~~
483475
// | link_range
@@ -494,13 +486,7 @@ fn resolution_failure(
494486
before=link_range.start - last_new_line_offset,
495487
found=link_range.len(),
496488
));
497-
diag
498489
}
499-
} else {
500-
cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
501-
NodeId::from_u32(0),
502-
sp,
503-
&msg)
504490
};
505491
diag.help("to escape `[` and `]` characters, just add '\\' before them like \
506492
`\\[` or `\\]`");

0 commit comments

Comments
 (0)