Skip to content

Commit

Permalink
chore: fix new clippy warnings from Rust 1.67.0 (xJonathanLEI#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Jan 31, 2023
1 parent f169c9e commit 88bdcfd
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ use starknet::{
async fn main() {
let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let latest_block = provider.get_block(BlockId::Latest).await;
println!("{:#?}", latest_block);
println!("{latest_block:#?}");
}
2 changes: 1 addition & 1 deletion examples/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ async fn main() {
));

let block_number = rpc_client.block_number().await.unwrap();
println!("{}", block_number);
println!("{block_number}");
}
2 changes: 1 addition & 1 deletion examples/starknet-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub fn get_public_key(private_key_hex: &str) -> String {
let private_key = FieldElement::from_hex_be(private_key_hex).unwrap();
let public_key = starknet_crypto::get_public_key(&private_key);

format!("{:#064x}", public_key)
format!("{public_key:#064x}")
}
2 changes: 1 addition & 1 deletion starknet-contract/tests/contract_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ async fn can_deploy_contract_to_alpha_goerli() {

match result {
Ok(_) => {}
Err(err) => panic!("Contract deployment failed: {}", err),
Err(err) => panic!("Contract deployment failed: {err}"),
}
}
3 changes: 1 addition & 2 deletions starknet-core/src/serde/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub mod base64 {
match base64::decode(value) {
Ok(value) => Ok(value),
Err(err) => Err(serde::de::Error::custom(format!(
"invalid base64 string: {}",
err
"invalid base64 string: {err}"
))),
}
}
Expand Down
3 changes: 1 addition & 2 deletions starknet-core/src/serde/num_hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub mod u64 {
match u64::from_str_radix(value.trim_start_matches("0x"), 16) {
Ok(value) => Ok(value),
Err(err) => Err(serde::de::Error::custom(format!(
"invalid u64 hex string: {}",
err
"invalid u64 hex string: {err}"
))),
}
}
Expand Down
12 changes: 6 additions & 6 deletions starknet-core/src/serde/unsigned_field_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl SerializeAs<FieldElement> for UfeHex {
where
S: Serializer,
{
serializer.serialize_str(&format!("{:#x}", value))
serializer.serialize_str(&format!("{value:#x}"))
}
}

