Add --extern-loc to augment unused crate dependency diagnostics

This allows a build system to indicate a location in its own dependency
specification files (eg Cargo's `Cargo.toml`) which can be reported
along side any unused crate dependency.

This supports several types of location:
 - 'json' - provide some json-structured data, which is included in the json diagnostics
     in a `tool_metadata` field
 - 'raw' - emit the provided string into the output. This also appears as a json string in
     `tool_metadata`.

If no `--extern-location` is explicitly provided then a default json entry of the form
`"tool_metadata":{"name":<cratename>,"path":<cratepath>}` is emitted.
This commit is contained in:
Jeremy Fitzhardinge 2020-05-25 16:21:25 -07:00
parent 9778068cbc
commit 82ccb6582a
44 changed files with 512 additions and 47 deletions

View file

@ -14,6 +14,7 @@ use rustc_span::source_map::{FilePathMapping, SourceMap};
use crate::emitter::{Emitter, HumanReadableErrorType};
use crate::registry::Registry;
use crate::DiagnosticId;
use crate::ToolMetadata;
use crate::{CodeSuggestion, SubDiagnostic};
use rustc_lint_defs::{Applicability, FutureBreakage};
@ -180,6 +181,8 @@ struct Diagnostic {
children: Vec<Diagnostic>,
/// The message as rustc would render it.
rendered: Option<String>,
/// Extra tool metadata
tool_metadata: ToolMetadata,
}
#[derive(Encodable)]
@ -269,6 +272,7 @@ impl Diagnostic {
spans: DiagnosticSpan::from_suggestion(sugg, je),
children: vec![],
rendered: None,
tool_metadata: sugg.tool_metadata.clone(),
});
// generate regular command line output and store it in the json
@ -312,6 +316,7 @@ impl Diagnostic {
.chain(sugg)
.collect(),
rendered: Some(output),
tool_metadata: ToolMetadata::default(),
}
}
@ -327,6 +332,7 @@ impl Diagnostic {
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, je)),
children: vec![],
rendered: None,
tool_metadata: ToolMetadata::default(),
}
}
}