Skip to content

Commit 624082f

Browse files
committed
fix: stacks-common clippy errors
1 parent fff292b commit 624082f

File tree

18 files changed

+49
-61
lines changed

18 files changed

+49
-61
lines changed

.vscode/settings.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
2-
"lldb.launch.sourceLanguages": [
3-
"rust"
4-
],
5-
"rust-analyzer.runnables.extraEnv": {
6-
"BITCOIND_TEST": "1"
7-
},
8-
"rust-analyzer.rustfmt.extraArgs": [
9-
"+nightly"
10-
],
11-
"files.eol": "\n"
12-
}
2+
"lldb.launch.sourceLanguages": ["rust"],
3+
"rust-analyzer.runnables.extraEnv": {
4+
"BITCOIND_TEST": "1"
5+
},
6+
"rust-analyzer.rustfmt.extraArgs": ["+nightly"],
7+
"files.eol": "\n"
8+
}

stacks-common/src/address/c32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub fn c32_address_decode(c32_address_str: &str) -> Result<(u8, Vec<u8>), Error>
369369

370370
pub fn c32_address(version: u8, data: &[u8]) -> Result<String, Error> {
371371
let c32_string = c32_check_encode(version, data)?;
372-
Ok(format!("S{}", c32_string))
372+
Ok(format!("S{c32_string}"))
373373
}
374374

375375
#[cfg(test)]

