Skip to content

Commit 9ee7b33

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#1041: Remove extern crates
21a1cc7 Use pub(crate) for macros instead of macro_use (Tobin C. Harding) 23ee093 Remove extern crate (Tobin C. Harding) da8b1b5 Remove unused extern crate test (Tobin C. Harding) 01a8cc6 Remove extern crate bitcoin_hashes (Tobin C. Harding) Pull request description: Do some clean up of `extern crate` statements now we have edition 2018. 4 separate but very similar patches, separated to ease review. ACKs for top commit: sanket1729: utACK 21a1cc7 apoelstra: ACK 21a1cc7 Tree-SHA512: fba33ed8fd261cc756dad8dd94f186a5b38aaf20cf31c3a83ad7633e7bb60a390681c39ebfd913e9e242fffed3b502491d067250d72ebfe666b4d03e93c8b945
2 parents 66c2078 + 9530313 commit 9ee7b33

31 files changed

+67
-43
lines changed

src/blockdata/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::blockdata::transaction::Transaction;
2525
use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
2626
use crate::blockdata::script;
2727
use crate::VarInt;
28+
use crate::internal_macros::impl_consensus_encoding;
2829

2930
/// Bitcoin block header.
3031
///

src/blockdata/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::blockdata::block::{Block, BlockHeader};
2121
use crate::blockdata::witness::Witness;
2222
use crate::network::constants::Network;
2323
use crate::util::uint::Uint256;
24+
use crate::internal_macros::{impl_array_newtype, impl_bytes_newtype};
2425

2526
/// The maximum allowable sequence number
2627
pub const MAX_SEQUENCE: u32 = 0xFFFFFFFF;

src/blockdata/opcodes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#[cfg(feature = "serde")] use crate::prelude::*;
1515

1616
use core::{fmt, convert::From};
17+
use crate::internal_macros::display_from_debug;
1718

1819
// Note: I am deliberately not implementing PartialOrd or Ord on the
1920
// opcode enum. If you want to check ranges of opcodes, etc.,

src/blockdata/script.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::io;
1818
use core::convert::TryFrom;
1919
use core::{fmt, default::Default};
2020
use core::ops::Index;
21+
use crate::internal_macros::display_from_debug;
2122

2223
#[cfg(feature = "serde")] use serde;
2324

