Skip to content

Commit

Permalink
Merge pull request #5360 from nyurik/inline-fmt
Browse files Browse the repository at this point in the history
chore: inline format args to improve readability
  • Loading branch information
xdoardo authored Jan 23, 2025
2 parents fcd7504 + f123f69 commit d431db9
Show file tree
Hide file tree
Showing 103 changed files with 323 additions and 456 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ install-wasmer-headless-minimal:
update-testsuite:
git subtree pull --prefix tests/wast/spec https://github.com/WebAssembly/testsuite.git master --squash

lint-packages: RUSTFLAGS += -D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D function_item_references # TODO: add `-D missing-docs`
lint-packages: RUSTFLAGS += -D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D function_item_references -D clippy::uninlined_format_args # TODO: add `-D missing-docs`
lint-packages:
RUSTFLAGS="${RUSTFLAGS}" cargo clippy --all --exclude wasmer-cli --exclude wasmer-swift --locked -- -D clippy::all
RUSTFLAGS="${RUSTFLAGS}" cargo clippy --manifest-path lib/cli/Cargo.toml --locked $(compiler_features) -- -D clippy::all
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn main() -> anyhow::Result<()> {
with_test_module(wasitests, wasi_filesystem_test_name, |wasitests| {
test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
format!("tests/wasi-wast/wasi/{wasi_version}"),
|out, path| wasi_processor(out, path, wasi_filesystem_kind),
)
})?;
Expand Down
6 changes: 3 additions & 3 deletions lib/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
"freebsd" => "freebsd",
"android" => "android",
"ios" => "ios",
other => panic!("Unsupported CARGO_CFG_TARGET_OS: {}", other),
other => panic!("Unsupported CARGO_CFG_TARGET_OS: {other}"),
};

// Read target arch from cargo env
Expand All @@ -31,7 +31,7 @@ fn main() {
"mips" => "MIPS",
"powerpc" => "POWERPC",
"powerpc64" => "POWERPC64",
other => panic!("Unsupported CARGO_CFG_TARGET_ARCH: {}", other),
other => panic!("Unsupported CARGO_CFG_TARGET_ARCH: {other}"),
};

