Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unnecessary question mark warnings #2443

Merged
merged 3 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions crates/turbo-tasks/src/no_move_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl<T> COption<T> {
let slice = Box::<[COption<T>]>::new_zeroed_slice(size);
// Safety:
// We know that a zeroed COption<T> is a valid COption::None value.
let slice = unsafe { slice.assume_init() };
slice
unsafe { slice.assume_init() }
}

/// Returns a reference to the contained value, or `None` if it is `None`.
Expand Down