primitives: add clippy::use_self lint
What changed, and why it matters
This commit only turns on a Rust style lint (clippy::use_self) and replaces explicit type names with `Self` in the source code. It does not change what the code does, only how it is written. There is no security impact.
No security action needed. This is a code-quality/style change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds use_self = "warn" to primitives/Cargo.toml and mechanically refactors return types, struct literals, and associated-function calls to use Self instead of the concrete type name. The public API files (api/primitives/*.txt) are updated to reflect the changed return-type text, but the actual generated API is unchanged. No logic, parsing, serialization, or validation behavior is modified.
Changed components
primitives/Cargo.tomlprimitives/src/block.rsprimitives/src/hash_types/generic.rsprimitives/src/hash_types/script_hash.rsprimitives/src/hash_types/witness_script_hash.rsprimitives/src/script/mod.rsprimitives/src/transaction.rsprimitives/src/witness.rsInspect captured patch +84 / −83
diff --git a/api/primitives/all-features.txt b/api/primitives/all-features.txt
index 2bd45cae..acef4b2d 100644
--- a/api/primitives/all-features.txt
+++ b/api/primitives/all-features.txt
@@ -1184,7 +1184,7 @@ pub const bitcoin_primitives::script::MAX_WITNESS_SCRIPT_SIZE: usize
pub const bitcoin_primitives::transaction::OutPoint::COINBASE_PREVOUT: Self
pub const bitcoin_primitives::transaction::OutPoint::SIZE: usize
pub const bitcoin_primitives::transaction::Transaction::MAX_STANDARD_WEIGHT: bitcoin_units::weight::encapsulate::Weight
-pub const bitcoin_primitives::transaction::TxIn::EMPTY_COINBASE: bitcoin_primitives::transaction::TxIn
+pub const bitcoin_primitives::transaction::TxIn::EMPTY_COINBASE: Self
pub const bitcoin_primitives::transaction::Version::ONE: Self
pub const bitcoin_primitives::transaction::Version::THREE: Self
pub const bitcoin_primitives::transaction::Version::TWO: Self
@@ -1224,7 +1224,7 @@ pub const fn bitcoin_primitives::script::WScriptHash::as_byte_array(&self) -> &[
pub const fn bitcoin_primitives::script::WScriptHash::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::script::WScriptHash::to_byte_array(self) -> [u8; 32]
pub const fn bitcoin_primitives::transaction::Version::is_standard(self) -> bool
-pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> bitcoin_primitives::transaction::Version
+pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> Self
pub const fn bitcoin_primitives::transaction::Version::to_u32(self) -> u32
pub const fn bitcoin_primitives::witness::Witness::new() -> Self
pub enum bitcoin_primitives::BlockChecked
@@ -1269,10 +1269,10 @@ pub fn bitcoin_primitives::BlockHash::deserialize<D: serde::de::Deserializer<'de
pub fn bitcoin_primitives::BlockHash::encoder(&self) -> Self::Encoder
pub fn bitcoin_primitives::BlockHash::eq(&self, other: &bitcoin_primitives::BlockHash) -> bool
pub fn bitcoin_primitives::BlockHash::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::BlockHash::from(block: &bitcoin_primitives::block::Block) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(block: bitcoin_primitives::block::Block) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(header: &bitcoin_primitives::block::Header) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(header: bitcoin_primitives::block::Header) -> bitcoin_primitives::BlockHash
+pub fn bitcoin_primitives::BlockHash::from(block: &bitcoin_primitives::block::Block) -> Self
+pub fn bitcoin_primitives::BlockHash::from(block: bitcoin_primitives::block::Block) -> Self
+pub fn bitcoin_primitives::BlockHash::from(header: &bitcoin_primitives::block::Header) -> Self
+pub fn bitcoin_primitives::BlockHash::from(header: bitcoin_primitives::block::Header) -> Self
pub fn bitcoin_primitives::BlockHash::from_str(s: &str) -> core::result::Result<Self, Self::Err>
pub fn bitcoin_primitives::BlockHash::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::BlockHash::partial_cmp(&self, other: &bitcoin_primitives::BlockHash) -> core::option::Option<core::cmp::Ordering>
@@ -1317,8 +1317,8 @@ pub fn bitcoin_primitives::Txid::cmp(&self, other: &bitcoin_primitives::Txid) ->
pub fn bitcoin_primitives::Txid::deserialize<D: serde::de::Deserializer<'de>>(d: D) -> core::result::Result<bitcoin_primitives::Txid, <D as serde::de::Deserializer>::Error>
pub fn bitcoin_primitives::Txid::eq(&self, other: &bitcoin_primitives::Txid) -> bool
pub fn bitcoin_primitives::Txid::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::Txid::from(tx: &bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Txid
-pub fn bitcoin_primitives::Txid::from(tx: bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Txid
+pub fn bitcoin_primitives::Txid::from(tx: &bitcoin_primitives::transaction::Transaction) -> Self
+pub fn bitcoin_primitives::Txid::from(tx: bitcoin_primitives::transaction::Transaction) -> Self
pub fn bitcoin_primitives::Txid::from_str(s: &str) -> core::result::Result<Self, Self::Err>
pub fn bitcoin_primitives::Txid::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::Txid::partial_cmp(&self, other: &bitcoin_primitives::Txid) -> core::option::Option<core::cmp::Ordering>
@@ -1361,8 +1361,8 @@ pub fn bitcoin_primitives::Wtxid::cmp(&self, other: &bitcoin_primitives::Wtxid)
pub fn bitcoin_primitives::Wtxid::deserialize<D: serde::de::Deserializer<'de>>(d: D) -> core::result::Result<bitcoin_primitives::Wtxid, <D as serde::de::Deserializer>::Error>
pub fn bitcoin_primitives::Wtxid::eq(&self, other: &bitcoin_primitives::Wtxid) -> bool
pub fn bitcoin_primitives::Wtxid::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::Wtxid::from(tx: &bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Wtxid
-pub fn bitcoin_primitives::Wtxid::from(tx: bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Wtxid
+pub fn bitcoin_primitives::Wtxid::from(tx: &bitcoin_primitives::transaction::Transaction) -> Self
+pub fn bitcoin_primitives::Wtxid::from(tx: bitcoin_primitives::transaction::Transaction) -> Self
pub fn bitcoin_primitives::Wtxid::from_str(s: &str) -> core::result::Result<Self, Self::Err>
pub fn bitcoin_primitives::Wtxid::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::Wtxid::partial_cmp(&self, other: &bitcoin_primitives::Wtxid) -> core::option::Option<core::cmp::Ordering>
@@ -1378,7 +1378,7 @@ pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Checked>::hea
pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Checked>::transactions(&self) -> &[bitcoin_primitives::transaction::Transaction]
pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::assume_checked(self, witness_root: core::option::Option<bitcoin_primitives::WitnessMerkleNode>) -> bitcoin_primitives::block::Block<bitcoin_primitives::block::Checked>
pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::into_parts(self) -> (bitcoin_primitives::block::Header, alloc::vec::Vec<bitcoin_primitives::transaction::Transaction>)
-pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::new_unchecked(header: bitcoin_primitives::block::Header, transactions: alloc::vec::Vec<bitcoin_primitives::transaction::Transaction>) -> bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>
+pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::new_unchecked(header: bitcoin_primitives::block::Header, transactions: alloc::vec::Vec<bitcoin_primitives::transaction::Transaction>) -> Self
pub fn bitcoin_primitives::block::BlockEncoder<'e>::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::BlockEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::block::BlockHashDecoder::default() -> Self
@@ -1430,7 +1430,7 @@ pub fn bitcoin_primitives::block::Version::arbitrary(u: &mut arbitrary::unstruct
pub fn bitcoin_primitives::block::Version::clone(&self) -> bitcoin_primitives::block::Version
pub fn bitcoin_primitives::block::Version::cmp(&self, other: &bitcoin_primitives::block::Version) -> core::cmp::Ordering
pub fn bitcoin_primitives::block::Version::decoder() -> Self::Decoder
-pub fn bitcoin_primitives::block::Version::default() -> bitcoin_primitives::block::Version
+pub fn bitcoin_primitives::block::Version::default() -> Self
pub fn bitcoin_primitives::block::Version::deserialize<__D>(__deserializer: __D) -> core::result::Result<Self, <__D as serde::de::Deserializer>::Error> where __D: serde::de::Deserializer<'de>
pub fn bitcoin_primitives::block::Version::encoder(&self) -> Self::Encoder
pub fn bitcoin_primitives::block::Version::eq(&self, other: &bitcoin_primitives::block::Version) -> bool
diff --git a/api/primitives/alloc-only.txt b/api/primitives/alloc-only.txt
index f43c0de0..d027c114 100644
--- a/api/primitives/alloc-only.txt
+++ b/api/primitives/alloc-only.txt
@@ -1054,7 +1054,7 @@ pub const bitcoin_primitives::script::MAX_WITNESS_SCRIPT_SIZE: usize
pub const bitcoin_primitives::transaction::OutPoint::COINBASE_PREVOUT: Self
pub const bitcoin_primitives::transaction::OutPoint::SIZE: usize
pub const bitcoin_primitives::transaction::Transaction::MAX_STANDARD_WEIGHT: bitcoin_units::weight::encapsulate::Weight
-pub const bitcoin_primitives::transaction::TxIn::EMPTY_COINBASE: bitcoin_primitives::transaction::TxIn
+pub const bitcoin_primitives::transaction::TxIn::EMPTY_COINBASE: Self
pub const bitcoin_primitives::transaction::Version::ONE: Self
pub const bitcoin_primitives::transaction::Version::THREE: Self
pub const bitcoin_primitives::transaction::Version::TWO: Self
@@ -1094,7 +1094,7 @@ pub const fn bitcoin_primitives::script::WScriptHash::as_byte_array(&self) -> &[
pub const fn bitcoin_primitives::script::WScriptHash::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::script::WScriptHash::to_byte_array(self) -> [u8; 32]
pub const fn bitcoin_primitives::transaction::Version::is_standard(self) -> bool
-pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> bitcoin_primitives::transaction::Version
+pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> Self
pub const fn bitcoin_primitives::transaction::Version::to_u32(self) -> u32
pub const fn bitcoin_primitives::witness::Witness::new() -> Self
pub enum bitcoin_primitives::BlockChecked
@@ -1134,10 +1134,10 @@ pub fn bitcoin_primitives::BlockHash::decoder() -> Self::Decoder
pub fn bitcoin_primitives::BlockHash::encoder(&self) -> Self::Encoder
pub fn bitcoin_primitives::BlockHash::eq(&self, other: &bitcoin_primitives::BlockHash) -> bool
pub fn bitcoin_primitives::BlockHash::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::BlockHash::from(block: &bitcoin_primitives::block::Block) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(block: bitcoin_primitives::block::Block) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(header: &bitcoin_primitives::block::Header) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(header: bitcoin_primitives::block::Header) -> bitcoin_primitives::BlockHash
+pub fn bitcoin_primitives::BlockHash::from(block: &bitcoin_primitives::block::Block) -> Self
+pub fn bitcoin_primitives::BlockHash::from(block: bitcoin_primitives::block::Block) -> Self
+pub fn bitcoin_primitives::BlockHash::from(header: &bitcoin_primitives::block::Header) -> Self
+pub fn bitcoin_primitives::BlockHash::from(header: bitcoin_primitives::block::Header) -> Self
pub fn bitcoin_primitives::BlockHash::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::BlockHash::partial_cmp(&self, other: &bitcoin_primitives::BlockHash) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::Ntxid::as_ref(&self) -> &[u8; 32]
@@ -1170,8 +1170,8 @@ pub fn bitcoin_primitives::Txid::clone(&self) -> bitcoin_primitives::Txid
pub fn bitcoin_primitives::Txid::cmp(&self, other: &bitcoin_primitives::Txid) -> core::cmp::Ordering
pub fn bitcoin_primitives::Txid::eq(&self, other: &bitcoin_primitives::Txid) -> bool
pub fn bitcoin_primitives::Txid::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::Txid::from(tx: &bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Txid
-pub fn bitcoin_primitives::Txid::from(tx: bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Txid
+pub fn bitcoin_primitives::Txid::from(tx: &bitcoin_primitives::transaction::Transaction) -> Self
+pub fn bitcoin_primitives::Txid::from(tx: bitcoin_primitives::transaction::Transaction) -> Self
pub fn bitcoin_primitives::Txid::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::Txid::partial_cmp(&self, other: &bitcoin_primitives::Txid) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::WitnessCommitment::as_ref(&self) -> &[u8; 32]
@@ -1202,8 +1202,8 @@ pub fn bitcoin_primitives::Wtxid::clone(&self) -> bitcoin_primitives::Wtxid
pub fn bitcoin_primitives::Wtxid::cmp(&self, other: &bitcoin_primitives::Wtxid) -> core::cmp::Ordering
pub fn bitcoin_primitives::Wtxid::eq(&self, other: &bitcoin_primitives::Wtxid) -> bool
pub fn bitcoin_primitives::Wtxid::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::Wtxid::from(tx: &bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Wtxid
-pub fn bitcoin_primitives::Wtxid::from(tx: bitcoin_primitives::transaction::Transaction) -> bitcoin_primitives::Wtxid
+pub fn bitcoin_primitives::Wtxid::from(tx: &bitcoin_primitives::transaction::Transaction) -> Self
+pub fn bitcoin_primitives::Wtxid::from(tx: bitcoin_primitives::transaction::Transaction) -> Self
pub fn bitcoin_primitives::Wtxid::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::Wtxid::partial_cmp(&self, other: &bitcoin_primitives::Wtxid) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::block::Block::encoder(&self) -> Self::Encoder
@@ -1216,7 +1216,7 @@ pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Checked>::hea
pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Checked>::transactions(&self) -> &[bitcoin_primitives::transaction::Transaction]
pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::assume_checked(self, witness_root: core::option::Option<bitcoin_primitives::WitnessMerkleNode>) -> bitcoin_primitives::block::Block<bitcoin_primitives::block::Checked>
pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::into_parts(self) -> (bitcoin_primitives::block::Header, alloc::vec::Vec<bitcoin_primitives::transaction::Transaction>)
-pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::new_unchecked(header: bitcoin_primitives::block::Header, transactions: alloc::vec::Vec<bitcoin_primitives::transaction::Transaction>) -> bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>
+pub fn bitcoin_primitives::block::Block<bitcoin_primitives::block::Unchecked>::new_unchecked(header: bitcoin_primitives::block::Header, transactions: alloc::vec::Vec<bitcoin_primitives::transaction::Transaction>) -> Self
pub fn bitcoin_primitives::block::BlockEncoder<'e>::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::BlockEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::block::BlockHashDecoder::default() -> Self
@@ -1264,7 +1264,7 @@ pub fn bitcoin_primitives::block::Unchecked::partial_cmp(&self, other: &bitcoin_
pub fn bitcoin_primitives::block::Version::clone(&self) -> bitcoin_primitives::block::Version
pub fn bitcoin_primitives::block::Version::cmp(&self, other: &bitcoin_primitives::block::Version) -> core::cmp::Ordering
pub fn bitcoin_primitives::block::Version::decoder() -> Self::Decoder
-pub fn bitcoin_primitives::block::Version::default() -> bitcoin_primitives::block::Version
+pub fn bitcoin_primitives::block::Version::default() -> Self
pub fn bitcoin_primitives::block::Version::encoder(&self) -> Self::Encoder
pub fn bitcoin_primitives::block::Version::eq(&self, other: &bitcoin_primitives::block::Version) -> bool
pub fn bitcoin_primitives::block::Version::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
diff --git a/api/primitives/no-features.txt b/api/primitives/no-features.txt
index e4510cc0..0c661012 100644
--- a/api/primitives/no-features.txt
+++ b/api/primitives/no-features.txt
@@ -474,7 +474,7 @@ pub const fn bitcoin_primitives::Wtxid::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::Wtxid::to_byte_array(self) -> [u8; 32]
pub const fn bitcoin_primitives::block::Version::from_consensus(v: i32) -> Self
pub const fn bitcoin_primitives::transaction::Version::is_standard(self) -> bool
-pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> bitcoin_primitives::transaction::Version
+pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> Self
pub const fn bitcoin_primitives::transaction::Version::to_u32(self) -> u32
pub fn bitcoin_primitives::BlockHash::as_ref(&self) -> &[u8; 32]
pub fn bitcoin_primitives::BlockHash::as_ref(&self) -> &[u8]
@@ -486,8 +486,8 @@ pub fn bitcoin_primitives::BlockHash::decoder() -> Self::Decoder
pub fn bitcoin_primitives::BlockHash::encoder(&self) -> Self::Encoder
pub fn bitcoin_primitives::BlockHash::eq(&self, other: &bitcoin_primitives::BlockHash) -> bool
pub fn bitcoin_primitives::BlockHash::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::BlockHash::from(header: &bitcoin_primitives::block::Header) -> bitcoin_primitives::BlockHash
-pub fn bitcoin_primitives::BlockHash::from(header: bitcoin_primitives::block::Header) -> bitcoin_primitives::BlockHash
+pub fn bitcoin_primitives::BlockHash::from(header: &bitcoin_primitives::block::Header) -> Self
+pub fn bitcoin_primitives::BlockHash::from(header: bitcoin_primitives::block::Header) -> Self
pub fn bitcoin_primitives::BlockHash::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::BlockHash::partial_cmp(&self, other: &bitcoin_primitives::BlockHash) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::Ntxid::as_ref(&self) -> &[u8; 32]
@@ -577,7 +577,7 @@ pub fn bitcoin_primitives::block::HeaderEncoder::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::block::Version::clone(&self) -> bitcoin_primitives::block::Version
pub fn bitcoin_primitives::block::Version::cmp(&self, other: &bitcoin_primitives::block::Version) -> core::cmp::Ordering
pub fn bitcoin_primitives::block::Version::decoder() -> Self::Decoder
-pub fn bitcoin_primitives::block::Version::default() -> bitcoin_primitives::block::Version
+pub fn bitcoin_primitives::block::Version::default() -> Self
pub fn bitcoin_primitives::block::Version::encoder(&self) -> Self::Encoder
pub fn bitcoin_primitives::block::Version::eq(&self, other: &bitcoin_primitives::block::Version) -> bool
pub fn bitcoin_primitives::block::Version::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml
index 505e04c9..90cb37a5 100644
--- a/primitives/Cargo.toml
+++ b/primitives/Cargo.toml
@@ -162,6 +162,7 @@ unreadable_literal = "warn"
unsafe_derive_deserialize = "warn"
unused_async = "warn"
unused_self = "warn"
+use_self = "warn"
used_underscore_binding = "warn"
used_underscore_items = "warn"
verbose_bit_mask = "warn"
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 01cf784e..ed6f61ec 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -87,8 +87,8 @@ where
impl Block<Unchecked> {
/// Constructs a new `Block` without doing any validation.
#[inline]
- pub fn new_unchecked(header: Header, transactions: Vec<Transaction>) -> Block<Unchecked> {
- Block { header, transactions, witness_root: None, marker: PhantomData::<Unchecked> }
+ pub fn new_unchecked(header: Header, transactions: Vec<Transaction>) -> Self {
+ Self { header, transactions, witness_root: None, marker: PhantomData::<Unchecked> }
}
/// Ignores block validation logic and just assumes you know what you are doing.
@@ -138,13 +138,13 @@ impl<V: Validation> Block<V> {
#[cfg(feature = "alloc")]
impl From<Block> for BlockHash {
#[inline]
- fn from(block: Block) -> BlockHash { block.block_hash() }
+ fn from(block: Block) -> Self { block.block_hash() }
}
#[cfg(feature = "alloc")]
impl From<&Block> for BlockHash {
#[inline]
- fn from(block: &Block) -> BlockHash { block.block_hash() }
+ fn from(block: &Block) -> Self { block.block_hash() }
}
/// Marker that the block's merkle root has been successfully validated.
@@ -425,12 +425,12 @@ impl std::error::Error for HeaderDecoderError {
impl From<Header> for BlockHash {
#[inline]
- fn from(header: Header) -> BlockHash { header.block_hash() }
+ fn from(header: Header) -> Self { header.block_hash() }
}
impl From<&Header> for BlockHash {
#[inline]
- fn from(header: &Header) -> BlockHash { header.block_hash() }
+ fn from(header: &Header) -> Self { header.block_hash() }
}
/// Bitcoin block version number.
@@ -472,7 +472,7 @@ impl Version {
///
/// This is the data type used in consensus code in Bitcoin Core.
#[inline]
- pub const fn from_consensus(v: i32) -> Self { Version(v) }
+ pub const fn from_consensus(v: i32) -> Self { Self(v) }
/// Returns the inner `i32` value.
///
@@ -502,7 +502,7 @@ impl Version {
impl Default for Version {
#[inline]
- fn default() -> Version { Self::NO_SOFT_FORK_SIGNALLING }
+ fn default() -> Self { Self::NO_SOFT_FORK_SIGNALLING }
}
encoding::encoder_newtype! {
@@ -584,14 +584,14 @@ impl<'a> Arbitrary<'a> for Block {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let header = Header::arbitrary(u)?;
let transactions = Vec::<Transaction>::arbitrary(u)?;
- Ok(Block::new_unchecked(header, transactions))
+ Ok(Self::new_unchecked(header, transactions))
}
}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for Header {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(Header {
+ Ok(Self {
version: Version::arbitrary(u)?,
prev_blockhash: BlockHash::from_byte_array(u.arbitrary()?),
merkle_root: TxMerkleNode::from_byte_array(u.arbitrary()?),
@@ -608,10 +608,10 @@ impl<'a> Arbitrary<'a> for Version {
// Equally weight known versions and arbitrary versions
let choice = u.int_in_range(0..=3)?;
match choice {
- 0 => Ok(Version::ONE),
- 1 => Ok(Version::TWO),
- 2 => Ok(Version::NO_SOFT_FORK_SIGNALLING),
- _ => Ok(Version::from_consensus(u.arbitrary()?)),
+ 0 => Ok(Self::ONE),
+ 1 => Ok(Self::TWO),
+ 2 => Ok(Self::NO_SOFT_FORK_SIGNALLING),
+ _ => Ok(Self::from_consensus(u.arbitrary()?)),
}
}
}
diff --git a/primitives/src/hash_types/generic.rs b/primitives/src/hash_types/generic.rs
index 3ba0883c..50ba31de 100644
--- a/primitives/src/hash_types/generic.rs
+++ b/primitives/src/hash_types/generic.rs
@@ -64,6 +64,6 @@ impl fmt::Debug for HashType {
impl<'a> Arbitrary<'a> for HashType {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let arbitrary_bytes = u.arbitrary()?;
- Ok(HashType::from_byte_array(arbitrary_bytes))
+ Ok(Self::from_byte_array(arbitrary_bytes))
}
}
diff --git a/primitives/src/hash_types/script_hash.rs b/primitives/src/hash_types/script_hash.rs
index 4bb64167..444c849c 100644
--- a/primitives/src/hash_types/script_hash.rs
+++ b/primitives/src/hash_types/script_hash.rs
@@ -42,7 +42,7 @@ impl ScriptHash {
}
// We've just checked the length
- Ok(ScriptHash::from_script_unchecked(redeem_script))
+ Ok(Self::from_script_unchecked(redeem_script))
}
/// Constructs a new `ScriptHash` from any script irrespective of script size.
@@ -53,7 +53,7 @@ impl ScriptHash {
/// [BIP-0016]: <https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#user-content-520byte_limitation_on_serialized_script_size>
#[inline]
pub fn from_script_unchecked<T>(script: &Script<T>) -> Self {
- ScriptHash(hash160::Hash::hash(script.as_bytes()))
+ Self(hash160::Hash::hash(script.as_bytes()))
}
}
diff --git a/primitives/src/hash_types/witness_script_hash.rs b/primitives/src/hash_types/witness_script_hash.rs
index 5e4c915d..6dfb9d94 100644
--- a/primitives/src/hash_types/witness_script_hash.rs
+++ b/primitives/src/hash_types/witness_script_hash.rs
@@ -37,7 +37,7 @@ impl WScriptHash {
}
// We've just checked the length
- Ok(WScriptHash::from_script_unchecked(witness_script))
+ Ok(Self::from_script_unchecked(witness_script))
}
/// Constructs a new `WScriptHash` from any script irrespective of script size.
@@ -48,7 +48,7 @@ impl WScriptHash {
/// ref: [BIP-0141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)
#[inline]
pub fn from_script_unchecked(script: &WitnessScript) -> Self {
- WScriptHash(sha256::Hash::hash(script.as_bytes()))
+ Self(sha256::Hash::hash(script.as_bytes()))
}
}
diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs
index c65ec729..317c1b54 100644
--- a/primitives/src/script/mod.rs
+++ b/primitives/src/script/mod.rs
@@ -217,7 +217,7 @@ impl<T> From<ScriptBuf<T>> for Vec<u8> {
fn from(v: ScriptBuf<T>) -> Self { v.into_bytes() }
}
-impl<T> AsRef<Script<T>> for Script<T> {
+impl<T> AsRef<Self> for Script<T> {
#[inline]
fn as_ref(&self) -> &Self { self }
}
@@ -237,7 +237,7 @@ impl<T> AsRef<[u8]> for ScriptBuf<T> {
fn as_ref(&self) -> &[u8] { self.as_bytes() }
}
-impl<T> AsMut<Script<T>> for Script<T> {
+impl<T> AsMut<Self> for Script<T> {
#[inline]
fn as_mut(&mut self) -> &mut Self { self }
}
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index daf392f5..01309ba6 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -142,7 +142,7 @@ impl Transaction {
/// having the same inputs and outputs.
#[doc(alias = "ntxid")]
pub fn compute_ntxid(&self) -> Ntxid {
- let normalized = Transaction {
+ let normalized = Self {
version: self.version,
lock_time: self.lock_time,
inputs: self
@@ -216,25 +216,25 @@ impl cmp::Ord for Transaction {
#[cfg(feature = "alloc")]
impl From<Transaction> for Txid {
#[inline]
- fn from(tx: Transaction) -> Txid { tx.compute_txid() }
+ fn from(tx: Transaction) -> Self { tx.compute_txid() }
}
#[cfg(feature = "alloc")]
impl From<&Transaction> for Txid {
#[inline]
- fn from(tx: &Transaction) -> Txid { tx.compute_txid() }
+ fn from(tx: &Transaction) -> Self { tx.compute_txid() }
}
#[cfg(feature = "alloc")]
impl From<Transaction> for Wtxid {
#[inline]
- fn from(tx: Transaction) -> Wtxid { tx.compute_wtxid() }
+ fn from(tx: Transaction) -> Self { tx.compute_wtxid() }
}
#[cfg(feature = "alloc")]
impl From<&Transaction> for Wtxid {
#[inline]
- fn from(tx: &Transaction) -> Wtxid { tx.compute_wtxid() }
+ fn from(tx: &Transaction) -> Self { tx.compute_wtxid() }
}
// Duplicated in `bitcoin`.
@@ -727,7 +727,7 @@ pub struct TxIn {
#[cfg(feature = "alloc")]
impl TxIn {
/// An empty transaction input with the previous output as for a coinbase transaction.
- pub const EMPTY_COINBASE: TxIn = TxIn {
+ pub const EMPTY_COINBASE: Self = Self {
previous_output: OutPoint::COINBASE_PREVOUT,
script_sig: ScriptSigBuf::new(),
sequence: Sequence::MAX,
@@ -1055,7 +1055,7 @@ impl core::str::FromStr for OutPoint {
if colon == 0 || colon == s.len() - 1 {
return Err(ParseOutPointError::Format);
}
- Ok(OutPoint {
+ Ok(Self {
txid: s[..colon].parse().map_err(ParseOutPointError::Txid)?,
vout: parse_vout(&s[colon + 1..])?,
})
@@ -1331,7 +1331,7 @@ impl Version {
///
/// This can accept both standard and non-standard versions.
#[inline]
- pub const fn maybe_non_standard(version: u32) -> Version { Self(version) }
+ pub const fn maybe_non_standard(version: u32) -> Self { Self(version) }
/// Returns the inner `u32` value of this `Version`.
#[inline]
@@ -1345,7 +1345,7 @@ impl Version {
/// versions 1, 2, and 3 are considered standard.
#[inline]
pub const fn is_standard(self) -> bool {
- self.0 == Version::ONE.0 || self.0 == Version::TWO.0 || self.0 == Version::THREE.0
+ self.0 == Self::ONE.0 || self.0 == Self::TWO.0 || self.0 == Self::THREE.0
}
}
@@ -1431,7 +1431,7 @@ impl std::error::Error for VersionDecoderError {
#[cfg(feature = "alloc")]
impl<'a> Arbitrary<'a> for Transaction {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(Transaction {
+ Ok(Self {
version: Version::arbitrary(u)?,
lock_time: absolute::LockTime::arbitrary(u)?,
inputs: Vec::<TxIn>::arbitrary(u)?,
@@ -1444,7 +1444,7 @@ impl<'a> Arbitrary<'a> for Transaction {
#[cfg(feature = "alloc")]
impl<'a> Arbitrary<'a> for TxIn {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(TxIn {
+ Ok(Self {
previous_output: OutPoint::arbitrary(u)?,
script_sig: ScriptSigBuf::arbitrary(u)?,
sequence: Sequence::arbitrary(u)?,
@@ -1457,14 +1457,14 @@ impl<'a> Arbitrary<'a> for TxIn {
#[cfg(feature = "alloc")]
impl<'a> Arbitrary<'a> for TxOut {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(TxOut { amount: Amount::arbitrary(u)?, script_pubkey: ScriptPubKeyBuf::arbitrary(u)? })
+ Ok(Self { amount: Amount::arbitrary(u)?, script_pubkey: ScriptPubKeyBuf::arbitrary(u)? })
}
}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for OutPoint {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(OutPoint { txid: Txid::arbitrary(u)?, vout: u32::arbitrary(u)? })
+ Ok(Self { txid: Txid::arbitrary(u)?, vout: u32::arbitrary(u)? })
}
}
@@ -1474,10 +1474,10 @@ impl<'a> Arbitrary<'a> for Version {
// Equally weight the case of normal version numbers
let choice = u.int_in_range(0..=3)?;
match choice {
- 0 => Ok(Version::ONE),
- 1 => Ok(Version::TWO),
- 2 => Ok(Version::THREE),
- _ => Ok(Version(u.arbitrary()?)),
+ 0 => Ok(Self::ONE),
+ 1 => Ok(Self::TWO),
+ 2 => Ok(Self::THREE),
+ _ => Ok(Self(u.arbitrary()?)),
}
}
}
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index c79cf09c..78f5859e 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -67,7 +67,7 @@ impl Witness {
/// Constructs a new empty [`Witness`].
#[inline]
pub const fn new() -> Self {
- Witness { content: Vec::new(), witness_elements: 0, indices_start: 0 }
+ Self { content: Vec::new(), witness_elements: 0, indices_start: 0 }
}
/// Constructs a new [`Witness`] from inner parts.
@@ -84,7 +84,7 @@ impl Witness {
witness_elements: usize,
indices_start: usize,
) -> Self {
- Witness { content, witness_elements, indices_start }
+ Self { content, witness_elements, indices_start }
}
/// Constructs a new [`Witness`] object from a slice of bytes slices where each slice is a witness item.
@@ -108,7 +108,7 @@ impl Witness {
cursor += elem.as_ref().len();
}
- Witness { witness_elements, content, indices_start: content_size }
+ Self { witness_elements, content, indices_start: content_size }
}
/// Convenience method to create an array of byte-arrays from this witness.
@@ -668,69 +668,69 @@ impl<'de> serde::Deserialize<'de> for Witness {
deserializer.deserialize_seq(Visitor)
} else {
let vec: Vec<Vec<u8>> = serde::Deserialize::deserialize(deserializer)?;
- Ok(Witness::from_slice(&vec))
+ Ok(Self::from_slice(&vec))
}
}
}
impl From<Vec<Vec<u8>>> for Witness {
#[inline]
- fn from(vec: Vec<Vec<u8>>) -> Self { Witness::from_slice(&vec) }
+ fn from(vec: Vec<Vec<u8>>) -> Self { Self::from_slice(&vec) }
}
impl From<&[&[u8]]> for Witness {
#[inline]
- fn from(slice: &[&[u8]]) -> Self { Witness::from_slice(slice) }
+ fn from(slice: &[&[u8]]) -> Self { Self::from_slice(slice) }
}
impl From<&[Vec<u8>]> for Witness {
#[inline]
- fn from(slice: &[Vec<u8>]) -> Self { Witness::from_slice(slice) }
+ fn from(slice: &[Vec<u8>]) -> Self { Self::from_slice(slice) }
}
impl From<Vec<&[u8]>> for Witness {
#[inline]
- fn from(vec: Vec<&[u8]>) -> Self { Witness::from_slice(&vec) }
+ fn from(vec: Vec<&[u8]>) -> Self { Self::from_slice(&vec) }
}
impl<const N: usize> From<[&[u8]; N]> for Witness {
#[inline]
- fn from(arr: [&[u8]; N]) -> Self { Witness::from_slice(&arr) }
+ fn from(arr: [&[u8]; N]) -> Self { Self::from_slice(&arr) }
}
impl<const N: usize> From<&[&[u8]; N]> for Witness {
#[inline]
- fn from(arr: &[&[u8]; N]) -> Self { Witness::from_slice(arr) }
+ fn from(arr: &[&[u8]; N]) -> Self { Self::from_slice(arr) }
}
impl<const N: usize> From<&[[u8; N]]> for Witness {
#[inline]
- fn from(slice: &[[u8; N]]) -> Self { Witness::from_slice(slice) }
+ fn from(slice: &[[u8; N]]) -> Self { Self::from_slice(slice) }
}
impl<const N: usize> From<&[&[u8; N]]> for Witness {
#[inline]
- fn from(slice: &[&[u8; N]]) -> Self { Witness::from_slice(slice) }
+ fn from(slice: &[&[u8; N]]) -> Self { Self::from_slice(slice) }
}
impl<const N: usize, const M: usize> From<[[u8; M]; N]> for Witness {
#[inline]
- fn from(slice: [[u8; M]; N]) -> Self { Witness::from_slice(&slice) }
+ fn from(slice: [[u8; M]; N]) -> Self { Self::from_slice(&slice) }
}
impl<const N: usize, const M: usize> From<&[[u8; M]; N]> for Witness {
#[inline]
- fn from(slice: &[[u8; M]; N]) -> Self { Witness::from_slice(slice) }
+ fn from(slice: &[[u8; M]; N]) -> Self { Self::from_slice(slice) }
}
impl<const N: usize, const M: usize> From<[&[u8; M]; N]> for Witness {
#[inline]
- fn from(slice: [&[u8; M]; N]) -> Self { Witness::from_slice(&slice) }
+ fn from(slice: [&[u8; M]; N]) -> Self { Self::from_slice(&slice) }
}
impl<const N: usize, const M: usize> From<&[&[u8; M]; N]> for Witness {
#[inline]
- fn from(slice: &[&[u8; M]; N]) -> Self { Witness::from_slice(slice) }
+ fn from(slice: &[&[u8; M]; N]) -> Self { Self::from_slice(slice) }
}
impl Default for Witness {
@@ -801,7 +801,7 @@ impl std::error::Error for UnexpectedEofError {}
impl<'a> Arbitrary<'a> for Witness {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let arbitrary_bytes = Vec::<Vec<u8>>::arbitrary(u)?;
- Ok(Witness::from_slice(&arbitrary_bytes))
+ Ok(Self::from_slice(&arbitrary_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.