Skip to content

Commit 6ed008f

Browse files
committed
Merge #507: Enable -D rustdoc::broken-intra-doc-links
ebaa31b Enable usage of -D rustdoc::broken-intra-doc-links (Tobin C. Harding) 16b6c76 Improve docs on enumerate_policy_tree (Tobin C. Harding) 90dc766 Do trivial cleanup to main lib docs (Tobin C. Harding) Pull request description: Make an effort to do some docs improvements without touching the whole codebase. - Patch 1: Trivial, because I can't help myself. - Patch 2: Clean up docs on a private method in preparation for duplicating in public docs - Patch 3: Fix broken links and enable `-D rustdoc::broken-intra-doc-links` in CI I'm in no way across this codebase, there may be other problems with docs that show up in this PR but the PR is an attempt at improving the docs without going too wild - both for my sanity and that of reviewers. ACKs for top commit: apoelstra: ACK ebaa31b Tree-SHA512: 6982f615fe6565f0defca30a4d4f4e077f9bcf446c1ed5f86cb15986c6b1d6f95a34cbd0d9b9c6096ccb932767aa71f99011931f612cc33c69709c79857679a0
2 parents 45eb69d + ebaa31b commit 6ed008f

File tree

7 files changed

+73
-58
lines changed

7 files changed

+73
-58
lines changed

contrib/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fi
9292

9393
# Build the docs if told to (this only works with the nightly toolchain)
9494
if [ "$DO_DOCS" = true ]; then
95-
RUSTDOCFLAGS="--cfg docsrs" cargo doc --features="$FEATURES"
95+
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links
9696
fi
9797

9898
exit 0

src/descriptor/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl DescriptorPublicKey {
600600
}
601601

602602
#[deprecated(note = "use at_derivation_index instead")]
603-
/// Deprecated name of [`at_derivation_index`].
603+
/// Deprecated name for [`Self::at_derivation_index`].
604604
pub fn derive(self, index: u32) -> Result<DefiniteDescriptorKey, ConversionError> {
605605
self.at_derivation_index(index)
606606
}

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl Descriptor<DescriptorPublicKey> {
537537
}
538538

539539
#[deprecated(note = "use at_derivation_index instead")]
540-
/// Deprecated name for [`at_derivation_index`].
540+
/// Deprecated name for [`Self::at_derivation_index`].
541541
pub fn derive(&self, index: u32) -> Result<Descriptor<DefiniteDescriptorKey>, ConversionError> {
542542
self.at_derivation_index(index)
543543
}

src/interpreter/stack.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use crate::miniscript::context::SigType;
1515
use crate::prelude::*;
1616

1717
/// Definition of Stack Element of the Stack used for interpretation of Miniscript.
18-
/// All stack elements with vec![] go to Dissatisfied and vec![1] are marked to Satisfied.
19-
/// Others are directly pushed as witness
18+
///
19+
/// All stack elements with `vec![]` go to `Element::Dissatisfied` and `vec![1]` are marked to
20+
/// `Element::Satisfied`. Others are directly pushed as witness.
2021
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
2122
pub enum Element<'txin> {
2223
/// Result of a satisfied Miniscript fragment

src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
//! Miniscript and Output Descriptors
55
//!
6-
//! # Introduction
76
//! ## Bitcoin Script
87
//!
98
//! In Bitcoin, spending policies are defined and enforced by means of a
@@ -35,7 +34,7 @@
3534
//! While spending policies in Bitcoin are entirely defined by Script; there
3635
//! are multiple ways of embedding these Scripts in transaction outputs; for
3736
//! example, P2SH or Segwit v0. These different embeddings are expressed by
38-
//! *Output Descriptors*, [which are described here](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md)
37+
//! *Output Descriptors*, [which are described here](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md).
3938
//!
4039
//! # Examples
4140
//!
@@ -51,7 +50,7 @@
5150
//! )))\
5251
//! ").unwrap();
5352
//!
54-
//! // Derive the P2SH address
53+
//! // Derive the P2SH address.
5554
//! assert_eq!(
5655
//! desc.address(bitcoin::Network::Bitcoin).unwrap().to_string(),
5756
//! "3CJxbQBfWAe1ZkKiGQNEYrioV73ZwvBWns"
@@ -62,7 +61,7 @@
6261
//! // elements in Wsh scripts or they contain a combination of timelock and heightlock.
6362
//! assert!(desc.sanity_check().is_ok());
6463
//!
65-
//! // Estimate the satisfaction cost
64+
//! // Estimate the satisfaction cost.
6665
//! assert_eq!(desc.max_satisfaction_weight().unwrap(), 293);
6766
//! ```
6867
//!
@@ -155,19 +154,20 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
155154
/// in BIP389 multipath descriptors.
156155
fn num_der_paths(&self) -> usize;
157156

