From 04c8f3cba3a31ea776e12cf12f8d87ae85bb1700 Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 18 Oct 2017 00:05:37 +0500 Subject: [PATCH 1/2] Minor codestyle fixes --- src/lib.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3dfecc4..2e088b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -951,9 +951,9 @@ impl Handle { } // The result has been collected, whether or not we were the caller that // collected it. Return a reference. - match self.result.borrow().expect("result not filled") { - &Ok(ref output) => Ok(output), - &Err(ref err) => Err(clone_io_error(err)), + match *self.result.borrow().expect("result not filled") { + Ok(ref output) => Ok(output), + Err(ref err) => Err(clone_io_error(err)), } } @@ -1189,11 +1189,7 @@ fn pipe_status_precedence( (Some(left), Some(right)) => (left, right), _ => return None, }; - Some(if right_status.is_checked_error() { - right_status - } else if left_status.is_checked_error() { - left_status - } else if !right_status.status.success() { + Some(if right_status.is_checked_error() || !right_status.status.success() { right_status } else { left_status @@ -1217,7 +1213,7 @@ impl ThenHandle { right_lock: Mutex::new(Some((right, context))), right_cell: AtomicLazyCell::new(), }); - let clone = shared.clone(); + let clone = Arc::clone(&shared); let background_waiter = std::thread::spawn(move || { Ok(clone.wait(WaitMode::Blocking)?.expect( "blocking wait can't return None", @@ -1341,7 +1337,7 @@ fn start_io( match *io_inner { Input(ref v) => { return Ok(HandleInner::Input(Box::new( - InputHandle::start(expr_inner, context, v.clone())?, + InputHandle::start(expr_inner, context, Arc::clone(v))?, ))) } Stdin(ref p) => { @@ -1539,12 +1535,12 @@ enum IoValue { impl IoValue { fn try_clone(&self) -> io::Result { - Ok(match self { - &IoValue::ParentStdin => IoValue::ParentStdin, - &IoValue::ParentStdout => IoValue::ParentStdout, - &IoValue::ParentStderr => IoValue::ParentStderr, - &IoValue::Null => IoValue::Null, - &IoValue::Handle(ref f) => IoValue::Handle(f.try_clone()?), + Ok(match *self { + IoValue::ParentStdin => IoValue::ParentStdin, + IoValue::ParentStdout => IoValue::ParentStdout, + IoValue::ParentStderr => IoValue::ParentStderr, + IoValue::Null => IoValue::Null, + IoValue::Handle(ref f) => IoValue::Handle(f.try_clone()?), }) } @@ -1804,8 +1800,7 @@ impl WaitMode { // guaranteed to finish soon). Blocking waits should always join, even // in the presence of errors. match (self, expression_result) { - (&WaitMode::Blocking, _) => true, - (_, &Ok(Some(_))) => true, + (&WaitMode::Blocking, _) | (_, &Ok(Some(_))) => true, _ => false, } } From 612a1c7f0131b6d877c50a32cc63354a98bd66f4 Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 18 Oct 2017 00:33:47 +0500 Subject: [PATCH 2/2] Fixed an error I missed --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2e088b3..e73c47d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1189,7 +1189,11 @@ fn pipe_status_precedence( (Some(left), Some(right)) => (left, right), _ => return None, }; - Some(if right_status.is_checked_error() || !right_status.status.success() { + Some(if right_status.is_checked_error() { + right_status + } else if left_status.is_checked_error() { + left_status + } else if !right_status.status.success() { right_status } else { left_status