Expand All @@ -26,7 +26,7 @@ impl<'de> DeserializeAs<'de, FieldElement> for UfeHex {
let value = String::deserialize(deserializer)?;
match FieldElement::from_hex_be(&value) {
Ok(value) => Ok(value),
Err(err) => Err(DeError::custom(format!("invalid hex string: {}", err))),
Err(err) => Err(DeError::custom(format!("invalid hex string: {err}"))),
}
}
}
Expand All @@ -37,7 +37,7 @@ impl SerializeAs<Option<FieldElement>> for UfeHexOption {
S: Serializer,
{
match value {
Some(value) => serializer.serialize_str(&format!("{:#064x}", value)),
Some(value) => serializer.serialize_str(&format!("{value:#064x}")),
None => serializer.serialize_none(),
}
}
Expand All @@ -53,7 +53,7 @@ impl<'de> DeserializeAs<'de, Option<FieldElement>> for UfeHexOption {
"" => Ok(None),
_ => match FieldElement::from_hex_be(&value) {
Ok(value) => Ok(Some(value)),
Err(err) => Err(DeError::custom(format!("invalid hex string: {}", err))),
Err(err) => Err(DeError::custom(format!("invalid hex string: {err}"))),
},
}
}
Expand All @@ -65,7 +65,7 @@ impl SerializeAs<Option<FieldElement>> for UfePendingBlockHash {
S: Serializer,
{
match value {
Some(value) => serializer.serialize_str(&format!("{:#064x}", value)),
Some(value) => serializer.serialize_str(&format!("{value:#064x}")),
// We don't know if it's `null` or `"pending"`
None => serializer.serialize_none(),
}
Expand All @@ -83,7 +83,7 @@ impl<'de> DeserializeAs<'de, Option<FieldElement>> for UfePendingBlockHash {
} else {
match FieldElement::from_hex_be(&value) {
Ok(value) => Ok(Some(value)),
Err(err) => Err(DeError::custom(format!("invalid hex string: {}", err))),
Err(err) => Err(DeError::custom(format!("invalid hex string: {err}"))),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion starknet-core/src/types/contract_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl<'de> Deserialize<'de> for ParentLocation {

let location = array.pop().unwrap();
let location = Location::deserialize(location).map_err(|err| {
serde::de::Error::custom(format!("unable to deserialize Location: {}", err))
serde::de::Error::custom(format!("unable to deserialize Location: {err}"))
})?;

Ok(Self {
Expand Down
13 changes: 6 additions & 7 deletions starknet-core/src/types/contract_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,27 @@ impl<'de> Deserialize<'de> for AbiEntry {
serde_json::Value::String(type_str) => match &type_str[..] {
"constructor" => Ok(AbiEntry::Constructor(
Constructor::deserialize(temp_value).map_err(|err| {
DeError::custom(format!("invalid constructor variant: {}", err))
DeError::custom(format!("invalid constructor variant: {err}"))
})?,
)),
"function" => Ok(AbiEntry::Function(
Function::deserialize(temp_value).map_err(|err| {
DeError::custom(format!("invalid function variant: {}", err))
DeError::custom(format!("invalid function variant: {err}"))
})?,
)),
"struct" => Ok(AbiEntry::Struct(Struct::deserialize(temp_value).map_err(
|err| DeError::custom(format!("invalid struct variant: {}", err)),
|err| DeError::custom(format!("invalid struct variant: {err}")),
)?)),
"l1_handler" => Ok(AbiEntry::L1Handler(
L1Handler::deserialize(temp_value).map_err(|err| {
DeError::custom(format!("invalid l1_handler variant: {}", err))
DeError::custom(format!("invalid l1_handler variant: {err}"))
})?,
)),
"event" => Ok(AbiEntry::Event(Event::deserialize(temp_value).map_err(
|err| DeError::custom(format!("invalid event variant: {}", err)),
|err| DeError::custom(format!("invalid event variant: {err}")),
)?)),
_ => Err(DeError::custom(format!(
"unknown ABI entry type: {}",
type_str
"unknown ABI entry type: {type_str}"
))),
},
_ => Err(DeError::custom("invalid type field")),
Expand Down
5 changes: 2 additions & 3 deletions starknet-crypto-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn lookup_table(input: TokenStream) -> TokenStream {
let bits: u32 = input.base10_parse().expect("invalid bits");

let mut output = String::new();
writeln!(output, "pub const CURVE_CONSTS_BITS: usize = {};", bits).unwrap();
writeln!(output, "pub const CURVE_CONSTS_BITS: usize = {bits};").unwrap();

push_points(&mut output, "P0", PEDERSEN_P0, 248, bits).expect("push_points failed");
push_points(&mut output, "P1", PEDERSEN_P1, 4, bits).expect("push_points failed");
Expand All @@ -41,8 +41,7 @@ fn push_points(

writeln!(
buf,
"pub const CURVE_CONSTS_{}: [::starknet_curve::AffinePoint; {}] = [",
name, len
"pub const CURVE_CONSTS_{name}: [::starknet_curve::AffinePoint; {len}] = ["
)?;

let mut bits_left = max_bits;
Expand Down
20 changes: 10 additions & 10 deletions starknet-ff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl LowerHex for FieldElement {
latch = nibble != 0 || (64 - ind_nibble <= width);
}
if latch {
write!(f, "{:x}", nibble)?;
write!(f, "{nibble:x}")?;
}
ind_nibble += 1;
}
Expand Down Expand Up @@ -427,7 +427,7 @@ impl UpperHex for FieldElement {
latch = nibble != 0 || (64 - ind_nibble <= width);
}
if latch {
write!(f, "{:X}", nibble)?;
write!(f, "{nibble:X}")?;
}
ind_nibble += 1;
}
Expand All @@ -441,7 +441,7 @@ impl Serialize for FieldElement {
where
S: serde::Serializer,
{
serializer.serialize_str(&format!("{}", self))
serializer.serialize_str(&format!("{self}"))
}
}

Expand Down Expand Up @@ -634,19 +634,19 @@ mod tests {
fn test_zero_padded_hex_fmt() {
let fe = FieldElement::from_hex_be("0x1234abcd").unwrap();

assert_eq!(format!("{:011x}", fe), "0001234abcd");
assert_eq!(format!("{:011X}", fe), "0001234ABCD");
assert_eq!(format!("{:08x}", fe), "1234abcd");
assert_eq!(format!("{:06x}", fe), "1234abcd");
assert_eq!(format!("{:#x}", fe), "0x1234abcd");
assert_eq!(format!("{fe:011x}"), "0001234abcd");
assert_eq!(format!("{fe:011X}"), "0001234ABCD");
assert_eq!(format!("{fe:08x}"), "1234abcd");
assert_eq!(format!("{fe:06x}"), "1234abcd");
assert_eq!(format!("{fe:#x}"), "0x1234abcd");
assert_eq!(
format!("{:#064x}", fe),
format!("{fe:#064x}"),
"0x000000000000000000000000000000000000000000000000000000001234abcd"
);

// Ignore if requesting more than 64 nibbles (or should we not?)
assert_eq!(
format!("{:#0100x}", fe),
format!("{fe:#0100x}"),
"0x000000000000000000000000000000000000000000000000000000001234abcd"
);
}
Expand Down
5 changes: 2 additions & 3 deletions starknet-providers/src/jsonrpc/models/serde_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl SerializeAs<u64> for NumAsHex {
where
S: serde::Serializer,
{
serializer.serialize_str(&format!("{:#x}", value))
serializer.serialize_str(&format!("{value:#x}"))
}
}

Expand All @@ -23,8 +23,7 @@ impl<'de> DeserializeAs<'de, u64> for NumAsHex {
match u64::from_str_radix(&value[2..], 16) {
Ok(value) => Ok(value),
Err(err) => Err(serde::de::Error::custom(format!(
"invalid hex string: {}",
err
"invalid hex string: {err}"
))),
}
}
Expand Down
26 changes: 13 additions & 13 deletions starknet-providers/src/sequencer_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_code");
request_url
.query_pairs_mut()
.append_pair("contractAddress", &format!("{:#x}", contract_address));
.append_pair("contractAddress", &format!("{contract_address:#x}"));
append_block_id(&mut request_url, block_identifier);

match self
Expand Down Expand Up @@ -379,7 +379,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_full_contract");
request_url
.query_pairs_mut()
.append_pair("contractAddress", &format!("{:#x}", contract_address));
.append_pair("contractAddress", &format!("{contract_address:#x}"));
append_block_id(&mut request_url, block_identifier);

self.send_get_request::<GatewayResponse<_>>(request_url)
Expand All @@ -395,7 +395,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_class_hash_at");
request_url
.query_pairs_mut()
.append_pair("contractAddress", &format!("{:#x}", contract_address));
.append_pair("contractAddress", &format!("{contract_address:#x}"));
append_block_id(&mut request_url, block_identifier);

self.send_get_request::<RawFieldElementResponse>(request_url)
Expand All @@ -410,7 +410,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_class_by_hash");
request_url
.query_pairs_mut()
.append_pair("classHash", &format!("{:#x}", class_hash));
.append_pair("classHash", &format!("{class_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand All @@ -426,7 +426,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_storage_at");
request_url
.query_pairs_mut()
.append_pair("contractAddress", &format!("{:#x}", contract_address))
.append_pair("contractAddress", &format!("{contract_address:#x}"))
.append_pair("key", &key.to_string());
append_block_id(&mut request_url, block_identifier);

Expand All @@ -443,7 +443,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_nonce");
request_url
.query_pairs_mut()
.append_pair("contractAddress", &format!("{:#x}", contract_address));
.append_pair("contractAddress", &format!("{contract_address:#x}"));
append_block_id(&mut request_url, block_identifier);

self.send_get_request::<RawFieldElementResponse>(request_url)
Expand All @@ -458,7 +458,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_transaction_status");
request_url
.query_pairs_mut()
.append_pair("transactionHash", &format!("{:#x}", transaction_hash));
.append_pair("transactionHash", &format!("{transaction_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand All @@ -472,7 +472,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_transaction");
request_url
.query_pairs_mut()
.append_pair("transactionHash", &format!("{:#x}", transaction_hash));
.append_pair("transactionHash", &format!("{transaction_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand All @@ -486,7 +486,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_transaction_receipt");
request_url
.query_pairs_mut()
.append_pair("transactionHash", &format!("{:#x}", transaction_hash));
.append_pair("transactionHash", &format!("{transaction_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand All @@ -500,7 +500,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_transaction_trace");
request_url
.query_pairs_mut()
.append_pair("transactionHash", &format!("{:#x}", transaction_hash));
.append_pair("transactionHash", &format!("{transaction_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand Down Expand Up @@ -528,7 +528,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_block_id_by_hash");
request_url
.query_pairs_mut()
.append_pair("blockHash", &format!("{:#x}", block_hash));
.append_pair("blockHash", &format!("{block_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand Down Expand Up @@ -556,7 +556,7 @@ impl Provider for SequencerGatewayProvider {
let mut request_url = self.extend_feeder_gateway_url("get_transaction_id_by_hash");
request_url
.query_pairs_mut()
.append_pair("transactionHash", &format!("{:#x}", transaction_hash));
.append_pair("transactionHash", &format!("{transaction_hash:#x}"));

self.send_get_request::<GatewayResponse<_>>(request_url)
.await?
Expand Down Expand Up @@ -659,7 +659,7 @@ fn append_block_id(url: &mut Url, block_identifier: BlockId) {
match block_identifier {
BlockId::Hash(block_hash) => {
url.query_pairs_mut()
.append_pair("blockHash", &format!("{:#x}", block_hash));
.append_pair("blockHash", &format!("{block_hash:#x}"));
}
BlockId::Number(block_number) => {
url.query_pairs_mut()
Expand Down

0 comments on commit 88bdcfd

Please sign in to comment.