diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 47cdf39cd52..5dd743e8d00 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -212,7 +212,12 @@ pub trait Emitter { fn emit_future_breakage_report(&mut self, _diags: Vec) {} /// Emit list of unused externs - fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {} + fn emit_unused_externs( + &mut self, + _lint_level: rustc_lint_defs::Level, + _unused_externs: &[&str], + ) { + } /// Checks if should show explanations about "rustc --explain" fn should_show_explain(&self) -> bool { diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index d680e7fab70..6ff52182d6b 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -171,7 +171,8 @@ impl Emitter for JsonEmitter { } } - fn emit_unused_externs(&mut self, lint_level: &str, unused_externs: &[&str]) { + fn emit_unused_externs(&mut self, lint_level: rustc_lint_defs::Level, unused_externs: &[&str]) { + let lint_level = lint_level.as_str(); let data = UnusedExterns { lint_level, unused_extern_names: unused_externs }; let result = if self.pretty { writeln!(&mut self.dst, "{}", as_pretty_json(&data)) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 9f126d25a8d..3842ccbb2ef 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -969,10 +969,10 @@ impl Handler { self.inner.borrow_mut().emitter.emit_future_breakage_report(diags) } - pub fn emit_unused_externs(&self, lint_level: &str, unused_externs: &[&str]) { + pub fn emit_unused_externs(&self, lint_level: rustc_lint_defs::Level, unused_externs: &[&str]) { let mut inner = self.inner.borrow_mut(); - if lint_level == "deny" || lint_level == "forbid" { + if lint_level.is_error() { inner.bump_err_count(); } @@ -1147,7 +1147,7 @@ impl HandlerInner { self.emitter.emit_artifact_notification(path, artifact_type); } - fn emit_unused_externs(&mut self, lint_level: &str, unused_externs: &[&str]) { + fn emit_unused_externs(&mut self, lint_level: rustc_lint_defs::Level, unused_externs: &[&str]) { self.emitter.emit_unused_externs(lint_level, unused_externs); } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index f590172af4f..57b4f96dc10 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -214,6 +214,13 @@ impl Level { _ => None, } } + + pub fn is_error(self) -> bool { + match self { + Level::Allow | Level::Expect(_) | Level::Warn | Level::ForceWarn => false, + Level::Deny | Level::Forbid => true, + } + } } /// Specification of a single lint. diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index e8cdae7fd25..5ef89ce618e 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -208,10 +208,7 @@ impl CStore { let unused_externs = self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::>(); let unused_externs = unused_externs.iter().map(String::as_str).collect::>(); - tcx.sess - .parse_sess - .span_diagnostic - .emit_unused_externs(level.as_str(), &unused_externs); + tcx.sess.parse_sess.span_diagnostic.emit_unused_externs(level, &unused_externs); } } }