1
Fork 0

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

@ -4,6 +4,7 @@ extern crate rustc_macros;
pub use self::Level::*;
use rustc_ast::node_id::{NodeId, NodeMap};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_serialize::json::Json;
use rustc_span::edition::Edition;
use rustc_span::{sym, symbol::Ident, MultiSpan, Span, Symbol};
use rustc_target::spec::abi::Abi;
@ -239,6 +240,13 @@ impl<HCX> ToStableHashKey<HCX> for LintId {
}
}
// Duplicated from rustc_session::config::ExternDepSpec to avoid cyclic dependency
#[derive(PartialEq)]
pub enum ExternDepSpec {
Json(Json),
Raw(String),
}
// This could be a closure, but then implementing derive trait
// becomes hacky (and it gets allocated).
#[derive(PartialEq)]
@ -257,6 +265,7 @@ pub enum BuiltinLintDiagnostics {
UnusedDocComment(Span),
PatternsInFnsWithoutBody(Span, Ident),
LegacyDeriveHelpers(Span),
ExternDepSpec(String, ExternDepSpec),
}
/// Lints that are buffered up early on in the `Session` before the