Skip to content

Commit 81da5f6

Browse files
committed
Fix clippy warnings in stacks-common
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent a638e68 commit 81da5f6

File tree

9 files changed

+34
-52
lines changed

9 files changed

+34
-52
lines changed

stacks-common/src/address/c32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ mod test {
534534
let c32_encoded = c32_encode(&bytes);
535535
let decoded_bytes = c32_decode(&c32_encoded).unwrap();
536536
let result = (bytes, c32_encoded, decoded_bytes, expected);
537-
println!("{:?}", result);
537+
println!("{result:?}");
538538
result
539539
})
540540
.collect();

stacks-common/src/address/c32_old.rs

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

231231
pub fn c32_address(version: u8, data: &[u8]) -> Result<String, Error> {
232232
let c32_string = c32_check_encode(version, data)?;
233-
Ok(format!("S{}", c32_string))
233+
Ok(format!("S{c32_string}"))
234234
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ mod tests {
792792
let encoded = encode(&hrp, payload, variant).unwrap();
793793
assert_eq!(s.to_lowercase(), encoded.to_lowercase());
794794
}
795-
Err(e) => panic!("Did not decode: {:?} Reason: {:?}", s, e),
795+
Err(e) => panic!("Did not decode: {s:?} Reason: {e:?}"),
796796
}
797797
}
798798
}
@@ -850,8 +850,8 @@ mod tests {
850850
for p in pairs {
851851
let (s, expected_error) = p;
852852
match decode(s) {
853-
Ok(_) => panic!("Should be invalid: {:?}", s),
854-
Err(e) => assert_eq!(e, expected_error, "testing input '{}'", s),
853+
Ok(_) => panic!("Should be invalid: {s:?}"),
854+
Err(e) => assert_eq!(e, expected_error, "testing input '{s}'"),
855855
}
856856
}
857857
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ mod test {
766766
.push_opcode(opcodes::All::OP_CHECKSIG)
767767
.into_script();
768768
assert_eq!(
769-
&format!("{:x}", script),
769+
&format!("{script:x}"),
770770
"76a91416e1ae70ff0fa102905d4af297f6912bda6cce1988ac"
771771
);
772772
}

stacks-common/src/deps_common/ctrlc/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn test_set_handler() {
255255

256256
match ctrlc::set_handler(|sig_id| {}) {
257257
Err(ctrlc::Error::MultipleHandlers) => {}
258-
ret => panic!("{:?}", ret),
258+
ret => panic!("{ret:?}"),
259259
}
260260
}
261261

stacks-common/src/types/chainstate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl slog::Value for BlockHeaderHash {
123123
key: slog::Key,
124124
serializer: &mut dyn slog::Serializer,
125125
) -> slog::Result {
126-
serializer.emit_arguments(key, &format_args!("{}", *self))
126+
serializer.emit_arguments(key, &format_args!("{self}"))
127127
}
128128
}
129129

@@ -168,7 +168,7 @@ impl SortitionId {
168168
write!(hasher, "{pox}").expect("Failed to deserialize PoX ID into the hasher");
169169
let h = Sha512Trunc256Sum::from_hasher(hasher);
170170
let s = SortitionId(h.0);
171-
test_debug!("SortitionId({}) = {} + {}", &s, bhh, pox);
171+
test_debug!("SortitionId({s}) = {bhh} + {pox}");
172172
s
173173
}
174174
}

stacks-common/src/util/chunked_encoding.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl HttpChunkedTransferReaderState {
126126
if nr == 0 {
127127
return Ok(nr);
128128
}
129-
trace!("Got {} bytes", nr);
129+
trace!("Got {nr} bytes");
130130

131131
self.chunk_buffer[self.i] = b[0];
132132
self.i += 1;
@@ -156,7 +156,7 @@ impl HttpChunkedTransferReaderState {
156156
}
157157
};
158158

159-
trace!("chunk offset: {}. chunk len: {}", offset, chunk_len);
159+
trace!("chunk offset: {offset}. chunk len: {chunk_len}");
160160
if chunk_len > MAX_MESSAGE_LEN as u64 {
161161
trace!("chunk buffer: {:?}", &self.chunk_buffer[0..self.i]);
162162
return Err(io::Error::new(
@@ -203,11 +203,11 @@ impl HttpChunkedTransferReaderState {
203203
fd.read(buf)? as u64
204204
} else {
205205
// will read up to a chunk boundary
206-
trace!("Read {} bytes (fill remainder)", remaining);
206+
trace!("Read {remaining} bytes (fill remainder)");
207207
fd.read(&mut buf[0..(remaining as usize)])? as u64
208208
};
209209

210-
trace!("Got {} bytes", nr);
210+
trace!("Got {nr} bytes");
211211

212212
self.chunk_read += nr;
213213

@@ -264,7 +264,7 @@ impl HttpChunkedTransferReaderState {
264264
self.parse_step = HttpChunkedTransferParseMode::ChunkBoundary;
265265
}
266266

267-
trace!("Consumed {} bytes of chunk boundary (i = {})", nr, self.i);
267+
trace!("Consumed {nr} bytes of chunk boundary (i = {})", self.i);
268268
Ok(nr)
269269
}
270270

@@ -673,7 +673,7 @@ mod test {
673673
),
674674
];
675675
for (encoded_vec, expected) in tests.iter() {
676-
test_debug!("expect {:?}", &expected);
676+
test_debug!("expect {expected:?}");
677677

678678
let mut output = vec![];
679679
let mut cursor = SegmentReader::new((*encoded_vec).clone());
@@ -715,19 +715,17 @@ mod test {
715715
),
716716
];
717717
for (encoded, expected_len, expected) in tests.iter() {
718-
test_debug!("expect '{}'", expected);
718+
test_debug!("expect '{expected}'");
719719
let mut cursor = io::Cursor::new(encoded.as_bytes());
720720
let mut decoder = HttpChunkedTransferReader::from_reader(&mut cursor, 20);
721721
let mut output = vec![0u8; *expected_len as usize];
722722

723723
let err = decoder.read_exact(&mut output).unwrap_err();
724-
let errstr = format!("{:?}", &err);
724+
let errstr = format!("{err:?}");
725725

726726
assert!(
727727
errstr.contains(expected),
728-
"Expected '{}' in '{:?}'",
729-
expected,
730-
errstr
728+
"Expected '{expected}' in '{errstr:?}'"
731729
);
732730
}
733731
}

