Plumb through rustc_lint_defs::Level as enum rather than string.

This commit is contained in:
Jeremy Fitzhardinge 2022-04-15 01:24:49 -07:00 committed by Jeremy Fitzhardinge
parent 39f2f18463
commit 0529a13b5d
5 changed files with 19 additions and 9 deletions

View File

@ -212,7 +212,12 @@ pub trait Emitter {
fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {} fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {}
/// Emit list of unused externs /// 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" /// Checks if should show explanations about "rustc --explain"
fn should_show_explain(&self) -> bool { fn should_show_explain(&self) -> bool {

View File

@ -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 data = UnusedExterns { lint_level, unused_extern_names: unused_externs };
let result = if self.pretty { let result = if self.pretty {
writeln!(&mut self.dst, "{}", as_pretty_json(&data)) writeln!(&mut self.dst, "{}", as_pretty_json(&data))

View File

@ -969,10 +969,10 @@ impl Handler {
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags) 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(); let mut inner = self.inner.borrow_mut();
if lint_level == "deny" || lint_level == "forbid" { if lint_level.is_error() {
inner.bump_err_count(); inner.bump_err_count();
} }
@ -1147,7 +1147,7 @@ impl HandlerInner {
self.emitter.emit_artifact_notification(path, artifact_type); 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); self.emitter.emit_unused_externs(lint_level, unused_externs);
} }

View File

@ -214,6 +214,13 @@ impl Level {
_ => None, _ => 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. /// Specification of a single lint.

View File

@ -208,10 +208,7 @@ impl CStore {
let unused_externs = let unused_externs =
self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>(); self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>(); let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>();
tcx.sess tcx.sess.parse_sess.span_diagnostic.emit_unused_externs(level, &unused_externs);
.parse_sess
.span_diagnostic
.emit_unused_externs(level.as_str(), &unused_externs);
} }
} }
} }