Fix clippy error: struct is never constructed
What changed, and why it matters
This commit is a routine code-quality fix. It adds Rust feature gates so that certain test-only structs and imports are only compiled when the 'alloc' feature is enabled, silencing a Clippy warning about structs that are never constructed. There is no security relevance.
No security action needed; treat as normal maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch addresses a Clippy lint (‘struct is never constructed’) by gating test helper structs and their impls behind #[cfg(feature = "alloc")]. It also gates an import of crate::sha256 in test code behind the same feature. These changes are purely build/lint hygiene in test code and do not alter runtime behavior or fix any vulnerability.
Changed components
consensus_encoding/tests/encode.rshashes/src/sha256t/mod.rsInspect captured patch +9 / −1
diff --git a/consensus_encoding/tests/encode.rs b/consensus_encoding/tests/encode.rs
index 8865b4a4..a5c48477 100644
--- a/consensus_encoding/tests/encode.rs
+++ b/consensus_encoding/tests/encode.rs
@@ -8,8 +8,10 @@ use std::io::{Cursor, Write};
use consensus_encoding::{ArrayEncoder, BytesEncoder, Encodable, Encoder};
// Simple test type that implements Encodable.
+#[cfg(feature = "alloc")]
struct TestData(u32);
+#[cfg(feature = "alloc")]
impl Encodable for TestData {
type Encoder<'s>
= ArrayEncoder<4>
@@ -22,8 +24,10 @@ impl Encodable for TestData {
}
// Test with a type that creates an empty encoder.
+#[cfg(feature = "alloc")]
struct EmptyData;
+#[cfg(feature = "alloc")]
impl Encodable for EmptyData {
type Encoder<'s>
= ArrayEncoder<0>
diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs
index b1a3c5dc..a0ca15d6 100644
--- a/hashes/src/sha256t/mod.rs
+++ b/hashes/src/sha256t/mod.rs
@@ -192,7 +192,9 @@ macro_rules! sha256t_tag_constructor {
#[cfg(test)]
mod tests {
- use crate::{sha256, sha256t};
+ use crate::sha256t;
+ #[cfg(feature = "alloc")]
+ use crate::sha256;
const TEST_MIDSTATE: [u8; 32] = [
156, 224, 228, 230, 124, 17, 108, 57, 56, 179, 202, 242, 195, 15, 80, 137, 211, 243, 147,
@@ -211,8 +213,10 @@ mod tests {
"ed1382037800c9dd938dd8854f1a8863bcdeb6705069b4b56a66ec22519d5829";
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
+ #[cfg(feature = "alloc")]
pub struct TestHashTag;
+ #[cfg(feature = "alloc")]
impl sha256t::Tag for TestHashTag {
const MIDSTATE: sha256::Midstate = sha256::Midstate::new(TEST_MIDSTATE, 64);
}
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.