stacks-common/src/address/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ impl fmt::Display for Error {
5656
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5757
match *self {
5858
Error::InvalidCrockford32 => write!(f, "Invalid crockford 32 string"),
59-
Error::InvalidVersion(ref v) => write!(f, "Invalid version {}", v),
59+
Error::InvalidVersion(ref v) => write!(f, "Invalid version {v}"),
6060
Error::EmptyData => f.write_str("Empty data"),
61-
Error::BadByte(b) => write!(f, "invalid base58 character 0x{:x}", b),
61+
Error::BadByte(b) => write!(f, "invalid base58 character 0x{b:x}"),
6262
Error::BadChecksum(exp, actual) => write!(
6363
f,
64-
"base58ck checksum 0x{:x} does not match expected 0x{:x}",
65-
actual, exp
64+
"base58ck checksum 0x{actual:x} does not match expected 0x{exp:x}"
6665
),
67-
Error::InvalidLength(ell) => write!(f, "length {} invalid for this base58 type", ell),
66+
Error::InvalidLength(ell) => write!(f, "length {ell} invalid for this base58 type"),
6867
Error::TooShort(_) => write!(f, "base58ck data not even long enough for a checksum"),
6968
Error::Other(ref s) => f.write_str(s),
7069
}

stacks-common/src/bitvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<const MAX_SIZE: u16> BitVec<MAX_SIZE> {
246246
.data
247247
.into_iter()
248248
.fold(String::new(), |acc, byte| {
249-
acc + &format!("{:08b}", byte).chars().rev().collect::<String>()
249+
acc + &format!("{byte:08b}").chars().rev().collect::<String>()
250250
})
251251
.chars()
252252
.take(self.len() as usize)

stacks-common/src/codec/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,13 @@ fn read_next_vec<T: StacksMessageCodec + Sized, R: Read>(
139139
if len > max_items {
140140
// too many items
141141
return Err(Error::DeserializeError(format!(
142-
"Array has too many items ({} > {}",
143-
len, max_items
142+
"Array has too many items ({len} > {max_items})"
144143
)));
145144
}
146145
} else if len != num_items {
147146
// inexact item count
148147
return Err(Error::DeserializeError(format!(
149-
"Array has incorrect number of items ({} != {})",
150-
len, num_items
148+
"Array has incorrect number of items ({len} != {num_items})"
151149
)));
152150
}
153151

stacks-common/src/deps_common/bech32/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,11 @@ pub enum Error {
679679
impl fmt::Display for Error {
680680
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
681681
match *self {
682-
Error::MissingSeparator => write!(f, "missing human-readable separator, \"{}\"", SEP),
682+
Error::MissingSeparator => write!(f, "missing human-readable separator, \"{SEP}\""),
683683
Error::InvalidChecksum => write!(f, "invalid checksum"),
684684
Error::InvalidLength => write!(f, "invalid length"),
685-
Error::InvalidChar(n) => write!(f, "invalid character (code={})", n),
686-
Error::InvalidData(n) => write!(f, "invalid data point ({})", n),
685+
Error::InvalidChar(n) => write!(f, "invalid character (code={n})"),
686+
Error::InvalidData(n) => write!(f, "invalid data point ({n})"),
687687
Error::InvalidPadding => write!(f, "invalid padding"),
688688
Error::MixedCase => write!(f, "mixed-case strings not allowed"),
689689
}

stacks-common/src/deps_common/bitcoin/blockdata/script.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ impl fmt::Debug for Script {
111111
if opcode == opcodes::All::OP_PUSHBYTES_0 {
112112
f.write_str("OP_0")?;
113113
} else {
114-
write!(f, "{:?}", opcode)?;
114+
write!(f, "{opcode:?}")?;
115115
}
116116
// Write any pushdata
117117
if data_len > 0 {
118118
f.write_str(" ")?;
119119
if index + data_len <= self.0.len() {
120120
for ch in &self.0[index..index + data_len] {
121-
write!(f, "{:02x}", ch)?;
121+
write!(f, "{ch:02x}")?;
122122
}
123123
index += data_len;
124124
} else {
@@ -140,7 +140,7 @@ impl fmt::Display for Script {
140140
impl fmt::LowerHex for Script {
141141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142142
for &ch in self.0.iter() {
143-
write!(f, "{:02x}", ch)?;
143+
write!(f, "{ch:02x}")?;
144144
}
145145
Ok(())
146146
}
@@ -149,7 +149,7 @@ impl fmt::LowerHex for Script {
149149
impl fmt::UpperHex for Script {
150150
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
151151
for &ch in self.0.iter() {
152-
write!(f, "{:02X}", ch)?;
152+
write!(f, "{ch:02X}")?;
153153
}
154154
Ok(())
155155
}
@@ -677,7 +677,7 @@ impl serde::Serialize for Script {
677677
where
678678
S: serde::Serializer,
679679
{
680-
serializer.serialize_str(&format!("{:x}", self))
680+
serializer.serialize_str(&format!("{self:x}"))
681681
}
682682
}
683683

stacks-common/src/deps_common/bitcoin/network/serialize.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ impl fmt::Display for Error {
7777
Error::UnexpectedNetworkMagic {
7878
expected: ref e,
7979
actual: ref a,
80-
} => write!(f, "unexpected network magic: expected {}, actual {}", e, a),
80+
} => write!(f, "unexpected network magic: expected {e}, actual {a}"),
8181
Error::OversizedVectorAllocation {
8282
requested: ref r,
8383
max: ref m,
8484
} => write!(
8585
f,
86-
"allocation of oversized vector requested: requested {}, maximum {}",
87-
r, m
86+
"allocation of oversized vector requested: requested {r}, maximum {m}"
8887
),
8988
Error::InvalidChecksum {
9089
expected: ref e,
@@ -95,18 +94,18 @@ impl fmt::Display for Error {
9594
hex_encode(e),
9695
hex_encode(a)
9796
),
98-
Error::UnknownNetworkMagic(ref m) => write!(f, "unknown network magic: {}", m),
99-
Error::ParseFailed(ref e) => write!(f, "parse failed: {}", e),
97+
Error::UnknownNetworkMagic(ref m) => write!(f, "unknown network magic: {m}"),
98+
Error::ParseFailed(ref e) => write!(f, "parse failed: {e}"),
10099
Error::UnsupportedWitnessVersion(ref wver) => {
101-
write!(f, "unsupported witness version: {}", wver)
100+
write!(f, "unsupported witness version: {wver}")
102101
}
103102
Error::UnsupportedSegwitFlag(ref swflag) => {
104-
write!(f, "unsupported segwit version: {}", swflag)
103+
write!(f, "unsupported segwit version: {swflag}")
105104
}
106105
Error::UnrecognizedNetworkCommand(ref nwcmd) => {
107-
write!(f, "unrecognized network command: {}", nwcmd)
106+
write!(f, "unrecognized network command: {nwcmd}")
108107
}
109-
Error::UnexpectedHexDigit(ref d) => write!(f, "unexpected hex digit: {}", d),
108+
Error::UnexpectedHexDigit(ref d) => write!(f, "unexpected hex digit: {d}"),
110109
}
111110
}
112111
}

stacks-common/src/deps_common/bitcoin/util/hash.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl fmt::Debug for Sha256dHash {
369369
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
370370
let &Sha256dHash(data) = self;
371371
for ch in data.iter() {
372-
write!(f, "{:02x}", ch)?;
372+
write!(f, "{ch:02x}")?;
373373
}
374374
Ok(())
375375
}
@@ -380,7 +380,7 @@ impl fmt::Debug for Hash160 {
380380
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
381381
let &Hash160(data) = self;
382382
for ch in data.iter() {
383-
write!(f, "{:02x}", ch)?;
383+
write!(f, "{ch:02x}")?;
384384
}
385385
Ok(())
386386
}
@@ -402,7 +402,7 @@ impl fmt::LowerHex for Sha256dHash {
402402
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
403403
let &Sha256dHash(data) = self;
404404
for ch in data.iter().rev() {
405-
write!(f, "{:02x}", ch)?;
405+
write!(f, "{ch:02x}")?;
406406
}
407407
Ok(())
408408
}
@@ -413,7 +413,7 @@ impl fmt::UpperHex for Sha256dHash {
413413
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
414414
let &Sha256dHash(data) = self;
415415
for ch in data.iter().rev() {
416-
write!(f, "{:02X}", ch)?;
416+
write!(f, "{ch:02X}")?;
417417
}
418418
Ok(())
419419
}

stacks-common/src/types/chainstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl SortitionId {
170170
} else {
171171
let mut hasher = Sha512_256::new();
172172
hasher.update(bhh);
173-
write!(hasher, "{}", pox).expect("Failed to deserialize PoX ID into the hasher");
173+
write!(hasher, "{pox}").expect("Failed to deserialize PoX ID into the hasher");
174174
let h = Sha512Trunc256Sum::from_hasher(hasher);
175175
let s = SortitionId(h.0);
176176
test_debug!("SortitionId({}) = {} + {}", &s, bhh, pox);

0 commit comments

Comments
 (0)