Skip to content

Commit 5c466a8

Browse files
committed
Merge #374: Initiate configuration of rustfmt
8062016 Configure imports_granularity (Tobin C. Harding) a89edba Configure group_imports (Tobin C. Harding) ccdef6f Add rustfmt configuration file (Tobin C. Harding) f7f6f3b Run cargo fmt with nightly toolchain (Tobin C. Harding) 8d0c69a Use term fmt instead of lint (Tobin C. Harding) Pull request description: We currently use `rustfmt` with the default configuration. There is some interest in using `rustfmt` in the crates lower down the stack but it is contentious and difficult to find a configuration, if one exists, that is 'good' for everyone. By configuring `rustfmt` in this crate we can reduce the scope of the discussion from 'should we even do this' down to 'this is a good formatting configuration', with the hope that if we can get a good configuration worked out in this crate it will help ease the debate in the others. To get this started add a default config file and then set two, hopefully non-contentious, config options. Please note carefully; the first patch changes CI to run linting checks using the nightly toolchain. Re: edition 2018 changes, there are some changes to imports in the `examples/` that appear in this PR that should really be removed altogether, leaving as is so as not to clutter this PR. ACKs for top commit: sanket1729: reACK 8062016 Tree-SHA512: 2b8967752fa659eb6a66dfd6a4ea817547c0212e740624011cdc6a272f9f5aa4e28fa9f4b3726ac535b61b64441c4b475125b0445ea207631a1792c3d6823561
2 parents abcec45 + 8062016 commit 5c466a8

39 files changed

+293
-247
lines changed

.github/workflows/rust.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ on: [push, pull_request]
33
name: Continuous integration
44

55
jobs:
6-
lint_fuzz_stable:
7-
name: Lint + Fuzz
6+
Fuzz:
7+
name: Fuzz
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
@@ -24,11 +24,10 @@ jobs:
2424
- name: Running fuzzer
2525
env:
2626
DO_FUZZ: true
27-
DO_LINT: true
2827
run: ./contrib/test.sh
2928

3029
Nightly:
31-
name: Bench + Docs
30+
name: Bench + Docs + Fmt
3231
runs-on: ubuntu-latest
3332
steps:
3433
- name: Checkout Crate
@@ -47,6 +46,10 @@ jobs:
4746
env:
4847
DO_DOCS: true
4948
run: ./contrib/test.sh
49+
- name: Running formatter
50+
env:
51+
DO_FMT: true
52+
run: ./contrib/test.sh
5053

5154
UnitTests:
5255
name: Tests

contrib/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ then
88
alias cargo="cargo +$TOOLCHAIN"
99
fi
1010

