about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/json.rs
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2020-06-30 18:58:15 +0200
committerest31 <MTest31@outlook.com>2021-03-08 08:17:48 +0100
commitaef1e35edc11b3e0ecf7f77bc70c197062023476 (patch)
tree1cfe7f18b527bf750afb53f2cf3e0a45b12a430d /compiler/rustc_errors/src/json.rs
parent76c500ec6c36fa8287317d6dc342a64c079301de (diff)
downloadrust-aef1e35edc11b3e0ecf7f77bc70c197062023476.tar.gz
rust-aef1e35edc11b3e0ecf7f77bc70c197062023476.zip
Emit unused externs
Diffstat (limited to 'compiler/rustc_errors/src/json.rs')
-rw-r--r--compiler/rustc_errors/src/json.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs
index c27b39a9d62..a1ab98f766e 100644
--- a/compiler/rustc_errors/src/json.rs
+++ b/compiler/rustc_errors/src/json.rs
@@ -159,6 +159,19 @@ impl Emitter for JsonEmitter {
         }
     }
 
+    fn emit_unused_externs(&mut self, unused_externs: &[&str]) {
+        let data = UnusedExterns { unused_extern_names: unused_externs };
+        let result = if self.pretty {
+            writeln!(&mut self.dst, "{}", as_pretty_json(&data))
+        } else {
+            writeln!(&mut self.dst, "{}", as_json(&data))
+        }
+        .and_then(|_| self.dst.flush());
+        if let Err(e) = result {
+            panic!("failed to print unused externs: {:?}", e);
+        }
+    }
+
     fn source_map(&self) -> Option<&Lrc<SourceMap>> {
         Some(&self.sm)
     }
@@ -322,6 +335,12 @@ struct FutureIncompatReport {
     future_incompat_report: Vec<FutureBreakageItem>,
 }
 
+#[derive(Encodable)]
+struct UnusedExterns<'a, 'b> {
+    /// List of unused externs by their names.
+    unused_extern_names: &'a [&'b str],
+}
+
 impl Diagnostic {
     fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnostic {
         let sugg = diag.suggestions.iter().map(|sugg| Diagnostic {