diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/flycheck/src/lib.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 92ec4f92e..9335098ff 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs | |||
@@ -5,8 +5,9 @@ | |||
5 | use std::{ | 5 | use std::{ |
6 | fmt, | 6 | fmt, |
7 | io::{self, BufReader}, | 7 | io::{self, BufReader}, |
8 | ops, | ||
8 | path::PathBuf, | 9 | path::PathBuf, |
9 | process::{Command, Stdio}, | 10 | process::{self, Command, Stdio}, |
10 | time::Duration, | 11 | time::Duration, |
11 | }; | 12 | }; |
12 | 13 | ||
@@ -236,8 +237,9 @@ fn run_cargo( | |||
236 | mut command: Command, | 237 | mut command: Command, |
237 | on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool, | 238 | on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool, |
238 | ) -> io::Result<()> { | 239 | ) -> io::Result<()> { |
239 | let mut child = | 240 | let child = |
240 | command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()).spawn()?; | 241 | command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()).spawn()?; |
242 | let mut child = ChildKiller(child); | ||
241 | 243 | ||
242 | // We manually read a line at a time, instead of using serde's | 244 | // We manually read a line at a time, instead of using serde's |
243 | // stream deserializers, because the deserializer cannot recover | 245 | // stream deserializers, because the deserializer cannot recover |
@@ -283,3 +285,24 @@ fn run_cargo( | |||
283 | 285 | ||
284 | Ok(()) | 286 | Ok(()) |
285 | } | 287 | } |
288 | |||
289 | struct ChildKiller(process::Child); | ||
290 | |||
291 | impl ops::Deref for ChildKiller { | ||
292 | type Target = process::Child; | ||
293 | fn deref(&self) -> &process::Child { | ||
294 | &self.0 | ||
295 | } | ||
296 | } | ||
297 | |||
298 | impl ops::DerefMut for ChildKiller { | ||
299 | fn deref_mut(&mut self) -> &mut process::Child { | ||
300 | &mut self.0 | ||
301 | } | ||
302 | } | ||
303 | |||
304 | impl Drop for ChildKiller { | ||
305 | fn drop(&mut self) { | ||
306 | let _ = self.0.kill(); | ||
307 | } | ||
308 | } | ||