158-
/// The associated [`sha256::Hash`] for this [`MiniscriptKey`],
159-
/// used in the hash256 fragment.
157+
/// The associated [`bitcoin::hashes::sha256::Hash`] for this [`MiniscriptKey`], used in the
158+
/// sha256 fragment.
160159
type Sha256: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
161160

162-
/// The associated [`hash256::Hash`] for this [`MiniscriptKey`],
163-
/// used in the hash256 fragment.
161+
/// The associated [`miniscript::hash256::Hash`] for this [`MiniscriptKey`], used in the
162+
/// hash256 fragment.
164163
type Hash256: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
165-
/// The associated [`ripedmd160::Hash`] for this [`MiniscriptKey`] type.
166-
/// used in the ripemd160 fragment
164+
165+
/// The associated [`bitcoin::hashes::ripemd160::Hash`] for this [`MiniscriptKey`] type, used
166+
/// in the ripemd160 fragment.
167167
type Ripemd160: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
168168

169-
/// The associated [`hash160::Hash`] for this [`MiniscriptKey`] type.
170-
/// used in the hash160 fragment
169+
/// The associated [`bitcoin::hashes::hash160::Hash`] for this [`MiniscriptKey`] type, used in
170+
/// the hash160 fragment.
171171
type Hash160: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
172172
}
173173

src/miniscript/decode.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use crate::miniscript::ScriptContext;
2424
use crate::prelude::*;
2525
use crate::{bitcoin, hash256, Error, Miniscript, MiniscriptKey, ToPublicKey};
2626

