Skip to content

Commit 0529a13

Browse files
committed
Plumb through rustc_lint_defs::Level as enum rather than string.
1 parent 39f2f18 commit 0529a13

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ pub trait Emitter {
212212
fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {}
213213

214214
/// Emit list of unused externs
215-
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}
215+
fn emit_unused_externs(
216+
&mut self,
217+
_lint_level: rustc_lint_defs::Level,
218+
_unused_externs: &[&str],
219+
) {
220+
}
216221

217222
/// Checks if should show explanations about "rustc --explain"
218223
fn should_show_explain(&self) -> bool {

compiler/rustc_errors/src/json.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ impl Emitter for JsonEmitter {
171171
}
172172
}
173173

174-
fn emit_unused_externs(&mut self, lint_level: &str, unused_externs: &[&str]) {
174+
fn emit_unused_externs(&mut self, lint_level: rustc_lint_defs::Level, unused_externs: &[&str]) {
175+
let lint_level = lint_level.as_str();
175176
let data = UnusedExterns { lint_level, unused_extern_names: unused_externs };
176177
let result = if self.pretty {
177178
writeln!(&mut self.dst, "{}", as_pretty_json(&data))

compiler/rustc_errors/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,10 @@ impl Handler {
969969
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
970970
}
971971

972-
pub fn emit_unused_externs(&self, lint_level: &str, unused_externs: &[&str]) {
972+
pub fn emit_unused_externs(&self, lint_level: rustc_lint_defs::Level, unused_externs: &[&str]) {
973973
let mut inner = self.inner.borrow_mut();
974974

975-
if lint_level == "deny" || lint_level == "forbid" {
975+
if lint_level.is_error() {
976976
inner.bump_err_count();
977977
}
978978

@@ -1147,7 +1147,7 @@ impl HandlerInner {
11471147
self.emitter.emit_artifact_notification(path, artifact_type);
11481148
}
11491149

1150-
fn emit_unused_externs(&mut self, lint_level: &str, unused_externs: &[&str]) {
1150+
fn emit_unused_externs(&mut self, lint_level: rustc_lint_defs::Level, unused_externs: &[&str]) {
11511151
self.emitter.emit_unused_externs(lint_level, unused_externs);
11521152
}
11531153

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ impl Level {
214214
_ => None,
215215
}
216216
}
217+
218+
pub fn is_error(self) -> bool {
219+
match self {
220+
Level::Allow | Level::Expect(_) | Level::Warn | Level::ForceWarn => false,
221+
Level::Deny | Level::Forbid => true,
222+
}
223+
}
217224
}
218225

219226
/// Specification of a single lint.

compiler/rustc_metadata/src/creader.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ impl CStore {
208208
let unused_externs =
209209
self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
210210
let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>();
211-
tcx.sess
212-
.parse_sess
213-
.span_diagnostic
214-
.emit_unused_externs(level.as_str(), &unused_externs);
211+
tcx.sess.parse_sess.span_diagnostic.emit_unused_externs(level, &unused_externs);
215212
}
216213
}
217214
}

0 commit comments

Comments
 (0)