units: Remove usage of deprecated to_hex
What changed, and why it matters
This is a small cleanup change inside test code only. It replaces a deprecated method call with a modern equivalent and tidies up an import. There is no security issue here.
No security action needed. This is a routine code-quality/test-maintenance patch.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies units/src/pow.rs test code. It removes the use of the deprecated to_hex() method on CompactTarget in favor of alloc::format!(“{:x}”, compact_target), and moves a std::error::Error import into the one test that actually needs it. No production code behavior changes.
Changed components
units/src/pow.rs (test code only)Inspect captured patch +5 / −4
diff --git a/units/src/pow.rs b/units/src/pow.rs
index 646fdc8a..1635cfa7 100644
--- a/units/src/pow.rs
+++ b/units/src/pow.rs
@@ -548,8 +548,6 @@ mod tests {
#[cfg(feature = "alloc")]
#[cfg(feature = "encoding")]
use alloc::string::ToString;
- #[cfg(feature = "std")]
- use std::error::Error as _;
#[cfg(feature = "encoding")]
use encoding::Decoder as _;
@@ -1537,16 +1535,19 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
- #[allow(deprecated)]
fn compact_target_to_hex() {
let compact_target = CompactTarget::from_consensus(0x1d00_ffff);
- assert_eq!(compact_target.to_hex(), "1d00ffff");
+ let got = alloc::format!("{:x}", compact_target);
+ assert_eq!(got, "1d00ffff");
}
#[test]
#[cfg(feature = "encoding")]
#[cfg(feature = "alloc")]
fn compact_target_decoder_error_display_and_source() {
+ #[cfg(feature = "std")]
+ use std::error::Error as _;
+
let mut slice = [0u8; 3].as_slice();
let mut decoder = CompactTargetDecoder::new();
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.