-
Notifications
You must be signed in to change notification settings - Fork 153
Clean up miniscript/mod.rs
#583
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 miniscript/mod.rs
#583
Conversation
src/miniscript/mod.rs
Outdated
@@ -59,7 +59,7 @@ pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> { | |||
pub ty: types::Type, | |||
///Additional information helpful for extra analysis. | |||
pub ext: types::extra_props::ExtData, | |||
/// Context PhantomData. Only accessible inside this crate | |||
/// Needed because not all terminals are paramatized by script context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In c874074
This is actually just used to simulate #[non_exhaustive]
which we did not have in 1.29. We can just drop it and add #[non_exhaustive]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you think this was an enum? I think the comment is correct IIUC, if we remove the phantom we get build error
error[E0392]: parameter `Ctx` is never used
--> src/miniscript/mod.rs:55:42
|
55 | pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
| ^^^ unused parameter
|
= help: consider removing `Ctx`, referring to it in a field, or using a marker such as `PhantomData`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, no, I think actually I'm just wrong. But I don't understand your comment. Ctx
is clearly used in the node
field, this error is just a bug in rustc (which I think has been well-known for many years). We should change the comment to clarify this.
And it is doing double-duty as a #[non_exhaustive]
tag, which is fine. It prevents users from directly constructing this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I thought it was being caused by the fact that not all variants of Terminal
have Ctx
. Not sure what to write there now, the original is definitely just noise though.
src/miniscript/mod.rs
Outdated
/// The type information and extra_properties can be deterministically determined | ||
/// by the ast. | ||
/// | ||
/// The type information and extra_properties can be deterministically determined by the AST. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 33c04e2:
While we're touching this, let's replace "can be deterministically determined" with "are implied" :P.
5182529 looks good otherwise |
6775430
to
3150427
Compare
Changes in force push:
|
3150427
to
447412a
Compare
... and fixed the rebase |
447412a
to
55e65f3
Compare
And rebased on master to pick up the pinning fix. |
55e65f3 is good except I'd like to change the comment on the phantom. |
The `Hash` trait is related to PartialEq, Eq, PartialOrd, Ord - as such put it next to them.
Improve and make the docs all the same.
Move the `Miniscript` impl block (with the constructors in in) to be underneath the struct. Refactor only, no logic changes.
Combine the two impl blocks that contain constructors and conversion functions. Refactor only, no logic changes.
Move the `encode` and `script_size` functions to the main impl block. Refactor only, no logic changes.
Move the two `max_satisfaction*` functions to the main impl block. Refactor only, no logic changes.
Move the two `satisfy*` functions to the main impl block. Refactor only, no logic changes.
There are now two impl blocks for `Miniscript` with different generics, put one directly under the other. To match the diff this should be said "move trait impls below the second Miniscript impl block".
Compress match arms using `|`, this makes the code more terse and easier to quickly see if terminal variants return the expected length (for the trivial ones at least).
Reduce duplicate code by factoring out a helper function. Refactor only, no logic changes.
55e65f3
to
a60c642
Compare
I just dropped the phantom doc change altogether. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a60c642
Make an effort to clean up the
miniscript/mod.rs
file. I could not see a reason for all the separate impl blocks, is there one? Please note this PR does not fix all the docs, just does ones that should not be too hard to review.