]> git.lizzy.rs Git - rust.git/commitdiff
Dedup a rustdoc diagnostic construction
authorDale Wijnand <dale.wijnand@gmail.com>
Wed, 20 Feb 2019 10:17:23 +0000 (10:17 +0000)
committerDale Wijnand <dale.wijnand@gmail.com>
Wed, 20 Feb 2019 14:07:07 +0000 (14:07 +0000)
src/librustdoc/passes/collect_intra_doc_links.rs

index 62b79646f6b0808301be68c5582d58beaddeca7e..7f7fffbba100ee9038f5cf8da286deab31fa406f 100644 (file)
@@ -458,26 +458,18 @@ fn resolution_failure(
     link_range: Option<Range<usize>>,
 ) {
     let sp = span_of_attrs(attrs);
-    let msg = format!("`[{}]` cannot be resolved, ignoring it...", path_str);
 
-    let mut diag = if let Some(link_range) = link_range {
+    let mut diag = cx.tcx.struct_span_lint_node(
+        lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
+        NodeId::from_u32(0),
+        sp,
+        &format!("`[{}]` cannot be resolved, ignoring it...", path_str),
+    );
+    if let Some(link_range) = link_range {
         if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) {
-            let mut diag = cx.tcx.struct_span_lint_node(
-                lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
-                NodeId::from_u32(0),
-                sp,
-                &msg,
-            );
+            diag.set_span(sp);
             diag.span_label(sp, "cannot be resolved, ignoring");
-            diag
         } else {
-            let mut diag = cx.tcx.struct_span_lint_node(
-                lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
-                NodeId::from_u32(0),
-                sp,
-                &msg,
-            );
-
             // blah blah blah\nblah\nblah [blah] blah blah\nblah blah
             //                       ^     ~~~~
             //                       |     link_range
@@ -494,13 +486,7 @@ fn resolution_failure(
                 before=link_range.start - last_new_line_offset,
                 found=link_range.len(),
             ));
-            diag
         }
-    } else {
-        cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
-                                     NodeId::from_u32(0),
-                                     sp,
-                                     &msg)
     };
     diag.help("to escape `[` and `]` characters, just add '\\' before them like \
                `\\[` or `\\]`");