Make primitives::opcodes pub with pub(crate) content
What changed, and why it matters
This commit is a routine internal refactoring in the rust-bitcoin library. It makes an internal module visible at the crate level (but not to end users) so that a future change can move a data type into it. It does not change any behavior, fix a bug, or alter security logic.
No security action required. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change exposes primitives::opcodes as a public module in the crate root, but marks every item inside it as pub(crate) and gates them behind the alloc feature. This is preparatory refactoring for moving Opcode into primitives. No API surface is exposed to external users; visibility is reduced from pub to pub(crate) for all module contents.
Changed components
primitives/src/lib.rsprimitives/src/opcodes.rsInspect captured patch +10 / −6
diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs
index 1488fc87..49c2fc5f 100644
--- a/primitives/src/lib.rs
+++ b/primitives/src/lib.rs
@@ -46,11 +46,10 @@ pub mod _export {
}
mod hash_types;
-#[cfg(feature = "alloc")]
-mod opcodes;
pub mod block;
pub mod merkle_tree;
+pub mod opcodes;
#[cfg(feature = "alloc")]
pub mod script;
#[cfg(feature = "alloc")]
diff --git a/primitives/src/opcodes.rs b/primitives/src/opcodes.rs
index 4d39abf0..02f83d99 100644
--- a/primitives/src/opcodes.rs
+++ b/primitives/src/opcodes.rs
@@ -7,22 +7,27 @@
#![allow(non_camel_case_types)]
+#[cfg(feature = "alloc")]
use core::fmt;
/// Read the following byte as a length, and read the following
/// bytes as a push of that length.
-pub const OP_PUSHDATA1: u8 = 0x4c;
+#[cfg(feature = "alloc")]
+pub(crate) const OP_PUSHDATA1: u8 = 0x4c;
/// Read the following 2 bytes as a little-endian length, and read the following
/// bytes as a push of that length.
-pub const OP_PUSHDATA2: u8 = 0x4d;
+#[cfg(feature = "alloc")]
+pub(crate) const OP_PUSHDATA2: u8 = 0x4d;
/// Read the following 4 bytes as a little-endian length, and read the following
/// bytes as a push of that length.
-pub const OP_PUSHDATA4: u8 = 0x4e;
+#[cfg(feature = "alloc")]
+pub(crate) const OP_PUSHDATA4: u8 = 0x4e;
/// Format a byte as a script opcode.
-pub fn fmt_opcode(op: u8, f: &mut fmt::Formatter) -> fmt::Result {
+#[cfg(feature = "alloc")]
+pub(crate) fn fmt_opcode(op: u8, f: &mut fmt::Formatter) -> fmt::Result {
match op {
0x00 => f.write_str("OP_0"),
0x01..=0x4b => write!(f, "OP_PUSHBYTES_{}", op),
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.