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:
@@ -4,7 +4,9 @@ use crate::Level;
|
||||
use crate::Substitution;
|
||||
use crate::SubstitutionPart;
|
||||
use crate::SuggestionStyle;
|
||||
use crate::ToolMetadata;
|
||||
use rustc_lint_defs::Applicability;
|
||||
use rustc_serialize::json::Json;
|
||||
use rustc_span::{MultiSpan, Span, DUMMY_SP};
|
||||
use std::fmt;
|
||||
|
||||
@@ -303,6 +305,7 @@ impl Diagnostic {
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::ShowCode,
|
||||
applicability,
|
||||
tool_metadata: Default::default(),
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -328,6 +331,7 @@ impl Diagnostic {
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::ShowCode,
|
||||
applicability,
|
||||
tool_metadata: Default::default(),
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -354,6 +358,7 @@ impl Diagnostic {
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::CompletelyHidden,
|
||||
applicability,
|
||||
tool_metadata: Default::default(),
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -408,6 +413,7 @@ impl Diagnostic {
|
||||
msg: msg.to_owned(),
|
||||
style,
|
||||
applicability,
|
||||
tool_metadata: Default::default(),
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -446,6 +452,7 @@ impl Diagnostic {
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::ShowCode,
|
||||
applicability,
|
||||
tool_metadata: Default::default(),
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -515,6 +522,23 @@ impl Diagnostic {
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds a suggestion intended only for a tool. The intent is that the metadata encodes
|
||||
/// the suggestion in a tool-specific way, as it may not even directly involve Rust code.
|
||||
pub fn tool_only_suggestion_with_metadata(
|
||||
&mut self,
|
||||
msg: &str,
|
||||
applicability: Applicability,
|
||||
tool_metadata: Json,
|
||||
) {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: vec![],
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::CompletelyHidden,
|
||||
applicability,
|
||||
tool_metadata: ToolMetadata::new(tool_metadata),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
|
||||
self.span = sp.into();
|
||||
if let Some(span) = self.span.primary_span() {
|
||||
|
||||
Reference in New Issue
Block a user