Skip to content

Commit

Permalink
Fix unnecessary question mark warnings (vercel/turbo#2443)
Browse files Browse the repository at this point in the history
* Fix unused question marks warnings

Fix some return types that were giving clippy warnings, mostly `needless_question_mark`.
Remaining warnings are either `too_many_arguments` or `type_complexity`.

* Fix unncessary let binding

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
  • Loading branch information
Allan and jridgewell committed Oct 28, 2022
1 parent ab4bf8d commit 43cc99e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
19 changes: 8 additions & 11 deletions crates/next-core/src/nodejs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@ async fn render_static(
let pool = renderer_pool.strongly_consistent().await?;
let mut operation = match pool.operation().await {
Ok(operation) => operation,
Err(err) => {
return Ok(static_error(path, err, None, fallback_page).await?);
}
Err(err) => return static_error(path, err, None, fallback_page).await,
};

match run_static_operation(
Expand All @@ -302,7 +300,7 @@ async fn render_static(
.await
{
Ok(asset) => Ok(asset),
Err(err) => Ok(static_error(path, err, Some(operation), fallback_page).await?),
Err(err) => static_error(path, err, Some(operation), fallback_page).await,
}
}

Expand Down Expand Up @@ -351,10 +349,9 @@ async fn static_error(
None => None,
};

let html_status = if let Some(status) = status {
format!("<h2>Exit status</h2><pre>{status}</pre>")
} else {
format!("<h3>No exit status</pre>")
let html_status = match status {
Some(status) => format!("<h2>Exit status</h2><pre>{status}</pre>"),
None => "<h3>No exit status</pre>".to_owned(),
};

let body = format!(
Expand Down Expand Up @@ -387,7 +384,7 @@ async fn trace_stack(
) -> Result<String> {
let root = match to_sys_path(intermediate_output_path.root()).await? {
Some(r) => r.to_string_lossy().to_string(),
_ => bail!("couldn't extract disk fs from path"),
None => bail!("couldn't extract disk fs from path"),
};

let map_ext = OsStr::new("map");
Expand Down Expand Up @@ -517,7 +514,7 @@ async fn render_proxy(
let mut operation = match pool.operation().await {
Ok(operation) => operation,
Err(err) => {
return Ok(proxy_error(path, err, None).await?);
return proxy_error(path, err, None).await;
}
};

Expand Down Expand Up @@ -545,7 +542,7 @@ async fn run_proxy_operation(
let data = data.await?;
// First, send the render data.
operation
.send(RenderProxyOutgoingMessage::Headers { data: &*data })
.send(RenderProxyOutgoingMessage::Headers { data: &data })
.await?;

let body = body.await?;
Expand Down
27 changes: 13 additions & 14 deletions crates/next-core/src/nodejs/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,20 @@ impl NodeJsPool {

async fn acquire_process(&self) -> Result<(NodeJsPoolProcess, OwnedSemaphorePermit)> {
let permit = self.semaphore.clone().acquire_owned().await?;

let popped = {
let mut processes = self.processes.lock().unwrap();
processes.pop()
};
Ok(if let Some(process) = popped {
(process, permit)
} else {
let process =
let process = match popped {
Some(process) => process,
None => {
NodeJsPoolProcess::new(self.cwd.as_path(), &self.env, self.entrypoint.as_path())
.await
.context("creating new process")?;
(process, permit)
})
.context("creating new process")?
}
};
Ok((process, permit))
}

pub(super) async fn operation(&self) -> Result<NodeJsOperation> {
Expand All @@ -224,10 +225,9 @@ pub struct NodeJsOperation {

impl NodeJsOperation {
fn process_mut(&mut self) -> Result<&mut RunningNodeJsPoolProcess> {
Ok(self
.process
self.process
.as_mut()
.context("Node.js operation already finished")?)
.context("Node.js operation already finished")
}

pub(super) async fn recv<M>(&mut self) -> Result<M>
Expand All @@ -239,18 +239,17 @@ impl NodeJsOperation {
.recv()
.await
.context("receiving message")?;
Ok(serde_json::from_slice(&message).context("deserializing message")?)
serde_json::from_slice(&message).context("deserializing message")
}

pub(super) async fn send<M>(&mut self, message: M) -> Result<()>
where
M: Serialize,
{
Ok(self
.process_mut()?
self.process_mut()?
.send(serde_json::to_vec(&message).context("serializing message")?)
.await
.context("sending message")?)
.context("sending message")
}

pub(super) async fn wait_or_kill(mut self) -> Result<ExitStatus> {
Expand Down

0 comments on commit 43cc99e

Please sign in to comment.