27+
#[cfg(doc)]
28+
use crate::Descriptor;
29+
2730
fn return_none<T>(_: usize) -> Option<T> {
2831
None
2932
}
@@ -112,14 +115,14 @@ enum NonTerm {
112115
// could be or_i or tern
113116
EndIfElse,
114117
}
115-
/// All AST elements
116-
/// This variant is the inner Miniscript variant that allows the user to bypass
117-
/// some of the miniscript rules. You should *never* construct Terminal directly.
118-
/// This is only exposed to external user to allow matching on the [`crate::Miniscript`]
118+
/// All AST elements.
119+
///
120+
/// This variant is the inner Miniscript variant that allows the user to bypass some of the
121+
/// miniscript rules. You should *never* construct `Terminal` directly. This is only exposed to
122+
/// external users to allow matching on the [`Miniscript`].
119123
///
120-
/// The average user should always use the [`crate::Descriptor`] APIs. Advanced users
121-
/// who want deal with Miniscript ASTs should use the [`crate::Miniscript`] APIs.
122-
#[allow(broken_intra_doc_links)]
124+
/// The average user should always use the [`Descriptor`] APIs. Advanced users who want deal
125+
/// with Miniscript ASTs should use the [`Miniscript`] APIs.
123126
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
124127
pub enum Terminal<Pk: MiniscriptKey, Ctx: ScriptContext> {
125128
/// `1`
@@ -160,38 +163,38 @@ pub enum Terminal<Pk: MiniscriptKey, Ctx: ScriptContext> {
160163
Check(Arc<Miniscript<Pk, Ctx>>),
161164
/// `DUP IF [V] ENDIF`
162165
DupIf(Arc<Miniscript<Pk, Ctx>>),
163-
/// [T] VERIFY
166+
/// `[T] VERIFY`
164167
Verify(Arc<Miniscript<Pk, Ctx>>),
165-
/// SIZE 0NOTEQUAL IF [Fn] ENDIF
168+
/// `SIZE 0NOTEQUAL IF [Fn] ENDIF`
166169
NonZero(Arc<Miniscript<Pk, Ctx>>),
167-
/// [X] 0NOTEQUAL
170+
/// `[X] 0NOTEQUAL`
168171
ZeroNotEqual(Arc<Miniscript<Pk, Ctx>>),
169172
// Conjunctions
170-
/// [V] [T]/[V]/[F]/[Kt]
173+
/// `[V] [T]/[V]/[F]/[Kt]`
171174
AndV(Arc<Miniscript<Pk, Ctx>>, Arc<Miniscript<Pk, Ctx>>),
172-
/// [E] [W] BOOLAND
175+
/// `[E] [W] BOOLAND`
173176
AndB(Arc<Miniscript<Pk, Ctx>>, Arc<Miniscript<Pk, Ctx>>),
174-
/// [various] NOTIF [various] ELSE [various] ENDIF
177+
/// `[various] NOTIF [various] ELSE [various] ENDIF`
175178
AndOr(
176179
Arc<Miniscript<Pk, Ctx>>,
177180
Arc<Miniscript<Pk, Ctx>>,
178181
Arc<Miniscript<Pk, Ctx>>,
179182
),
180183
// Disjunctions
181-
/// [E] [W] BOOLOR
184+
/// `[E] [W] BOOLOR`
182185
OrB(Arc<Miniscript<Pk, Ctx>>, Arc<Miniscript<Pk, Ctx>>),
183-
/// [E] IFDUP NOTIF [T]/[E] ENDIF
186+
/// `[E] IFDUP NOTIF [T]/[E] ENDIF`
184187
OrD(Arc<Miniscript<Pk, Ctx>>, Arc<Miniscript<Pk, Ctx>>),
185-
/// [E] NOTIF [V] ENDIF
188+
/// `[E] NOTIF [V] ENDIF`
186189
OrC(Arc<Miniscript<Pk, Ctx>>, Arc<Miniscript<Pk, Ctx>>),
187-
/// IF [various] ELSE [various] ENDIF
190+
/// `IF [various] ELSE [various] ENDIF`
188191
OrI(Arc<Miniscript<Pk, Ctx>>, Arc<Miniscript<Pk, Ctx>>),
189192
// Thresholds
190-
/// [E] ([W] ADD)* k EQUAL
193+
/// `[E] ([W] ADD)* k EQUAL`
191194
Thresh(usize, Vec<Arc<Miniscript<Pk, Ctx>>>),
192-
/// k (<key>)* n CHECKMULTISIG
195+
/// `k (<key>)* n CHECKMULTISIG`
193196
Multi(usize, Vec<Pk>),
194-
/// <key> CHECKSIG (<key> CHECKSIGADD)*(n-1) k NUMEQUAL
197+
/// `<key> CHECKSIG (<key> CHECKSIGADD)*(n-1) k NUMEQUAL`
195198
MultiA(usize, Vec<Pk>),
196199
}
197200

src/policy/concrete.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use crate::miniscript::types::extra_props::TimelockInfo;
2929
use crate::prelude::*;
3030
use crate::{errstr, Error, ForEachKey, MiniscriptKey, Translator};
3131

32+
#[cfg(all(doc, not(feature = "compiler")))]
33+
use crate::Descriptor;
34+
3235
/// Maximum TapLeafs allowed in a compiled TapTree
3336
#[cfg(feature = "compiler")]
3437
const MAX_COMPILATION_LEAVES: usize = 1024;
@@ -207,18 +210,18 @@ pub enum PolicyError {
207210
DuplicatePubKeys,
208211
}
209212

210-
/// Descriptor context for [`Policy`] compilation into a [`Descriptor`]
213+
/// Descriptor context for [`Policy`] compilation into a [`Descriptor`].
211214
pub enum DescriptorCtx<Pk> {
212-
/// [Bare][`Descriptor::Bare`]
215+
/// See docs for [`Descriptor::Bare`].
213216
Bare,
214-
/// [Sh][`Descriptor::Sh`]
217+
/// See docs for [`Descriptor::Sh`].
215218
Sh,
216-
/// [Wsh][`Descriptor::Wsh`]
219+
/// See docs for [`Descriptor::Wsh`].
217220
Wsh,
218-
/// Sh-wrapped [Wsh][`Descriptor::Wsh`]
221+
/// See docs for [`Descriptor::Wsh`].
219222
ShWsh,
220-
/// [Tr][`Descriptor::Tr`] where the Option<Pk> corresponds to the internal_key if no internal
221-
/// key can be inferred from the given policy
223+
/// [`Descriptor::Tr`] where the `Option<Pk>` corresponds to the internal key if no
224+
/// internal key can be inferred from the given policy.
222225
Tr(Option<Pk>),
223226
}
224227

@@ -364,7 +367,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
364367
}
365368
}
366369

