Skip to content

Commit 3fabe09

Browse files
committed
Merge #277: clippy!: Box large enum variants
650c3ee fix!: `Box` large enum variants (valued mammal) Pull request description: ### Description This is a fix to address clippy lints - `clippy::large_enum_variant` - `clippy::result_large_error` BREAKING: The types `LoadMismatch`, and `CreateWithPersistError` are changed as a result of the now boxed variants. fixes #245 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) #### Bugfixes: * [x] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [ ] I'm linking the issue being fixed by this PR ACKs for top commit: evanlinjin: ACK 650c3ee Tree-SHA512: 3634425499e3ddd401cf36c1c0519d19a2173a8c8414ea95e3195f9f6477f98b490899a57fb9c22195f6beaa2c4c3d9e00131524c195c88e8c25ad34e0033de0
2 parents 0eb4a9c + 650c3ee commit 3fabe09

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

clippy.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
# TODO fix, see: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
2-
enum-variant-size-threshold = 1032
3-
# TODO fix, see: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
4-
large-error-threshold = 993
1+
msrv = "1.63.0"

wallet/src/wallet/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ pub enum LoadMismatch {
227227
/// Keychain identifying the descriptor.
228228
keychain: KeychainKind,
229229
/// The loaded descriptor.
230-
loaded: Option<ExtendedDescriptor>,
230+
loaded: Option<Box<ExtendedDescriptor>>,
231231
/// The expected descriptor.
232-
expected: Option<ExtendedDescriptor>,
232+
expected: Option<Box<ExtendedDescriptor>>,
233233
},
234234
}
235235

@@ -565,8 +565,8 @@ impl Wallet {
565565
if descriptor.descriptor_id() != exp_desc.descriptor_id() {
566566
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
567567
keychain: KeychainKind::External,
568-
loaded: Some(descriptor),
569-
expected: Some(exp_desc),
568+
loaded: Some(Box::new(descriptor)),
569+
expected: Some(Box::new(exp_desc)),
570570
}));
571571
}
572572
if params.extract_keys {
@@ -575,7 +575,7 @@ impl Wallet {
575575
} else {
576576
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
577577
keychain: KeychainKind::External,
578-
loaded: Some(descriptor),
578+
loaded: Some(Box::new(descriptor)),
579579
expected: None,
580580
}));
581581
}
@@ -595,7 +595,7 @@ impl Wallet {
595595
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
596596
keychain: KeychainKind::Internal,
597597
loaded: None,
598-
expected: Some(exp_desc),
598+
expected: Some(Box::new(exp_desc)),
599599
}));
600600
}
601601
}
@@ -609,7 +609,7 @@ impl Wallet {
609609
None => {
610610
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
611611
keychain: KeychainKind::Internal,
612-
loaded: Some(desc),
612+
loaded: Some(Box::new(desc)),
613613
expected: None,
614614
}))
615615
}
@@ -621,8 +621,8 @@ impl Wallet {
621621
if desc.descriptor_id() != exp_desc.descriptor_id() {
622622
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
623623
keychain: KeychainKind::Internal,
624-
loaded: Some(desc),
625-
expected: Some(exp_desc),
624+
loaded: Some(Box::new(desc)),
625+
expected: Some(Box::new(exp_desc)),
626626
}));
627627
}
628628
if params.extract_keys {

wallet/src/wallet/persisted.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ impl<P: WalletPersister> PersistedWallet<P> {
150150
) -> Result<Self, CreateWithPersistError<P::Error>> {
151151
let existing = P::initialize(persister).map_err(CreateWithPersistError::Persist)?;
152152
if !existing.is_empty() {
153-
return Err(CreateWithPersistError::DataAlreadyExists(existing));
153+
return Err(CreateWithPersistError::DataAlreadyExists(Box::new(
154+
existing,
155+
)));
154156
}
155157
let mut inner =
156158
Wallet::create_with_params(params).map_err(CreateWithPersistError::Descriptor)?;
@@ -207,7 +209,9 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {
207209
.await
208210
.map_err(CreateWithPersistError::Persist)?;
209211
if !existing.is_empty() {
210-
return Err(CreateWithPersistError::DataAlreadyExists(existing));
212+
return Err(CreateWithPersistError::DataAlreadyExists(Box::new(
213+
existing,
214+
)));
211215
}
212216
let mut inner =
213217
Wallet::create_with_params(params).map_err(CreateWithPersistError::Descriptor)?;
@@ -292,6 +296,7 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
292296

293297
/// Error for [`bdk_file_store`]'s implementation of [`WalletPersister`].
294298
#[cfg(feature = "file_store")]
299+
#[allow(clippy::large_enum_variant)] // Can be fixed in `bdk_file_store` by boxing the dump.
295300
#[derive(Debug)]
296301
pub enum FileStoreError {
297302
/// Error when loading from the store.
@@ -357,7 +362,7 @@ pub enum CreateWithPersistError<E> {
357362
/// Error from persistence.
358363
Persist(E),
359364
/// Persister already has wallet data.
360-
DataAlreadyExists(ChangeSet),
365+
DataAlreadyExists(Box<ChangeSet>),
361366
/// Occurs when the loaded changeset cannot construct [`Wallet`].
362367
Descriptor(DescriptorError),
363368
}

wallet/tests/persisted_wallet.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ fn single_descriptor_wallet_persist_and_recover() {
346346
// should error on wrong internal params
347347
let desc = get_test_wpkh();
348348
let (exp_desc, _) = <Descriptor<DescriptorPublicKey>>::parse_descriptor(secp, desc).unwrap();
349+
let exp_desc = Box::new(exp_desc);
349350
let err = Wallet::load()
350351
.descriptor(KeychainKind::Internal, Some(desc))
351352
.extract_keys()

0 commit comments

Comments
 (0)