stacks-common/src/util/pipe.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ impl PipeRead {
7878

7979
if to_copy > 0 {
8080
trace!(
81-
"Pipe read {} bytes from buffer [{}...]",
82-
to_copy,
81+
"Pipe read {to_copy} bytes from buffer [{}...]",
8382
buf_available[0]
8483
);
8584
}
@@ -121,13 +120,13 @@ impl PipeRead {
121120
Ok(bytes) => bytes,
122121
Err(_e) => {
123122
// dead
124-
trace!("Pipe read disconnect on blocking read ({})", _e);
123+
trace!("Pipe read disconnect on blocking read ({_e})");
125124
disconnected = true;
126125
vec![]
127126
}
128127
}
129128
} else {
130-
trace!("Pipe read {} bytes before blocking", copied);
129+
trace!("Pipe read {copied} bytes before blocking");
131130
blocked = true;
132131
vec![]
133132
}
@@ -148,11 +147,7 @@ impl PipeRead {
148147
remaining
149148
};
150149

151-
trace!(
152-
"Pipe read copied {} bytes from channel ({} total)",
153-
to_copy,
154-
copied
155-
);
150+
trace!("Pipe read copied {to_copy} bytes from channel ({copied} total)");
156151
buf[copied..(copied + to_copy)].copy_from_slice(&next_bytes[0..to_copy]);
157152
copied += to_copy;
158153

@@ -207,7 +202,7 @@ impl PipeWrite {
207202
// ...and try to send the whole thing over
208203
match self.output.try_send(data) {
209204
Ok(_) => {
210-
trace!("Pipe wrote {} bytes", _len);
205+
trace!("Pipe wrote {_len} bytes");
211206
}
212207
Err(TrySendError::Full(data)) => {
213208
trace!("Pipe write buffered {} bytes", data.len());
@@ -259,10 +254,7 @@ impl Read for PipeRead {
259254
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
260255
let copied = self.drain_buf(buf);
261256
if copied == buf.len() {
262-
trace!(
263-
"Read {} bytes total from buffer (pipe channel not used)",
264-
copied
265-
);
257+
trace!("Read {copied} bytes total from buffer (pipe channel not used)");
266258
return Ok(copied);
267259
}
268260

@@ -275,12 +267,12 @@ impl Read for PipeRead {
275267
// buffer, then this isn't a failure.
276268
0
277269
} else {
278-
trace!("Error reading from pipe: {:?}", &e);
270+
trace!("Error reading from pipe: {e:?}");
279271
return Err(e);
280272
}
281273
}
282274
_ => {
283-
trace!("Error reading from pipe: {:?}", &e);
275+
trace!("Error reading from pipe: {e:?}");
284276
return Err(e);
285277
}
286278
},
@@ -306,7 +298,7 @@ impl Write for PipeWrite {
306298
.send(bytes)
307299
.map_err(|_e| io::Error::from(io::ErrorKind::BrokenPipe))?;
308300

309-
trace!("Pipe wrote {} bytes on flush", _len);
301+
trace!("Pipe wrote {_len} bytes on flush");
310302
}
311303
Ok(())
312304
}
@@ -341,12 +333,7 @@ mod test {
341333
];
342334

343335
for (send_bytes, recv_list, outputs) in tests.iter() {
344-
test_debug!(
345-
"send {:?}, recv {:?}, expect {:?}",
346-
send_bytes,
347-
recv_list,
348-
outputs
349-
);
336+
test_debug!("send {send_bytes:?}, recv {recv_list:?}, expect {outputs:?}");
350337

351338
assert_eq!(recv_list.len(), outputs.len());
352339

@@ -363,26 +350,23 @@ mod test {
363350
Ok(num_bytes) => {
364351
assert!(
365352
outputs[i].is_ok(),
366-
"Expected {:?}, got Ok({})",
367-
&outputs[i],
368-
num_bytes
353+
"Expected {:?}, got Ok({num_bytes})",
354+
&outputs[i]
369355
);
370356

371357
let num_bytes_expected = outputs[i].as_ref().ok().unwrap();
372358
assert_eq!(
373359
num_bytes, *num_bytes_expected,
374-
"Expected {}, got {}",
375-
num_bytes, num_bytes_expected
360+
"Expected {num_bytes}, got {num_bytes_expected}"
376361
);
377362

378363
recv_buf.extend_from_slice(&buf[0..num_bytes]);
379364
}
380365
Err(e) => {
381366
assert!(
382367
outputs[i].is_err(),
383-
"Expected {:?}, got Err({:?})",
384-
&outputs[i],
385-
&e
368+
"Expected {:?}, got Err({e:?})",
369+
&outputs[i]
386370
);
387371

388372
let expected_output_err = outputs[i].as_ref().err().unwrap();

stacks-common/src/util/uint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ mod tests {
556556
0xFFFFFFFFFFFFFFFF,
557557
]);
558558
assert_eq!(
559-
format!("{}", max_val),
559+
format!("{max_val}"),
560560
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
561561
);
562562
}

0 commit comments

Comments
 (0)