From c50d9f36837bcbd9ac29f30e4983e0c0dd9b1fc9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 4 Dec 2020 13:54:09 +0100 Subject: Remove unnecessary `Option` --- crates/proc_macro_api/src/process.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'crates/proc_macro_api') diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index 907cb3db7..fca506905 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs @@ -19,7 +19,7 @@ use crate::{ #[derive(Debug, Default)] pub(crate) struct ProcMacroProcessSrv { - inner: Option>>, + inner: Weak>, } #[derive(Debug)] @@ -42,7 +42,7 @@ impl ProcMacroProcessSrv { }); let task_tx = Arc::new(task_tx); - let srv = ProcMacroProcessSrv { inner: Some(Arc::downgrade(&task_tx)) }; + let srv = ProcMacroProcessSrv { inner: Arc::downgrade(&task_tx) }; let thread = ProcMacroProcessThread { handle, sender: task_tx }; Ok((thread, srv)) @@ -79,13 +79,8 @@ impl ProcMacroProcessSrv { where R: TryFrom, { - let sender = match &self.inner { - None => return Err(tt::ExpansionError::Unknown("No sender is found.".to_string())), - Some(it) => it, - }; - let (result_tx, result_rx) = bounded(0); - let sender = match sender.upgrade() { + let sender = match self.inner.upgrade() { None => { return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into())) } -- cgit v1.2.3 From 2845ce5bc6d8bd2cadaf0acb3afc3d4e10c76fab Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 4 Dec 2020 13:57:33 +0100 Subject: Destructure in for loop --- crates/proc_macro_api/src/process.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'crates/proc_macro_api') diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index fca506905..0aeb38a8a 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs @@ -109,9 +109,7 @@ fn client_loop(task_rx: Receiver, mut process: Process) { Some(it) => it, }; - for task in task_rx { - let Task { req, result_tx } = task; - + for Task { req, result_tx } in task_rx { match send_request(&mut stdin, &mut stdout, req) { Ok(res) => result_tx.send(res).unwrap(), Err(_err) => { -- cgit v1.2.3 From b85714972081ac7d19d98008b7466d37f6d38432 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 4 Dec 2020 14:03:06 +0100 Subject: Unwrap `process.stdio()` result If this is ever `None` here, that's a bug --- crates/proc_macro_api/src/process.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'crates/proc_macro_api') diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index 0aeb38a8a..b66613c38 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs @@ -104,10 +104,7 @@ impl ProcMacroProcessSrv { } fn client_loop(task_rx: Receiver, mut process: Process) { - let (mut stdin, mut stdout) = match process.stdio() { - None => return, - Some(it) => it, - }; + let (mut stdin, mut stdout) = process.stdio().expect("couldn't access child stdio"); for Task { req, result_tx } in task_rx { match send_request(&mut stdin, &mut stdout, req) { -- cgit v1.2.3