Emit the lint level of the unused-crate-dependencies

Also, turn off the lint when the unused dependencies json flag
is specified so that cargo doesn't have to supress the lint
This commit is contained in:
est31 2020-08-10 01:57:35 +02:00
parent 13371b59ee
commit 3a62eb74db
6 changed files with 66 additions and 19 deletions

View file

@ -196,7 +196,7 @@ pub trait Emitter {
fn emit_future_breakage_report(&mut self, _diags: Vec<(FutureBreakage, Diagnostic)>) {}
/// Emit list of unused externs
fn emit_unused_externs(&mut self, _unused_externs: &[&str]) {}
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}
/// Checks if should show explanations about "rustc --explain"
fn should_show_explain(&self) -> bool {

View file

@ -159,8 +159,8 @@ impl Emitter for JsonEmitter {
}
}
fn emit_unused_externs(&mut self, unused_externs: &[&str]) {
let data = UnusedExterns { unused_extern_names: unused_externs };
fn emit_unused_externs(&mut self, lint_level: &str, unused_externs: &[&str]) {
let data = UnusedExterns { lint_level, unused_extern_names: unused_externs };
let result = if self.pretty {
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
} else {
@ -336,9 +336,11 @@ struct FutureIncompatReport {
}
#[derive(Encodable)]
struct UnusedExterns<'a, 'b> {
struct UnusedExterns<'a, 'b, 'c> {
/// The severity level of the unused dependencies lint
lint_level: &'a str,
/// List of unused externs by their names.
unused_extern_names: &'a [&'b str],
unused_extern_names: &'b [&'c str],
}
impl Diagnostic {

View file

@ -767,8 +767,8 @@ impl Handler {
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
}
pub fn emit_unused_externs(&self, unused_externs: &[&str]) {
self.inner.borrow_mut().emit_unused_externs(unused_externs)
pub fn emit_unused_externs(&self, lint_level: &str, unused_externs: &[&str]) {
self.inner.borrow_mut().emit_unused_externs(lint_level, unused_externs)
}
pub fn delay_as_bug(&self, diagnostic: Diagnostic) {
@ -845,8 +845,8 @@ impl HandlerInner {
self.emitter.emit_artifact_notification(path, artifact_type);
}
fn emit_unused_externs(&mut self, unused_externs: &[&str]) {
self.emitter.emit_unused_externs(unused_externs);
fn emit_unused_externs(&mut self, lint_level: &str, unused_externs: &[&str]) {
self.emitter.emit_unused_externs(lint_level, unused_externs);
}
fn treat_err_as_bug(&self) -> bool {