@@ -998,7 +999,7 @@ impl<'de> serde::Deserialize<'de> for Script {
998999
D: serde::Deserializer<'de>,
9991000
{
10001001
use core::fmt::Formatter;
1001-
use hashes::hex::FromHex;
1002+
use crate::hashes::hex::FromHex;
10021003

10031004
if deserializer.is_human_readable() {
10041005

@@ -1092,6 +1093,7 @@ mod test {
10921093
use crate::blockdata::opcodes;
10931094
use crate::util::key::PublicKey;
10941095
use crate::util::psbt::serialize::Serialize;
1096+
use crate::internal_macros::hex_script;
10951097

10961098
#[test]
10971099
fn script() {

src/blockdata/transaction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::consensus::{encode, Decodable, Encodable};
3030
use crate::hash_types::{Sighash, Txid, Wtxid};
3131
use crate::VarInt;
3232
use crate::util::sighash::UINT256_ONE;
33+
use crate::internal_macros::{impl_consensus_encoding, serde_string_impl, serde_struct_human_string_impl, write_err};
3334

3435
#[cfg(doc)]
3536
use crate::util::sighash::SchnorrSighashType;

src/blockdata/witness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl serde::Serialize for Witness {
281281
where
282282
S: serde::Serializer,
283283
{
284-
use hashes::hex::ToHex;
284+
use crate::hashes::hex::ToHex;
285285
use serde::ser::SerializeSeq;
286286

287287
let human_readable = serializer.is_human_readable();
@@ -315,8 +315,8 @@ impl<'de> serde::Deserialize<'de> for Witness {
315315

316316
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut a: A) -> Result<Self::Value, A::Error>
317317
{
318-
use hashes::hex::FromHex;
319-
use hashes::hex::Error::*;
318+
use crate::hashes::hex::FromHex;
319+
use crate::hashes::hex::Error::*;
320320
use serde::de::{self, Unexpected};
321321

322322
let mut ret = match a.size_hint() {

src/consensus/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use core::{fmt, mem, u32, convert::From};
2222

2323
use crate::hashes::{sha256d, Hash, sha256};
2424
use crate::hash_types::{BlockHash, FilterHash, TxMerkleNode, FilterHeader};
25-
25+
use crate::internal_macros::write_err;
2626
use crate::io::{self, Cursor, Read};
2727

2828
use crate::util::endian;
@@ -231,7 +231,7 @@ macro_rules! decoder_fn {
231231
($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => {
232232
#[inline]
233233
fn $name(&mut self) -> Result<$val_type, Error> {
234-
const_assert!(::core::mem::size_of::<$val_type>() == $byte_len);
234+
$crate::internal_macros::const_assert!(::core::mem::size_of::<$val_type>() == $byte_len);
235235
let mut val = [0; $byte_len];
236236
self.read_exact(&mut val[..]).map_err(Error::Io)?;
237237
Ok(endian::$readfn(&val))

src/internal_macros.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ macro_rules! impl_consensus_encoding {
4444
}
4545
);
4646
}
47+
pub(crate) use impl_consensus_encoding;
4748

4849
/// Implements standard array methods for a given wrapper type
4950
macro_rules! impl_array_newtype {
@@ -104,6 +105,7 @@ macro_rules! impl_array_newtype {
104105
}
105106
};
106107
}
108+
pub(crate) use impl_array_newtype;
107109

108110
macro_rules! display_from_debug {
109111
($thing:ident) => {
@@ -114,15 +116,22 @@ macro_rules! display_from_debug {
114116
}
115117
};
116118
}
119+
pub(crate) use display_from_debug;
117120

118121
#[cfg(test)]
119122
macro_rules! hex_script (($s:expr) => (<$crate::Script as core::str::FromStr>::from_str($s).unwrap()));
123+
#[cfg(test)]
124+
pub(crate) use hex_script;
120125

121126
#[cfg(test)]
122127
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&<$crate::prelude::Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
128+
#[cfg(test)]
129+
pub(crate) use hex_hash;
123130

124131
#[cfg(test)]
125132
macro_rules! hex_decode (($h:ident, $s:expr) => (deserialize::<$h>(&<$crate::prelude::Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
133+
#[cfg(test)]
134+
pub(crate) use hex_decode;
126135

127136
macro_rules! serde_string_impl {
128137
($name:ident, $expecting:literal) => {
@@ -168,6 +177,7 @@ macro_rules! serde_string_impl {
168177
}
169178
};
170179
}
180+
pub(crate) use serde_string_impl;
171181

172182
/// A combination macro where the human-readable serialization is done like
173183
/// serde_string_impl and the non-human-readable impl is done as a struct.
@@ -342,6 +352,7 @@ macro_rules! serde_struct_human_string_impl {
342352
}
343353
)
344354
}
355+
pub(crate) use serde_struct_human_string_impl;
345356

346357
/// Implements several traits for byte-based newtypes.
347358
/// Implements:
@@ -476,6 +487,7 @@ macro_rules! impl_bytes_newtype {
476487
}
477488
};
478489
}
490+
pub(crate) use impl_bytes_newtype;
479491

480492
macro_rules! user_enum {
481493
(
@@ -563,6 +575,7 @@ macro_rules! user_enum {
563575
}
564576
);
565577
}
578+
pub(crate) use user_enum;
566579

567580
/// Formats error. If `std` feature is OFF appends error source (delimited by `: `). We do this
568581
/// because `e.source()` is only available in std builds, without this macro the error source is
@@ -582,10 +595,12 @@ macro_rules! write_err {
582595
}
583596
}
584597
}
598+
pub(crate) use write_err;
585599

586600
/// Asserts a boolean expression at compile time.
587601
macro_rules! const_assert {
588602
($x:expr) => {{
589603
const _: [(); 0 - !$x as usize] = [];
590604
}};
591605
}
606+
pub(crate) use const_assert;

src/lib.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,40 +59,22 @@ extern crate test;
5959
#[cfg(feature = "no-std")]
6060
#[macro_use]
6161
extern crate alloc;
62-
#[cfg(feature = "no-std")]
63-
extern crate core2;
64-
65-
// Re-exported dependencies.
66-
#[macro_use]
67-
pub extern crate bitcoin_hashes as hashes;
68-
pub extern crate bech32;
69-
pub extern crate secp256k1;
70-
71-
#[cfg(feature = "no-std")]
72-
extern crate hashbrown;
7362

74-
#[cfg(feature = "base64")]
75-
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
76-
pub extern crate base64;
63+
// Re-export dependencies we control.
64+
pub use bitcoin_hashes as hashes;
65+
pub use secp256k1;
66+
pub use bech32;
67+
#[cfg(feature="bitcoinconsensus")]
68+
pub use bitcoinconsensus;
7769

78-
#[cfg(feature = "bitcoinconsensus")]
79-
extern crate bitcoinconsensus;
8070
#[cfg(feature = "serde")]
8171
#[macro_use]
8272
extern crate actual_serde as serde;
83-
#[cfg(all(test, feature = "serde"))]
84-
extern crate bincode;
85-
#[cfg(all(test, feature = "serde"))]
86-
extern crate serde_json;
87-
#[cfg(all(test, feature = "serde"))]
88-
extern crate serde_test;
89-
#[cfg(all(test, feature = "unstable"))]
90-
extern crate test;
73+
9174

9275
#[cfg(test)]
9376
#[macro_use]
9477
mod test_macros;
95-
#[macro_use]
9678
mod internal_macros;
9779
#[cfg(feature = "serde")]
9880
mod serde_utils;

src/network/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use core::{fmt, ops, convert::From};
3030

3131
use crate::io;
3232
use crate::consensus::encode::{self, Encodable, Decodable};
33+
use crate::internal_macros::user_enum;
3334

3435
/// Version of the protocol as appearing in network message headers
3536
/// This constant is used to signal to other peers which features you support.

0 commit comments

Comments
 (0)