Skip to content

Commit

Permalink
Fix various warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsch committed May 19, 2023
1 parent b258439 commit b4accd5
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use {
/// Create a new server, bind it to an address, and serve responses until an error occurs.
pub async fn serve(serve_args: ServeArgs) -> Result<(), Error> {
// Load the wasm module into an execution context
let ctx = create_execution_context(&serve_args.shared(), true).await?;
let ctx = create_execution_context(serve_args.shared(), true).await?;

let addr = serve_args.addr();
ViceroyService::new(ctx).serve(addr).await?;
Expand Down Expand Up @@ -85,7 +85,7 @@ pub async fn main() -> ExitCode {
/// Execute a Wasm program in the Viceroy environment.
pub async fn run_wasm_main(run_args: RunArgs) -> Result<(), anyhow::Error> {
// Load the wasm module into an execution context
let ctx = create_execution_context(&run_args.shared(), false).await?;
let ctx = create_execution_context(run_args.shared(), false).await?;
let input = run_args.shared().input();
let program_name = match input.file_stem() {
Some(stem) => stem.to_string_lossy(),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl From<&ExperimentalModule> for ExperimentalModuleArg {
/// [opts]: struct.Opts.html
fn check_module(s: &str) -> Result<String, Error> {
let path = PathBuf::from(s);
let contents = std::fs::read(&path)?;
let contents = std::fs::read(path)?;
match wat::parse_bytes(&contents) {
Ok(_) => Ok(s.to_string()),
_ => Err(Error::FileFormat),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config/geolocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl GeolocationMapping {
pub fn read_json_contents(
file: &Path,
) -> Result<HashMap<IpAddr, GeolocationData>, GeolocationConfigError> {
let data = fs::read_to_string(&file).map_err(GeolocationConfigError::IoError)?;
let data = fs::read_to_string(file).map_err(GeolocationConfigError::IoError)?;

// Deserialize the contents of the given JSON file.
let json = match serde_json::from_str(&data)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config/secret_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl TryFrom<Table> for SecretStoreConfig {
err: SecretStoreConfigError::FileNotAString(key.to_string()),
}
})?;
fs::read(&path)
fs::read(path)
.map_err(|e| FastlyConfigError::InvalidSecretStoreDefinition {
name: store_name.to_string(),
err: SecretStoreConfigError::IoError(e),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl ExecuteCtx {

info!(
"request completed using {} of WebAssembly heap",
bytesize::ByteSize::kib(heap_pages as u64 * 64)
bytesize::ByteSize::kib(heap_pages * 64)
);

info!("request completed in {:.0?}", request_duration);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ impl<'session> SelectedTargets<'session> {

impl<'session> Drop for SelectedTargets<'session> {
fn drop(&mut self) {
let targets = std::mem::replace(&mut self.targets, Vec::new());
let targets = std::mem::take(&mut self.targets);
self.session.reinsert_select_targets(targets);
}
}
Expand Down
11 changes: 2 additions & 9 deletions lib/src/streaming_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ pub enum StreamingBodyItem {
Finished,
}

impl From<Chunk> for StreamingBodyItem {
fn from(chunk: Chunk) -> Self {
Self::Chunk(chunk)
}
}

impl StreamingBody {
/// Create a new channel for streaming a body, returning write and read ends as a pair.
pub fn new() -> (StreamingBody, mpsc::Receiver<StreamingBodyItem>) {
Expand All @@ -56,7 +50,7 @@ impl StreamingBody {
/// sending, e.g. due to the receive end being closed.
pub async fn send_chunk(&mut self, chunk: impl Into<Chunk>) -> Result<(), Error> {
self.sender
.send(Chunk::from(chunk.into()).into())
.send(StreamingBodyItem::Chunk(chunk.into()))
.await
.map_err(|_| Error::StreamingChunkSend)
}
Expand All @@ -78,9 +72,8 @@ impl StreamingBody {
// If the channel is full, maybe the other end is just taking a while to receive all
// the bytes. Spawn a task that will send a `finish` message as soon as there's room
// in the channel.
let sender = self.sender.clone();
tokio::task::spawn(async move {
let _ = sender.send(StreamingBodyItem::Finished).await;
let _ = self.sender.send(StreamingBodyItem::Finished).await;
});
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions lib/src/wiggle_abi/req_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,7 @@ impl FastlyHttpReq for Session {
&mut self,
pending_req_handle: PendingRequestHandle,
) -> Result<(u32, ResponseHandle, BodyHandle), Error> {
let handle: PendingRequestHandle = pending_req_handle.into();

if self.async_item_mut(handle.into())?.is_ready() {
if self.async_item_mut(pending_req_handle.into())?.is_ready() {
let resp = self
.take_pending_request(pending_req_handle)?
.recv()
Expand Down
2 changes: 1 addition & 1 deletion lib/src/wiggle_abi/secret_store_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl FastlySecretStore for Session {
.as_array(plaintext_len)
.as_slice_mut()?
.ok_or(Error::SharedMemory)?;
plaintext_out.copy_from_slice(&plaintext);
plaintext_out.copy_from_slice(plaintext);
nwritten_out.write(plaintext_len)?;

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions test-fixtures/src/bin/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! a distinct backend. Checks each for readiness, and then does a select with timeout against
//! all of them.
use std::io::Write;
use std::str::FromStr;

use fastly::handle::{BodyHandle, RequestHandle, ResponseHandle};
Expand Down Expand Up @@ -54,7 +55,7 @@ fn test_select() -> Result<(), Error> {
write_body_req.set_cache_override(&pass);
write_body_req.set_method(&Method::POST);
let mut write_body_initial = BodyHandle::new();
let initial_bytes = write_body_initial.write_bytes(&vec![0; INITIAL_BYTE_COUNT]);
let initial_bytes = write_body_initial.write(&vec![0; INITIAL_BYTE_COUNT])?;
assert_eq!(initial_bytes, INITIAL_BYTE_COUNT);
let (mut write_body, _write_body_pending_req) =
write_body_req.send_async_streaming(write_body_initial, "WriteBody")?;
Expand All @@ -65,7 +66,7 @@ fn test_select() -> Result<(), Error> {
// body we are streaming to it.
let one_chunk = vec![0; 8 * 1024];
while is_ready(write_body_handle) {
let nwritten = write_body.write_bytes(&one_chunk);
let nwritten = write_body.write(&one_chunk)?;
assert!(nwritten > 0);
}

Expand Down

0 comments on commit b4accd5

Please sign in to comment.