Skip to content

Commit

Permalink
Merge pull request #5362 from nyurik/inline-fmt3
Browse files Browse the repository at this point in the history
chore: inline format args to improve readability (3)
  • Loading branch information
xdoardo authored Jan 22, 2025
2 parents caf27dc + 174949d commit 94be28f
Show file tree
Hide file tree
Showing 36 changed files with 60 additions and 77 deletions.
2 changes: 1 addition & 1 deletion lib/wasix/src/bin_factory/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn call_module(
return;
}
Ok(WasiError::UnknownWasiVersion) => {
debug!("failed as wasi version is unknown",);
debug!("failed as wasi version is unknown");
runtime.on_taint(TaintReason::UnknownWasiVersion);
Ok(Errno::Noexec)
}
Expand Down
23 changes: 8 additions & 15 deletions lib/wasix/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ impl WasiFs {
Fd::READ,
self.root_inode.clone(),
)
.map_err(|e| format!("Could not create root fd: {}", e))?;
.map_err(|e| format!("Could not create root fd: {e}"))?;
self.preopen_fds.write().unwrap().push(fd);
Ok(())
}
Expand Down Expand Up @@ -1814,23 +1814,19 @@ impl WasiFs {
.create_inode(inodes, kind, true, preopen_name.clone())
.map_err(|e| {
format!(
"Failed to create inode for preopened dir (name `{}`): WASI error code: {}",
preopen_name, e
"Failed to create inode for preopened dir (name `{preopen_name}`): WASI error code: {e}",
)
})?;
let fd_flags = Fd::READ;
let fd = self
.create_fd(rights, rights, Fdflags::empty(), fd_flags, inode.clone())
.map_err(|e| format!("Could not open fd for file {:?}: {}", preopen_name, e))?;
.map_err(|e| format!("Could not open fd for file {preopen_name:?}: {e}"))?;
{
let mut guard = self.root_inode.write();
if let Kind::Root { entries } = guard.deref_mut() {
let existing_entry = entries.insert(preopen_name.clone(), inode);
if existing_entry.is_some() && !ignore_duplicates {
return Err(format!(
"Found duplicate entry for alias `{}`",
preopen_name
));
return Err(format!("Found duplicate entry for alias `{preopen_name}`"));
}
}
}
Expand All @@ -1853,7 +1849,7 @@ impl WasiFs {
let cur_dir_metadata = self
.root_fs
.metadata(path)
.map_err(|e| format!("Could not get metadata for file {:?}: {}", path, e))?;
.map_err(|e| format!("Could not get metadata for file {path:?}: {e}"))?;

let kind = if cur_dir_metadata.is_dir() {
Kind::Dir {
Expand Down Expand Up @@ -1917,10 +1913,7 @@ impl WasiFs {
self.create_inode(inodes, kind, true, path.to_string_lossy().into_owned())
}
.map_err(|e| {
format!(
"Failed to create inode for preopened dir: WASI error code: {}",
e
)
format!("Failed to create inode for preopened dir: WASI error code: {e}")
})?;
let fd_flags = {
let mut fd_flags = 0;
Expand All @@ -1938,7 +1931,7 @@ impl WasiFs {
};
let fd = self
.create_fd(rights, rights, Fdflags::empty(), fd_flags, inode.clone())
.map_err(|e| format!("Could not open fd for file {:?}: {}", path, e))?;
.map_err(|e| format!("Could not open fd for file {path:?}: {e}"))?;
{
let mut guard = self.root_inode.write();
if let Kind::Root { entries } = guard.deref_mut() {
Expand All @@ -1949,7 +1942,7 @@ impl WasiFs {
};
let existing_entry = entries.insert(key.clone(), inode);
if existing_entry.is_some() && !ignore_duplicates {
return Err(format!("Found duplicate entry for alias `{}`", key));
return Err(format!("Found duplicate entry for alias `{key}`"));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl std::fmt::Debug for HttpRequest {
} = self;

f.debug_struct("HttpRequest")
.field("url", &format_args!("{}", url))
.field("url", &format_args!("{url}"))
.field("method", method)
.field("headers", headers)
.field("body", &body.as_deref().map(String::from_utf8_lossy))
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl std::fmt::Display for ExtendedFsError {
write!(f, "fs error: {}", self.error)?;

if let Some(msg) = &self.message {
write!(f, " | {}", msg)?;
write!(f, " | {msg}")?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/os/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Commands {
unsafe {
InlineWaker::block_on(stderr_write(
parent_ctx,
format!("wasm command unknown - {}\r\n", path).as_bytes(),
format!("wasm command unknown - {path}\r\n").as_bytes(),
))
}
.ok();
Expand Down
9 changes: 3 additions & 6 deletions lib/wasix/src/os/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,9 @@ impl Console {
if let Err(err) = env.uses(self.uses.clone()) {
let mut stderr = self.stderr.clone();
InlineWaker::block_on(async {
virtual_fs::AsyncWriteExt::write_all(
&mut stderr,
format!("{}\r\n", err).as_bytes(),
)
.await
.ok();
virtual_fs::AsyncWriteExt::write_all(&mut stderr, format!("{err}\r\n").as_bytes())
.await
.ok();
});
tracing::debug!("failed to load used dependency - {}", err);
return Err(SpawnError::BadRequest);
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/runtime/resolver/backend_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ fn decode_summary(
};

let id = PackageId::Named(NamedPackageId {
full_name: format!("{}/{}", namespace, package_name),
full_name: format!("{namespace}/{package_name}"),
version: pkg_version
.version
.parse()
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/runtime/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn registry_error_message(specifier: &PackageSource) -> String {
}
PackageSource::Url(url) => format!("Unable to resolve \"{url}\""),
PackageSource::Path(path) => {
format!("Unable to load \"{}\" from disk", path)
format!("Unable to load \"{path}\" from disk")
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions lib/wasix/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub enum WasiStateCreationError {
fn validate_mapped_dir_alias(alias: &str) -> Result<(), WasiStateCreationError> {
if !alias.bytes().all(|b| b != b'\0') {
return Err(WasiStateCreationError::MappedDirAliasFormattingError(
format!("Alias \"{}\" contains a nul byte", alias),
format!("Alias \"{alias}\" contains a nul byte"),
));
}

Expand Down Expand Up @@ -774,16 +774,13 @@ impl WasiEnvBuilder {
}) {
Some(InvalidCharacter::Nul) => {
return Err(WasiStateCreationError::EnvironmentVariableFormatError(
format!("found nul byte in env var key \"{}\" (key=value)", env_key),
format!("found nul byte in env var key \"{env_key}\" (key=value)"),
))
}

Some(InvalidCharacter::Equal) => {
return Err(WasiStateCreationError::EnvironmentVariableFormatError(
format!(
"found equal sign in env var key \"{}\" (key=value)",
env_key
),
format!("found equal sign in env var key \"{env_key}\" (key=value)"),
))
}

Expand Down
8 changes: 3 additions & 5 deletions lib/wasix/src/state/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,15 +1164,13 @@ impl WasiEnv {
for package_name in uses {
let specifier = package_name.parse::<PackageSource>().map_err(|e| {
WasiStateCreationError::WasiIncludePackageError(format!(
"package_name={package_name}, {}",
e
"package_name={package_name}, {e}",
))
})?;
let pkg = InlineWaker::block_on(BinaryPackage::from_registry(&specifier, rt)).map_err(
|e| {
WasiStateCreationError::WasiIncludePackageError(format!(
"package_name={package_name}, {}",
e
"package_name={package_name}, {e}",
))
},
)?;
Expand Down Expand Up @@ -1209,7 +1207,7 @@ impl WasiEnv {
if let WasiFsRoot::Sandbox(root_fs) = &self.state.fs.root_fs {
let _ = root_fs.create_dir(Path::new("/bin"));

let path = format!("/bin/{}", command);
let path = format!("/bin/{command}");
let path = Path::new(path.as_str());
if let Err(err) = root_fs.new_open_options_ext().insert_ro_file(path, file) {
tracing::debug!("failed to add atom command [{}] - {}", command, err);
Expand Down
6 changes: 2 additions & 4 deletions lib/wasix/src/state/func_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ impl WasiFunctionEnv {
)
.map_err(|err| {
WasiRuntimeError::Runtime(wasmer::RuntimeError::new(format!(
"journal failed to save the module initialization event - {}",
err
"journal failed to save the module initialization event - {err}"
)))
})?;
} else {
Expand All @@ -371,8 +370,7 @@ impl WasiFunctionEnv {
)
.map_err(|err| {
WasiRuntimeError::Runtime(wasmer::RuntimeError::new(format!(
"journal failed to save clear ethereal event - {}",
err
"journal failed to save clear ethereal event - {err}",
)))
})?;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/wasix/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ pub(crate) fn get_memory_stack<M: MemorySize>(
.map_err(|err| format!("failed to save stack: stack pointer overflow (stack_pointer={}, stack_lower={}, stack_upper={})", stack_offset, env.layout.stack_lower, env.layout.stack_upper))?,
)
.and_then(|memory_stack| memory_stack.read_to_bytes())
.map_err(|err| format!("failed to read stack: {}", err))
.map_err(|err| format!("failed to read stack: {err}"))
}

#[allow(dead_code)]
Expand Down Expand Up @@ -1018,7 +1018,7 @@ pub(crate) fn set_memory_stack<M: MemorySize>(
.map_err(|_| "failed to restore stack: stack pointer overflow".to_string())?,
)
.and_then(|memory_stack| memory_stack.write_slice(&stack[..]))
.map_err(|err| format!("failed to write stack: {}", err))?;
.map_err(|err| format!("failed to write stack: {err}"))?;

// Set the stack pointer itself and return
set_memory_stack_offset(env, store, stack_offset)?;
Expand Down Expand Up @@ -1233,7 +1233,7 @@ where
.map_err(|_| "failed to save stack: stack pointer overflow".to_string())?,
)
.and_then(|memory_stack| memory_stack.read_to_bytes())
.map_err(|err| format!("failed to read stack: {}", err))?;
.map_err(|err| format!("failed to read stack: {err}"))?;

// Notify asyncify that we are no longer unwinding
if let Some(asyncify_stop_unwind) = env
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasi/args_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn args_get<M: MemorySize>(
.unwrap()
.iter()
.enumerate()
.map(|(i, v)| format!("{:>20}: {}", i, v))
.map(|(i, v)| format!("{i:>20}: {v}"))
.collect::<Vec<String>>()
.join("\n")
);
Expand Down
6 changes: 3 additions & 3 deletions lib/wasix/src/syscalls/wasi/poll_oneoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ where

if fd_guards.len() > 10 {
let small_list: Vec<_> = fd_guards.iter().take(10).collect();
tracing::Span::current().record("fd_guards", format!("{:?}...", small_list));
tracing::Span::current().record("fd_guards", format!("{small_list:?}..."));
} else {
tracing::Span::current().record("fd_guards", format!("{:?}", fd_guards));
tracing::Span::current().record("fd_guards", format!("{fd_guards:?}"));
}

fd_guards
Expand Down Expand Up @@ -391,7 +391,7 @@ where
|ctx: &FunctionEnvMut<'a, WasiEnv>| {
// The timeout has triggered so lets add that event
if clock_subs.is_empty() {
tracing::warn!("triggered_timeout (without any clock subscriptions)",);
tracing::warn!("triggered_timeout (without any clock subscriptions)");
}
let mut evts = Vec::new();
for (clock_info, userdata) in clock_subs {
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/chdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn chdir<M: MemorySize>(
let path = unsafe { get_input_str_ok!(&memory, path, path_len) };
Span::current().record("path", path.as_str());

wasi_try_ok!(chdir_internal(&mut ctx, &path,));
wasi_try_ok!(chdir_internal(&mut ctx, &path));
let env = ctx.data();

#[cfg(feature = "journal")]
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/futex_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(super) fn futex_wait_internal<M: MemorySize + 'static>(
OptionTag::Some => Some(Duration::from_nanos(timeout.u)),
_ => None,
};
Span::current().record("timeout", format!("{:?}", timeout));
Span::current().record("timeout", format!("{timeout:?}"));

let state = env.state.clone();
let futex_idx: u64 = futex_ptr.offset().into();
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/getcwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn getcwd<M: MemorySize>(
let env = ctx.data();
let (memory, mut state, inodes) = unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) };

let (_, cur_dir) = wasi_try!(state.fs.get_current_dir(inodes, crate::VIRTUAL_ROOT_FD,));
let (_, cur_dir) = wasi_try!(state.fs.get_current_dir(inodes, crate::VIRTUAL_ROOT_FD));
Span::current().record("path", cur_dir.as_str());

let max_path_len = wasi_try_mem!(path_len.read(&memory));
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/port_addr_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn port_addr_add<M: MemorySize>(
let memory = unsafe { env.memory_view(&ctx) };

let cidr = wasi_try_ok!(crate::net::read_cidr(&memory, ip));
Span::current().record("ip", format!("{:?}", cidr));
Span::current().record("ip", format!("{cidr:?}"));

wasi_try_ok!(port_addr_add_internal(&mut ctx, cidr)?);

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/port_addr_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn port_addr_remove<M: MemorySize>(
let memory = unsafe { env.memory_view(&ctx) };

let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
Span::current().record("ip", format!("{:?}", ip));
Span::current().record("ip", format!("{ip:?}"));

wasi_try_ok!(port_addr_remove_internal(&mut ctx, ip)?);

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/port_gateway_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn port_gateway_set<M: MemorySize>(
let memory = unsafe { env.memory_view(&ctx) };

let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
Span::current().record("ip", format!("{:?}", ip));
Span::current().record("ip", format!("{ip:?}"));

wasi_try_ok!(port_gateway_set_internal(&mut ctx, ip)?);

Expand Down
4 changes: 2 additions & 2 deletions lib/wasix/src/syscalls/wasix/port_route_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub fn port_route_add<M: MemorySize>(
let memory = unsafe { env.memory_view(&ctx) };

let cidr = wasi_try_ok!(crate::net::read_cidr(&memory, cidr));
Span::current().record("cidr", format!("{:?}", cidr));
Span::current().record("cidr", format!("{cidr:?}"));

let via_router = wasi_try_ok!(crate::net::read_ip(&memory, via_router));
Span::current().record("via_router", format!("{:?}", via_router));
Span::current().record("via_router", format!("{via_router:?}"));

let preferred_until = wasi_try_mem_ok!(preferred_until.read(&memory));
let preferred_until = match preferred_until.tag {
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/port_route_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn port_route_remove<M: MemorySize>(
let memory = unsafe { env.memory_view(&ctx) };

let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
Span::current().record("ip", format!("{:?}", ip));
Span::current().record("ip", format!("{ip:?}"));

wasi_try_ok!(port_route_remove_internal(&mut ctx, ip)?);

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/proc_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn proc_spawn<M: MemorySize>(
.record("working_dir", working_dir.as_str());

if chroot == Bool::True {
warn!("chroot is not currently supported",);
warn!("chroot is not currently supported");
return Ok(Errno::Notsup);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/sock_addr_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn sock_addr_local<M: MemorySize>(
|socket, _| socket.addr_local()
));

Span::current().record("addr", format!("{:?}", addr));
Span::current().record("addr", format!("{addr:?}"));

let memory = unsafe { ctx.data().memory_view(&ctx) };
wasi_try!(crate::net::write_ip_port(
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/sock_addr_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn sock_addr_peer<M: MemorySize>(
Rights::empty(),
|socket, _| socket.addr_peer()
));
Span::current().record("addr", format!("{:?}", addr));
Span::current().record("addr", format!("{addr:?}"));

let env = ctx.data();
let memory = unsafe { env.memory_view(&ctx) };
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/sock_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn sock_bind<M: MemorySize>(

let addr = wasi_try_ok!(crate::net::read_ip_port(&memory, addr));
let addr = SocketAddr::new(addr.0, addr.1);
Span::current().record("addr", format!("{:?}", addr));
Span::current().record("addr", format!("{addr:?}"));

wasi_try_ok!(sock_bind_internal(&mut ctx, sock, addr)?);

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/syscalls/wasix/sock_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn sock_connect<M: MemorySize>(
let memory = unsafe { env.memory_view(&ctx) };
let addr = wasi_try_ok!(crate::net::read_ip_port(&memory, addr));
let peer_addr = SocketAddr::new(addr.0, addr.1);
Span::current().record("addr", format!("{:?}", peer_addr));
Span::current().record("addr", format!("{peer_addr:?}"));

wasi_try_ok!(sock_connect_internal(&mut ctx, sock, peer_addr)?);

Expand Down
Loading

0 comments on commit 94be28f

Please sign in to comment.