367-
/// Compile the [`Policy`] into a [`Tr`][`Descriptor::Tr`] Descriptor.
370+
/// Compile the [`Policy`] into a [`Descriptor::Tr`].
368371
///
369372
/// ### TapTree compilation
370373
///
@@ -417,20 +420,26 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
417420
}
418421
}
419422

420-
/// Compile the [`Policy`] into a [`Tr`][`Descriptor::Tr`] Descriptor, with policy-enumeration
421-
/// by [`Policy::enumerate_policy_tree`].
423+
/// Compiles the [`Policy`] into a [`Descriptor::Tr`].
422424
///
423425
/// ### TapTree compilation
424426
///
425-
/// The policy tree constructed by root-level disjunctions over [`Or`][`Policy::Or`] and
426-
/// [`Thresh`][`Policy::Threshold`](k, ..n..) which is flattened into a vector (with respective
427-
/// probabilities derived from odds) of policies.
428-
/// For example, the policy `thresh(1,or(pk(A),pk(B)),and(or(pk(C),pk(D)),pk(E)))` gives the vector
427+
/// The policy tree constructed by root-level disjunctions over [`Policy::Or`] and
428+
/// [`Policy::Threshold`] (k, ..n..) which is flattened into a vector (with respective
429+
/// probabilities derived from odds) of policies. For example, the policy
430+
/// `thresh(1,or(pk(A),pk(B)),and(or(pk(C),pk(D)),pk(E)))` gives the vector
429431
/// `[pk(A),pk(B),and(or(pk(C),pk(D)),pk(E)))]`.
430432
///
431433
/// ### Policy enumeration
432434
///
433-
/// Refer to [`Policy::enumerate_policy_tree`] for the current strategy implemented.
435+
/// Generates a root-level disjunctive tree over the given policy tree.
436+
///
437+
/// Uses a fixed-point algorithm to enumerate the disjunctions until exhaustive root-level
438+
/// enumeration or limits exceed. For a given [`Policy`], we maintain an [ordered
439+
/// set](`BTreeSet`) of `(prob, policy)` (ordered by probability) to maintain the list of
440+
/// enumerated sub-policies whose disjunction is isomorphic to initial policy (*invariant*).
441+
///
442+
/// [`Policy`]: crate::policy::concrete::Policy
434443
#[cfg(feature = "compiler")]
435444
pub fn compile_tr_private_experimental(
436445
&self,
@@ -537,12 +546,14 @@ impl<Pk: MiniscriptKey> PolicyArc<Pk> {
537546
}
538547
}
539548

540-
/// Generates a root-level disjunctive tree over the given policy tree, by using fixed-point
541-
/// algorithm to enumerate the disjunctions until exhaustive root-level enumeration or limits
542-
/// exceed.
543-
/// For a given [policy][`Policy`], we maintain an [ordered set][`BTreeSet`] of `(prob, policy)`
544-
/// (ordered by probability) to maintain the list of enumerated sub-policies whose disjunction
545-
/// is isomorphic to initial policy (*invariant*).
549+
/// Generates a root-level disjunctive tree over the given policy tree.
550+
///
551+
/// Uses a fixed-point algorithm to enumerate the disjunctions until exhaustive root-level
552+
/// enumeration or limits exceed. For a given [`Policy`], we maintain an [ordered
553+
/// set](`BTreeSet`) of `(prob, policy)` (ordered by probability) to maintain the list of
554+
/// enumerated sub-policies whose disjunction is isomorphic to initial policy (*invariant*).
555+
///
556+
/// [`Policy`]: crate::policy::concrete::Policy
546557
#[cfg(feature = "compiler")]
547558
fn enumerate_policy_tree(self, prob: f64) -> Vec<(f64, Arc<Self>)> {
548559
let mut tapleaf_prob_vec = BTreeSet::<(Reverse<OrdF64>, Arc<Self>)>::new();

0 commit comments

Comments
 (0)