From 059307984e982ba53848807b9d1678253dd22af3 Mon Sep 17 00:00:00 2001
From: Marcin Mielniczuk <marmistrz.dev@zoho.eu>
Date: Sat, 8 Dec 2018 12:01:34 +0100
Subject: [PATCH] Workaround #703 to prevent obscure failures due to sccache.

---
 src/main.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/main.rs b/src/main.rs
index 2c4f638f97e..6441c2ef465 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,6 +60,7 @@ pub mod server;
 mod test;
 
 const RUSTC_SHIM_ENV_VAR_NAME: &str = "RLS_RUSTC_SHIM";
+const RUSTC_WRAPPER_ENV_VAR: &str = "RUSTC_WRAPPER";
 
 type Span = rls_span::Span<rls_span::ZeroIndexed>;
 
@@ -73,6 +74,17 @@ pub fn main() {
 fn main_inner() -> i32 {
     env_logger::init();
 
+    // [workaround]
+    // Currently sccache breaks RLS with obscure error messages.
+    // Until it's actually fixed disable the wrapper completely
+    // in the current process tree.
+    //
+    // See https://github.com/rust-lang/rls/issues/703
+    // and https://github.com/mozilla/sccache/issues/303
+   if env::var_os(RUSTC_WRAPPER_ENV_VAR).is_some() {
+        env::remove_var(RUSTC_WRAPPER_ENV_VAR);
+    }
+
     if env::var(RUSTC_SHIM_ENV_VAR_NAME)
         .map(|v| v != "0")
         .unwrap_or(false)