refactor: remove redundant type casts in push_bytes macro
What changed, and why it matters
This commit is a minor code cleanup in the rust-bitcoin library. It removes two unnecessary type casts inside a macro that converts fixed-size byte arrays into a 'PushBytesBuf' type used in Bitcoin script handling. The behavior of the code is unchanged; the casts were redundant because Rust automatically converts references to fixed-size arrays into references to slices.
No action required. This is a safe refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors the push_bytes macro in bitcoin/src/blockdata/script/push_bytes.rs. Two occurrences of as &[_] (explicit slice coercion) are removed: Vec::from(&bytes as &[_]) becomes Vec::from(&bytes), and Vec::from(bytes as &[_]) becomes Vec::from(bytes). In both cases, the From implementation for Vec<u8> accepts &[u8], and Rust performs the array-to-slice coercion implicitly. This is a non-functional refactor with no security implications.
Changed components
bitcoin/src/blockdata/script/push_bytes.rsInspect captured patch +2 / −2
diff --git a/bitcoin/src/blockdata/script/push_bytes.rs b/bitcoin/src/blockdata/script/push_bytes.rs
index 7fb46742..81b41d73 100644
--- a/bitcoin/src/blockdata/script/push_bytes.rs
+++ b/bitcoin/src/blockdata/script/push_bytes.rs
@@ -167,13 +167,13 @@ mod primitive {
impl From<[u8; $len]> for PushBytesBuf {
fn from(bytes: [u8; $len]) -> Self {
- PushBytesBuf(Vec::from(&bytes as &[_]))
+ PushBytesBuf(Vec::from(&bytes))
}
}
impl<'a> From<&'a [u8; $len]> for PushBytesBuf {
fn from(bytes: &'a [u8; $len]) -> Self {
- PushBytesBuf(Vec::from(bytes as &[_]))
+ PushBytesBuf(Vec::from(bytes))
}
}
)*
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.