What changed, and why it matters
This commit removes redundant Rust feature gates inside a module that is already entirely gated behind the 'alloc' feature. It is a code cleanup change with no security relevance.
No security action needed. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes #[cfg(feature = “alloc”)] attributes from methods and tests in primitives/src/script/borrowed.rs, owned.rs, and tests.rs. The entire script module is already compiled only when the ‘alloc’ feature is enabled, so these inner gates were redundant. Removing them does not change which code is compiled under any feature combination, nor does it alter runtime behavior.
Changed components
primitives/src/script/borrowed.rsprimitives/src/script/owned.rsprimitives/src/script/tests.rsInspect captured patch +0 / −9
diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs
index 8afddc6a..e7e452b3 100644
--- a/primitives/src/script/borrowed.rs
+++ b/primitives/src/script/borrowed.rs
@@ -146,7 +146,6 @@ impl<T> Script<T> {
///
/// Just the script bytes in hexadecimal **not** consensus encoding of the script i.e., the
/// string will not include a length prefix.
- #[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
#[inline]
#[deprecated(since = "1.0.0-rc.0", note = "use `format!(\"{var:x}\")` instead")]
@@ -212,7 +211,6 @@ mod tests {
// All tests should compile and pass no matter which script type you put here.
type Script = super::super::ScriptSig;
- #[cfg(feature = "alloc")]
use alloc::{borrow::ToOwned, vec};
#[test]
@@ -270,7 +268,6 @@ mod tests {
}
#[test]
- #[cfg(feature = "alloc")]
fn encode() {
// Consensus encoding includes the length of the encoded data
// (compact size encoded length prefix).
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index 98f24d81..479b7d71 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -126,7 +126,6 @@ impl<T> ScriptBuf<T> {
///
/// Just the script bytes in hexadecimal **not** consensus encoding of the script i.e., the
/// string will not include a length prefix.
- #[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
#[inline]
#[deprecated(since = "1.0.0-rc.0", note = "use `format!(\"{var:x}\")` instead")]
@@ -218,9 +217,7 @@ mod tests {
// All tests should compile and pass no matter which script type you put here.
type ScriptBuf = super::super::ScriptSigBuf;
- #[cfg(feature = "alloc")]
use alloc::string::ToString;
- #[cfg(feature = "alloc")]
use alloc::vec;
#[cfg(feature = "std")]
use std::error::Error as _;
diff --git a/primitives/src/script/tests.rs b/primitives/src/script/tests.rs
index 19e967e3..2231b12d 100644
--- a/primitives/src/script/tests.rs
+++ b/primitives/src/script/tests.rs
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: CC0-1.0
-#[cfg(feature = "alloc")]
use alloc::{format, vec};
use hashes::{hash160, sha256};
@@ -337,7 +336,6 @@ fn legacy_opcode() {
}
#[test]
-#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn script_to_hex() {
let script = Script::from_bytes(&[0xa1, 0xb2, 0xc3]);
@@ -346,7 +344,6 @@ fn script_to_hex() {
}
#[test]
-#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn script_buf_to_hex() {
let script = ScriptBuf::from_bytes(vec![0xa1, 0xb2, 0xc3]);
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.