Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up clippy allows #1186

Merged
merged 6 commits into from
Jan 31, 2024
Merged

Clean up clippy allows #1186

merged 6 commits into from
Jan 31, 2024

Conversation

ValuedMammal
Copy link
Contributor

@ValuedMammal ValuedMammal commented Oct 29, 2023

closes #1127

There are several instances in the code where we allow clippy lints that would otherwise be flagged during regular checks. It would be preferable to minimize the number of "clippy allow" attributes either by fixing the affected areas or setting a specific configuration in clippy.toml. In cases where we have to allow a particular lint, it should be documented why the lint doesn't apply.

For context see #1127 (comment) as well as the commit message details.

One area I'm unsure of is whether Boxing a large error in 4fc2216 is the right approach. Logically it makes sense to avoid allocating a needlessly heavy Result, but I haven't studied the implications or tradeoffs of such a change.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

@ValuedMammal ValuedMammal changed the title Clippy Clean up clippy allows Oct 29, 2023
@ValuedMammal
Copy link
Contributor Author

The first attempt failed CI due to clippy::iter_nth_zero. Of course, there's no reason to think the lint could be disregarded in the first place.. I believe I used the wrong invocation of cargo clippy on the command line, allowing it to slip by. I suppose the nix experience should eventually help prevent silly mistakes.

After taking another look at spk_iter.rs, I think it's fine to allow the exception (as it was originally), since we're specifically testing SpkIterator's custom implementation of nth. An alternative would be to write the tests in a way that doesn't require calling nth(0), but for now this seems like a trivial case not worth worrying about.

Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks really good, thanks a lot!
A few questions/suggestions:

example-crates/example_cli/src/lib.rs Outdated Show resolved Hide resolved
crates/esplora/src/async_ext.rs Outdated Show resolved Hide resolved
@ValuedMammal
Copy link
Contributor Author

rebasing now. dropped all the changes to coin_selection.rs, and made ref(tmp_plan) the last commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm on the fence regarding preselect_utxos. @LLFourn would you prefer we left this untouched so it's clear at the call site exactly what information we're passing?

@ValuedMammal
Copy link
Contributor Author

Reminder to bump msrv in clippy.toml

warning: the MSRV in `clippy.toml` and `Cargo.toml` differ; using `1.57.0` from `clippy.toml`

@ValuedMammal
Copy link
Contributor Author

Changes in most recent push:

  • re-refactored Psbt::get_utxo_for to use a match block. I think it conveys the same thing in a more concise way. compare

nursery/tmp_plan/src/lib.rs Outdated Show resolved Hide resolved
@LLFourn
Copy link
Contributor

LLFourn commented Jan 3, 2024

Please revert all changes to the tmp plan crate and just blanket allow everything. Other than that this looks good to go.

@ValuedMammal
Copy link
Contributor Author

@LLFourn appreciate your input, thanks for clarifying.

Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c4f1211

Thanks @ValuedMammal!

@ValuedMammal
Copy link
Contributor Author

Is anyone opposed to making the type InitialState in example_cli into a struct with comments?

/// The initial state returned from [`init`].
pub struct Init<CS: clap::Subcommand, S: clap::Args, C> {
    /// Arguments parsed by the cli.
    pub args: Args<CS, S>,
    /// Descriptor keymap.
    pub keymap: KeyMap,
    /// Keychain-txout index.
    pub index: KeychainTxOutIndex<Keychain>,
    /// Persistence backend.
    pub db: Mutex<Database<C>>,
    /// Initial changeset.
    pub init_changeset: C,
}

@danielabrozzoni
Copy link
Member

@ValuedMammal go for it!

These lints either resolved themselves, or the code has changed such that
they no longer apply, hence they can be removed with no further changes.

`clippy::derivable_impls`
`clippy::needless_collect`
`clippy::almost_swapped`
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a couple of NITs

crates/bdk/src/psbt/mod.rs Outdated Show resolved Hide resolved
example-crates/example_cli/src/lib.rs Outdated Show resolved Hide resolved
- Add typedefs to model the result of functions `planned_utxos`
and `init`

- Add new struct `CreateTxChange` to hold any change info
resulting from `create_tx`

These changes help resolve clippy::type_complexity
to reduce the number of required function args in order to satisfy
`clippy::too_many_arguments`
to address `clippy::result_large_err`. Clippy's default large-error-
threshold is 128. `esplora_client::Error` currently has size 272.
for holding the items returned from `example_cli::init`
@ValuedMammal
Copy link
Contributor Author

Thank you to all the reviewers! @danielabrozzoni @LLFourn

Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1c15cb2

@evanlinjin evanlinjin merged commit c6b9ed3 into bitcoindevkit:master Jan 31, 2024
12 checks passed
@ValuedMammal ValuedMammal deleted the clippy branch February 1, 2024 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Way too many clippy::allow
6 participants