11-
# Lint if told to
12-
if [ "$DO_LINT" = true ]
11+
# Format if told to
12+
if [ "$DO_FMT" = true ]
1313
then
1414
(
1515
rustup component add rustfmt

examples/htlc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
//! Example: Create an HTLC with miniscript using the policy compiler
1616
17+
use std::str::FromStr;
18+
1719
use bitcoin::Network;
1820
use miniscript::descriptor::Wsh;
1921
use miniscript::policy::{Concrete, Liftable};
2022
use miniscript::DescriptorTrait;
21-
use std::str::FromStr;
2223

2324
fn main() {
2425
// HTLC policy with 10:1 odds for happy (co-operative) case compared to uncooperative case.

examples/parse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
//! Example: Parsing a descriptor from a string.
1616
17-
use miniscript::{descriptor::DescriptorType, Descriptor, DescriptorTrait};
1817
use std::str::FromStr;
1918

19+
use miniscript::descriptor::DescriptorType;
20+
use miniscript::{Descriptor, DescriptorTrait};
21+
2022
fn main() {
2123
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
2224
"wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202))",

examples/sign_multisig.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
//! Example: Signing a 2-of-3 multisignature.
1616
17+
use std::collections::HashMap;
18+
use std::str::FromStr;
19+
1720
use bitcoin::blockdata::witness::Witness;
1821
use bitcoin::secp256k1;
1922
use miniscript::DescriptorTrait;
20-
use std::collections::HashMap;
21-
use std::str::FromStr;
2223

2324
fn main() {
2425
let mut tx = spending_transaction();

examples/verify_tx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
//! Example: Verifying a signed transaction.
1616
17+
use std::str::FromStr;
18+
1719
use bitcoin::consensus::Decodable;
1820
use bitcoin::secp256k1::{self, Secp256k1};
1921
use bitcoin::util::sighash;
2022
use miniscript::interpreter::KeySigPair;
21-
use std::str::FromStr;
2223

2324
fn main() {
2425
//

rustfmt.toml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
max_width = 100
2+
hard_tabs = false
3+
tab_spaces = 4
4+
newline_style = "Auto"
5+
indent_style = "Block"
6+
use_small_heuristics = "Default"
7+
fn_call_width = 60
8+
attr_fn_like_width = 70
9+
struct_lit_width = 18
10+
struct_variant_width = 35
11+
array_width = 60
12+
chain_width = 60
13+
single_line_if_else_max_width = 50
14+
wrap_comments = false
15+
format_code_in_doc_comments = false
16+
comment_width = 80
17+
normalize_comments = false
18+
normalize_doc_attributes = false
19+
license_template_path = ""
20+
format_strings = false
21+
format_macro_matchers = false
22+
format_macro_bodies = true
23+
hex_literal_case = "Preserve"
24+
empty_item_single_line = true
25+
struct_lit_single_line = true
26+
fn_single_line = false
27+
where_single_line = false
28+
imports_indent = "Block"
29+
imports_layout = "Mixed"
30+
imports_granularity = "Module" # Default "Preserve"
31+
group_imports = "StdExternalCrate" # Default "Preserve"
32+
reorder_imports = true
33+
reorder_modules = true
34+
reorder_impl_items = false
35+
type_punctuation_density = "Wide"
36+
space_before_colon = false
37+
space_after_colon = true
38+
spaces_around_ranges = false
39+
binop_separator = "Front"
40+
remove_nested_parens = true
41+
combine_control_expr = true
42+
overflow_delimited_expr = false
43+
struct_field_align_threshold = 0
44+
enum_discrim_align_threshold = 0
45+
match_arm_blocks = true
46+
match_arm_leading_pipes = "Never"
47+
force_multiline_blocks = false
48+
fn_args_layout = "Tall"
49+
brace_style = "SameLineWhere"
50+
control_brace_style = "AlwaysSameLine"
51+
trailing_semicolon = true
52+
trailing_comma = "Vertical"
53+
match_block_trailing_comma = false
54+
blank_lines_upper_bound = 1
55+
blank_lines_lower_bound = 0
56+
edition = "2015"
57+
version = "One"
58+
inline_attribute_width = 0
59+
format_generated_files = true
60+
merge_derives = true
61+
use_try_shorthand = false
62+
use_field_init_shorthand = false
63+
force_explicit_abi = true
64+
condense_wildcard_suffixes = false
65+
color = "Auto"
66+
required_version = "1.4.38"
67+
unstable_features = false
68+
disable_all_formatting = false
69+
skip_children = false
70+
hide_parse_errors = false
71+
error_on_line_overflow = false
72+
error_on_unformatted = false
73+
report_todo = "Never"
74+
report_fixme = "Never"
75+
ignore = []
76+
emit_mode = "Files"
77+
make_backup = false

src/descriptor/bare.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
//! Also includes pk, and pkh descriptors
1919
//!
2020
21-
use std::{fmt, str::FromStr};
21+
use std::fmt;
22+
use std::str::FromStr;
2223

23-
use bitcoin::{self, blockdata::script, Script};
24+
use bitcoin::blockdata::script;
25+
use bitcoin::{self, Script};
2426

27+
use super::checksum::{desc_checksum, verify_checksum};
28+
use super::DescriptorTrait;
2529
use crate::expression::{self, FromTree};
2630
use crate::miniscript::context::ScriptContext;
2731
use crate::policy::{semantic, Liftable};
@@ -31,11 +35,6 @@ use crate::{
3135
TranslatePk,
3236
};
3337

34-
use super::{
35-
checksum::{desc_checksum, verify_checksum},
36-
DescriptorTrait,
37-
};
38-
3938
/// Create a Bare Descriptor. That is descriptor that is
4039
/// not wrapped in sh or wsh. This covers the Pk descriptor
4140
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]

src/descriptor/checksum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ pub(super) fn verify_checksum(s: &str) -> Result<&str, Error> {
100100
}
101101
#[cfg(test)]
102102
mod test {
103-
use super::*;
104103
use std::str;
105104

105+
use super::*;
106+
106107
macro_rules! check_expected {
107108
($desc: expr, $checksum: expr) => {
108109
assert_eq!(desc_checksum($desc).unwrap(), $checksum);

src/descriptor/key.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use std::{error, fmt, str::FromStr};
1+
use std::str::FromStr;
2+
use std::{error, fmt};
23

3-
use bitcoin::{
4-
self,
5-
hashes::{hash160, Hash},
6-
hashes::{hex::FromHex, HashEngine},
7-
secp256k1::{Secp256k1, Signing, Verification},
8-
util::bip32,
9-
XOnlyPublicKey, XpubIdentifier,
10-
};
4+
use bitcoin::hashes::hex::FromHex;
5+
use bitcoin::hashes::{hash160, Hash, HashEngine};
6+
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
7+
use bitcoin::util::bip32;
8+
use bitcoin::{self, XOnlyPublicKey, XpubIdentifier};
119

1210
use crate::{MiniscriptKey, ToPublicKey};
1311

@@ -796,11 +794,11 @@ impl ToPublicKey for DerivedDescriptorKey {
796794

797795
#[cfg(test)]
798796
mod test {
799-
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
797+
use std::str::FromStr;
800798

801799
use bitcoin::secp256k1;
802800

803-
use std::str::FromStr;
801+
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
804802

805803
#[test]
806804
fn parse_descriptor_key_errors() {

src/descriptor/mod.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,21 @@
2323
//! these with BIP32 paths, pay-to-contract instructions, etc.
2424
//!
2525
26+
use std::collections::HashMap;
27+
use std::fmt;
2628
use std::ops::Range;
27-
use std::{collections::HashMap, sync::Arc};
28-
use std::{
29-
fmt,
30-
str::{self, FromStr},
31-
};
29+
use std::str::{self, FromStr};
30+
use std::sync::Arc;
3231

3332
use bitcoin::blockdata::witness::Witness;
3433
use bitcoin::util::address::WitnessVersion;
3534
use bitcoin::{self, secp256k1, Script};
3635

3736
use self::checksum::verify_checksum;
38-
use crate::expression;
39-
use crate::miniscript;
4037
use crate::miniscript::{Legacy, Miniscript, Segwitv0};
4138
use crate::{
42-
BareCtx, Error, ForEach, ForEachKey, MiniscriptKey, Satisfier, ToPublicKey, TranslatePk,
43-
TranslatePk2,
39+
expression, miniscript, BareCtx, Error, ForEach, ForEachKey, MiniscriptKey, Satisfier,
40+
ToPublicKey, TranslatePk, TranslatePk2,
4441
};
4542

4643
// Directly export from lib.rs, exporting the trait here causes conflicts in this file
@@ -857,26 +854,26 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
857854

858855
#[cfg(test)]
859856
mod tests {
860-
use super::checksum::desc_checksum;
861-
use super::tr::Tr;
862-
use super::*;
863-
use crate::descriptor::key::Wildcard;
864-
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
865-
use crate::hex_script;
866-
use crate::{Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
857+
use std::cmp;
858+
use std::collections::HashMap;
859+
use std::str::FromStr;
860+
867861
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
868862
use bitcoin::blockdata::script::Instruction;
869863
use bitcoin::blockdata::{opcodes, script};
870864
use bitcoin::hashes::hex::{FromHex, ToHex};
871865
use bitcoin::hashes::{hash160, sha256};
872866
use bitcoin::util::bip32;
873867
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey};
874-
use std::cmp;
875-
use std::collections::HashMap;
876-
use std::str::FromStr;
877868

869+
use super::checksum::desc_checksum;
870+
use super::tr::Tr;
871+
use super::*;
872+
use crate::descriptor::key::Wildcard;
873+
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
878874
#[cfg(feature = "compiler")]
879875
use crate::policy;
876+
use crate::{hex_script, Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
880877

881878
type StdDescriptor = Descriptor<PublicKey>;
882879
const TEST_PK: &'static str =

src/descriptor/pretaproot.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use std::{
2-
fmt,
3-
str::{self, FromStr},
4-
};
1+
use std::fmt;
2+
use std::str::{self, FromStr};
53

64
use bitcoin::{self, Script};
75

8-
use super::{checksum::verify_checksum, Bare, Pkh, Sh, Wpkh, Wsh};
6+
use super::checksum::verify_checksum;
7+
use super::{Bare, Pkh, Sh, Wpkh, Wsh};
98
use crate::{expression, DescriptorTrait, Error, MiniscriptKey, Satisfier, ToPublicKey};
109

1110
/// Script descriptor
@@ -241,12 +240,9 @@ serde_string_impl_pk!(PreTaprootDescriptor, "a pre-taproot script descriptor");
241240
pub(crate) mod traits {
242241
use bitcoin::Script;
243242

244-
use crate::{
245-
descriptor::{Pkh, Sh, Wpkh, Wsh},
246-
DescriptorTrait, MiniscriptKey, ToPublicKey,
247-
};
248-
249243
use super::PreTaprootDescriptor;
244+
use crate::descriptor::{Pkh, Sh, Wpkh, Wsh};
245+
use crate::{DescriptorTrait, MiniscriptKey, ToPublicKey};
250246

251247
/// A general trait for Pre taproot bitcoin descriptor.
252248
/// Similar to [`DescriptorTrait`], but `explicit_script` and `script_code` methods cannot fail

src/descriptor/segwitv0.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
//! Implementation of Segwit Descriptors. Contains the implementation
1717
//! of wsh, wpkh and sortedmulti inside wsh.
1818
19-
use std::{fmt, str::FromStr};
19+
use std::fmt;
20+
use std::str::FromStr;
2021

2122
use bitcoin::{self, Script};
2223

24+
use super::checksum::{desc_checksum, verify_checksum};
25+
use super::{DescriptorTrait, SortedMultiVec};
2326
use crate::expression::{self, FromTree};
2427
use crate::miniscript::context::{ScriptContext, ScriptContextError};
2528
use crate::policy::{semantic, Liftable};
@@ -28,11 +31,6 @@ use crate::{
2831
Error, ForEach, ForEachKey, Miniscript, MiniscriptKey, Satisfier, Segwitv0, ToPublicKey,
2932
TranslatePk,
3033
};
31-
32-
use super::{
33-
checksum::{desc_checksum, verify_checksum},
34-
DescriptorTrait, SortedMultiVec,
35-
};
3634
/// A Segwitv0 wsh descriptor
3735
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
3836
pub struct Wsh<Pk: MiniscriptKey> {

0 commit comments

Comments
 (0)