// Cleanup tmp data from prior builds
Expand Down Expand Up @@ -220,7 +220,7 @@ fn main() {
println!("cargo:rustc-link-lib=v8_snapshot");
println!("cargo:rustc-link-lib=v8_torque_generated");

if cfg!(any(target_os = "linux",)) {
if cfg!(any(target_os = "linux")) {
println!("cargo:rustc-link-lib=stdc++");
} else if cfg!(target_os = "windows") {
/* do nothing */
Expand Down
11 changes: 3 additions & 8 deletions lib/api/src/c_api/as_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ pub fn valtype_to_type(type_: *const wasm_valtype_t) -> Type {
crate::bindings::wasm_valkind_enum_WASM_V128 => Type::V128,
crate::bindings::wasm_valkind_enum_WASM_EXTERNREF => Type::ExternRef,
crate::bindings::wasm_valkind_enum_WASM_FUNCREF => Type::FuncRef,
_ => unreachable!(
"valtype {:?} has no matching valkind and therefore no matching wasmer_types::Type",
type_
),
_ => unreachable!("valtype {type_:?} has no matching valkind and therefore no matching wasmer_types::Type"),
}
#[cfg(feature = "wasmi")]
match type_ as _ {
Expand All @@ -231,8 +228,7 @@ pub fn valtype_to_type(type_: *const wasm_valtype_t) -> Type {
crate::bindings::wasm_valkind_enum_WASM_EXTERNREF => Type::ExternRef,
crate::bindings::wasm_valkind_enum_WASM_FUNCREF => Type::FuncRef,
_ => unreachable!(
"valtype {:?} has no matching valkind and therefore no matching wasmer_types::Type",
type_
"valtype {type_:?} has no matching valkind and therefore no matching wasmer_types::Type",
),
}
#[cfg(feature = "v8")]
Expand All @@ -244,8 +240,7 @@ pub fn valtype_to_type(type_: *const wasm_valtype_t) -> Type {
crate::bindings::wasm_valkind_enum_WASM_ANYREF => Type::ExternRef,
crate::bindings::wasm_valkind_enum_WASM_FUNCREF => Type::FuncRef,
_ => unreachable!(
"valtype {:?} has no matching valkind and therefore no matching wasmer_types::Type",
type_
"valtype {type_:?} has no matching valkind and therefore no matching wasmer_types::Type",
),
}
}
6 changes: 3 additions & 3 deletions lib/api/src/c_api/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Trap {
let err_ptr = Box::leak(Box::new(err));
let mut data = std::mem::zeroed();
// let x = format!("")
let s1 = format!("🐛{:p}", err_ptr);
let s1 = format!("🐛{err_ptr:p}");
let _s = s1.into_bytes().into_boxed_slice();
wasm_byte_vec_new(&mut data, _s.len(), _s.as_ptr() as _);
std::mem::forget(_s);
Expand All @@ -76,7 +76,7 @@ impl Trap {
// pub unsafe fn deserialize_from_wasm_trap(trap: *mut wasm_trap_t) -> Self {
// let mut data = std::mem::zeroed();
// wasm_trap_message(trap, data);
// println!("data: {:p}", data);
// println!("data: {data:p}");

// std::ptr::read(data as *const _)
// }
Expand Down Expand Up @@ -126,7 +126,7 @@ impl std::error::Error for Trap {
impl fmt::Display for Trap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.inner {
InnerTrap::User(e) => write!(f, "{}", e),
InnerTrap::User(e) => write!(f, "{e}"),
InnerTrap::CApi(value) => {
// let message: wasm_message_t;
// wasm_trap_message(value, &mut message);
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ impl fmt::Display for RuntimeError {
write!(f, " at ")?;
match frame.function_name() {
Some(name) => match rustc_demangle::try_demangle(name) {
Ok(name) => write!(f, "{}", name)?,
Err(_) => write!(f, "{}", name)?,
Ok(name) => write!(f, "{name}")?,
Err(_) => write!(f, "{name}")?,
},
None => write!(f, "<unnamed>")?,
}
Expand Down
8 changes: 2 additions & 6 deletions lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ impl Function {

if expected != given {
return Err(RuntimeError::new(format!(
"given types (`{:?}`) for the function arguments don't match the actual types (`{:?}`)",
given,
expected,
"given types (`{given:?}`) for the function arguments don't match the actual types (`{expected:?}`)",
)));
}
}
Expand All @@ -435,9 +433,7 @@ impl Function {
if expected != given {
// todo: error result types don't match
return Err(RuntimeError::new(format!(
"given types (`{:?}`) for the function results don't match the actual types (`{:?}`)",
given,
expected,
"given types (`{given:?}`) for the function results don't match the actual types (`{expected:?}`)",
)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl fmt::Debug for Imports {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Empty => write!(f, "(empty)"),
Self::Some(len) => write!(f, "(... {} item(s) ...)", len),
Self::Some(len) => write!(f, "(... {len} item(s) ...)"),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ impl Module {
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!(
"Error when converting wat: {}",
e
"Error when converting wat: {e}",
)))
})?;
Self::from_binary(engine, bytes.as_ref())
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/sys/externals/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Table {
self.handle
.get_mut(store.objects_mut())
.grow(delta, item)
.ok_or_else(|| RuntimeError::new(format!("failed to grow table by `{}`", delta)))
.ok_or_else(|| RuntimeError::new(format!("failed to grow table by `{delta}`")))
}

pub fn copy(
Expand Down
8 changes: 4 additions & 4 deletions lib/api/src/sys/tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ mod tests {
let style = tunables.memory_style(&requested);
match style {
MemoryStyle::Dynamic { offset_guard_size } => assert_eq!(offset_guard_size, 256),
s => panic!("Unexpected memory style: {:?}", s),
s => panic!("Unexpected memory style: {s:?}"),
}

// Large maximum
let requested = MemoryType::new(3, Some(5_000_000), true);
let style = tunables.memory_style(&requested);
match style {
MemoryStyle::Dynamic { offset_guard_size } => assert_eq!(offset_guard_size, 256),
s => panic!("Unexpected memory style: {:?}", s),
s => panic!("Unexpected memory style: {s:?}"),
}

// Small maximum
Expand All @@ -53,7 +53,7 @@ mod tests {
assert_eq!(bound, Pages(2048));
assert_eq!(offset_guard_size, 128);
}
s => panic!("Unexpected memory style: {:?}", s),
s => panic!("Unexpected memory style: {s:?}"),
}
}

Expand Down Expand Up @@ -471,7 +471,7 @@ mod tests {
.get_function("large_local")?
.call(&mut store, &[]);

println!("result = {:?}", result);
println!("result = {result:?}");
assert!(result.is_err());

Ok(())
Expand Down
14 changes: 7 additions & 7 deletions lib/api/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ impl Value {
impl fmt::Debug for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::I32(v) => write!(f, "I32({:?})", v),
Self::I64(v) => write!(f, "I64({:?})", v),
Self::F32(v) => write!(f, "F32({:?})", v),
Self::F64(v) => write!(f, "F64({:?})", v),
Self::I32(v) => write!(f, "I32({v:?})"),
Self::I64(v) => write!(f, "I64({v:?})"),
Self::F32(v) => write!(f, "F32({v:?})"),
Self::F64(v) => write!(f, "F64({v:?})"),
Self::ExternRef(None) => write!(f, "Null ExternRef"),
Self::ExternRef(Some(v)) => write!(f, "ExternRef({:?})", v),
Self::ExternRef(Some(v)) => write!(f, "ExternRef({v:?})"),
Self::FuncRef(None) => write!(f, "Null FuncRef"),
Self::FuncRef(Some(v)) => write!(f, "FuncRef({:?})", v),
Self::V128(v) => write!(f, "V128({:?})", v),
Self::FuncRef(Some(v)) => write!(f, "FuncRef({v:?})"),
Self::V128(v) => write!(f, "V128({v:?})"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/tests/import_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn back_and_forth_with_imports() -> Result<()> {
)?;

fn sum(a: i32, b: i32) -> i32 {
println!("Summing: {}+{}", a, b);
println!("Summing: {a}+{b}");
a + b
}

Expand Down
16 changes: 8 additions & 8 deletions lib/api/tests/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,35 +194,35 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> {
let imports = imports! {
"host" => {
"host_func1" => Function::new_typed(&mut store, |p: u64| {
println!("host_func1: Found number {}", p);
println!("host_func1: Found number {p}");
assert_eq!(p, u64::max_value());
}),
"host_func2" => Function::new_typed(&mut store, |p: u32| {
println!("host_func2: Found number {}", p);
println!("host_func2: Found number {p}");
assert_eq!(p, u32::max_value());
}),
"host_func3" => Function::new_typed(&mut store, |p: i64| {
println!("host_func3: Found number {}", p);
println!("host_func3: Found number {p}");
assert_eq!(p, -1);
}),
"host_func4" => Function::new_typed(&mut store, |p: i32| {
println!("host_func4: Found number {}", p);
println!("host_func4: Found number {p}");
assert_eq!(p, -1);
}),
"host_func5" => Function::new_typed(&mut store, |p: i16| {
println!("host_func5: Found number {}", p);
println!("host_func5: Found number {p}");
assert_eq!(p, -1);
}),
"host_func6" => Function::new_typed(&mut store, |p: u16| {
println!("host_func6: Found number {}", p);
println!("host_func6: Found number {p}");
assert_eq!(p, u16::max_value());
}),
"host_func7" => Function::new_typed(&mut store, |p: i8| {
println!("host_func7: Found number {}", p);
println!("host_func7: Found number {p}");
assert_eq!(p, -1);
}),
"host_func8" => Function::new_typed(&mut store, |p: u8| {
println!("host_func8: Found number {}", p);
println!("host_func8: Found number {p}");
assert_eq!(p, u8::max_value());
}),
}
Expand Down
4 changes: 2 additions & 2 deletions lib/api/tests/typed_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn typed_host_function_closure_panics() -> Result<(), String> {
let state = 3;

Function::new_typed(&mut store, move |_: i32| {
println!("{}", state);
println!("{state}");
});

Ok(())
Expand All @@ -34,7 +34,7 @@ fn typed_with_env_host_function_closure_panics() -> Result<(), String> {
&mut store,
&env,
move |_env: FunctionEnvMut<i32>, _: i32| {
println!("{}", state);
println!("{state}");
},
);

Expand Down
2 changes: 1 addition & 1 deletion lib/backend-api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl WasmerClient {
}
user_agent
.parse()
.with_context(|| format!("invalid user agent: '{}'", user_agent))
.with_context(|| format!("invalid user agent: '{user_agent}'"))
}

pub fn new_with_client(
Expand Down
2 changes: 1 addition & 1 deletion lib/backend-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl std::fmt::Display for GraphQLApiFailure {
.map(|err| err.to_string())
.collect::<Vec<_>>()
.join(", ");
write!(f, "GraphQL API failure: {}", errs)
write!(f, "GraphQL API failure: {errs}")
}
}

Expand Down
16 changes: 8 additions & 8 deletions lib/backend-api/src/global_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,25 +371,25 @@ impl std::fmt::Display for GlobalIdParseError {

match &self.kind {
ErrorKind::UnknownPrefix(p) => {
write!(f, "unknown type prefix '{}'", p)
write!(f, "unknown type prefix '{p}'")
}
ErrorKind::Decode(s) => {
write!(f, "decode error: {}", s)
write!(f, "decode error: {s}")
}
ErrorKind::MissingScope => {
write!(f, "missing scope value")
}
ErrorKind::UnknownScope(x) => {
write!(f, "unknown scope value {}", x)
write!(f, "unknown scope value {x}")
}
ErrorKind::MissingVersion => {
write!(f, "missing version value")
}
ErrorKind::UnknownVersion(v) => {
write!(f, "unknown version value {}", v)
write!(f, "unknown version value {v}")
}
ErrorKind::UnknownNodeType(t) => {
write!(f, "unknown node type '{}'", t)
write!(f, "unknown node type '{t}'")
}
ErrorKind::MissingPrefix => write!(f, "missing prefix"),
ErrorKind::PrefixTypeMismatch => write!(f, "prefix type mismatch"),
Expand All @@ -412,7 +412,7 @@ mod tests {
kind: NodeKind::DeployApp,
database_id: 123,
};
assert_eq!(Ok(x1), GlobalId::parse_prefixed(&x1.encode_prefixed()),);
assert_eq!(Ok(x1), GlobalId::parse_prefixed(&x1.encode_prefixed()));
assert_eq!(Ok(x1), GlobalId::parse_url(&x1.encode_url()));

assert_eq!(
Expand Down Expand Up @@ -450,12 +450,12 @@ mod tests {

#[test]
fn test_global_id_parse_values() {
assert_eq!(GlobalId::parse_values(&[]), Err(ErrorKind::MissingScope),);
assert_eq!(GlobalId::parse_values(&[]), Err(ErrorKind::MissingScope));
assert_eq!(
GlobalId::parse_values(&[2]),
Err(ErrorKind::UnknownScope(2)),
);
assert_eq!(GlobalId::parse_values(&[1]), Err(ErrorKind::MissingVersion),);
assert_eq!(GlobalId::parse_values(&[1]), Err(ErrorKind::MissingVersion));
assert_eq!(
GlobalId::parse_values(&[1, 999]),
Err(ErrorKind::UnknownVersion(999)),
Expand Down
4 changes: 2 additions & 2 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ pub async fn app_deployment(
) -> Result<types::AutobuildRepository, anyhow::Error> {
let node = get_node(client, id.clone())
.await?
.with_context(|| format!("app deployment with id '{}' not found", id))?;
.with_context(|| format!("app deployment with id '{id}' not found"))?;
match node {
types::Node::AutobuildRepository(x) => Ok(*x),
_ => anyhow::bail!("invalid node type returned"),
Expand Down Expand Up @@ -1429,7 +1429,7 @@ pub async fn namespace_apps(

let ns = res
.get_namespace
.with_context(|| format!("failed to get namespace '{}'", namespace))?;
.with_context(|| format!("failed to get namespace '{namespace}'"))?;

let apps: Vec<_> = ns
.apps
Expand Down
2 changes: 1 addition & 1 deletion lib/backend-api/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn package_version_ready(
if let Some(token) = client.auth_token() {
req.headers_mut().insert(
reqwest::header::AUTHORIZATION,
HeaderValue::from_str(&format!("Bearer {}", token))?,
HeaderValue::from_str(&format!("Bearer {token}"))?,
);
}

Expand Down
Loading

0 comments on commit d431db9

Please sign in to comment.