Skip to content

Commit

Permalink
Inline variables in format strings
Browse files Browse the repository at this point in the history
### What
Inline variables in format strings.

### Why
Rust 1.66 introduces a lint to clippy that requires variables to be embedded in format strings.

At this moment the beta (1.66) and nightly (1.67) versions of clippy will emit warnings. This is inconvenient for people choosing to use beta and nightly. In the near future (6 weeks) we'll see this lint in stable.
  • Loading branch information
willemneal authored Nov 5, 2022
1 parent 2a065ee commit 243c43f
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Cmd {
} else {
self.run_in_sandbox(contract)?
};
println!("{}", res_str);
println!("{res_str}");
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ impl Cmd {
rust::generate_from_file(&wasm_path_str, None).map_err(Error::GenerateRustFromFile)?;
match code.to_formatted_string() {
Ok(formatted) => {
println!("{}", formatted);
println!("{formatted}");
Ok(())
}
Err(e) => {
println!("{}", code);
println!("{code}");
Err(Error::FormatRust(e.to_string()))
}
}
Expand All @@ -62,7 +62,7 @@ impl Cmd {
let wasm_path_str = self.wasm.to_string_lossy();
let json =
json::generate_from_file(&wasm_path_str, None).map_err(Error::GenerateJsonFromFile)?;
println!("{}", json);
println!("{json}");
Ok(())
}
}
10 changes: 5 additions & 5 deletions src/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Cmd {
for env_meta_entry in ScEnvMetaEntry::read_xdr_iter(&mut cursor) {
match env_meta_entry? {
ScEnvMetaEntry::ScEnvMetaKindInterfaceVersion(v) => {
println!(" • Interface Version: {}", v);
println!(" • Interface Version: {v}");
}
}
}
Expand All @@ -81,16 +81,16 @@ impl Cmd {
f.outputs.as_slice(),
),
ScSpecEntry::UdtUnionV0(udt) => {
println!(" • Union: {:?}", udt);
println!(" • Union: {udt:?}");
}
ScSpecEntry::UdtStructV0(udt) => {
println!(" • Struct: {:?}", udt);
println!(" • Struct: {udt:?}");
}
ScSpecEntry::UdtEnumV0(udt) => {
println!(" • Enum: {:?}", udt);
println!(" • Enum: {udt:?}");
}
ScSpecEntry::UdtErrorEnumV0(udt) => {
println!(" • Error: {:?}", udt);
println!(" • Error: {udt:?}");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl Cmd {
error: e,
})?;

println!("{}", res_str);
println!("{res_str}");
// TODO: print cost

Ok(())
Expand Down Expand Up @@ -412,7 +412,7 @@ impl Cmd {
error: e,
})?;

println!("{}", res_str);
println!("{res_str}");

let (storage, budget, events) = h.try_finish().map_err(|_h| {
HostError::from(ScStatus::HostStorageError(
Expand All @@ -431,17 +431,17 @@ impl Cmd {
eprintln!("Cpu Insns: {}", budget.get_cpu_insns_count());
eprintln!("Mem Bytes: {}", budget.get_mem_bytes_count());
for cost_type in CostType::variants() {
eprintln!("Cost ({:?}): {}", cost_type, budget.get_input(*cost_type));
eprintln!("Cost ({cost_type:?}): {}", budget.get_input(*cost_type));
}
}

for (i, event) in events.0.iter().enumerate() {
eprint!("#{}: ", i);
eprint!("#{i}: ");
match event {
HostEvent::Contract(e) => {
eprintln!("event: {}", serde_json::to_string(&e).unwrap());
}
HostEvent::Debug(e) => eprintln!("debug: {}", e),
HostEvent::Debug(e) => eprintln!("debug: {e}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ async fn main() {
};

if let Err(e) = run(root.cmd, &mut saved_matches).await {
eprintln!("error: {}", e);
eprintln!("error: {e}");
}
}
6 changes: 3 additions & 3 deletions src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Cmd {
let routes = jsonrpc_route.with(cors);

let addr: SocketAddr = ([127, 0, 0, 1], self.port).into();
println!("Listening on: {}/soroban/rpc", addr);
println!("Listening on: {addr}/soroban/rpc");
warp::serve(routes).run(addr).await;
Ok(())
}
Expand Down Expand Up @@ -182,7 +182,7 @@ fn reply(
result: res,
}),
Err(err) => {
eprintln!("err: {:?}", err);
eprintln!("err: {err:?}");
jsonrpc::Response::Err(jsonrpc::ErrorResponse {
jsonrpc: "2.0".to_string(),
id: id.as_ref().unwrap_or(&jsonrpc::Id::Null).clone(),
Expand Down Expand Up @@ -537,7 +537,7 @@ async fn send_transaction(
}
}
Err(err) => {
eprintln!("error: {:?}", err);
eprintln!("error: {err:?}");
json!({
"id": id,
"status": "error",
Expand Down
6 changes: 3 additions & 3 deletions src/strval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl Display for StrValError {
match self {
Self::UnknownError => write!(f, "an unknown error occurred")?,
Self::InvalidValue => write!(f, "value is not parseable to type")?,
Self::Serde(e) => write!(f, "{}", e)?,
Self::Xdr(e) => write!(f, "{}", e)?,
Self::Serde(e) => write!(f, "{e}")?,
Self::Xdr(e) => write!(f, "{e}")?,
};
Ok(())
}
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn from_json(v: &Value, t: &ScSpecTypeDef) -> Result<ScVal, StrValError> {
// Number parsing
(ScSpecTypeDef::BigInt, Value::String(s)) => from_string(s, &ScSpecTypeDef::BigInt)?,
(ScSpecTypeDef::BigInt, Value::Number(n)) => {
from_json(&Value::String(format!("{}", n)), &ScSpecTypeDef::BigInt)?
from_json(&Value::String(format!("{n}")), &ScSpecTypeDef::BigInt)?
}
(ScSpecTypeDef::I32, Value::Number(n)) => ScVal::I32(
n.as_i64()
Expand Down
2 changes: 1 addition & 1 deletion src/token/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Cmd {
} else {
self.run_in_sandbox(salt, self.admin, &self.name, &self.symbol, self.decimal)?
};
println!("{}", res_str);
println!("{res_str}");
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/token/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Cmd {
} else {
self.run_in_sandbox(&asset)?
};
println!("{}", res_str);
println!("{res_str}");
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn add_contract_to_ledger_entries(

pub fn padded_hex_from_str(s: &String, n: usize) -> Result<Vec<u8>, FromHexError> {
let mut decoded = vec![0u8; n];
let padded = format!("{:0>width$}", s, width = n * 2);
let padded = format!("{s:0>width$}", width = n * 2);
hex::decode_to_slice(padded, &mut decoded)?;
Ok(decoded)
}
Expand Down
2 changes: 1 addition & 1 deletion src/xdr/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Cmd {
xdr::Type::from_xdr_base64(self.r#type, self.xdr.clone()).map_err(Error::Xdr)?;

match self.output {
Output::Default => println!("{:#?}", value),
Output::Default => println!("{value:#?}"),
Output::Json => println!(
"{}",
serde_json::to_string_pretty(&value).map_err(Error::Json)?
Expand Down

0 comments on commit 243c43f

Please sign in to comment.