Skip to content

Move transparent_newtype to use include!#5612

Merged
apoelstra merged 2 commits intorust-bitcoin:masterfrom
mpbagot:feature/newtype-macro-includes
Apr 1, 2026
Merged

Move transparent_newtype to use include!#5612
apoelstra merged 2 commits intorust-bitcoin:masterfrom
mpbagot:feature/newtype-macro-includes

Conversation

@mpbagot
Copy link
Copy Markdown
Contributor

@mpbagot mpbagot commented Feb 4, 2026

The transparent_newtype macro from internals is one of many cross-crate macros which we'd like to remove over time.

  • Patch 1 adjusts hashes newtype doc comments.
  • Patch 2 copies transparent_newtype macro to includes directory and replaces all uses of internals::transparent_newtype with include! calls and direct usage of the macro.

Contributes to #5596

@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate C-internals PRs modifying the internals crate C-io PRs modifying the io crate C-primitives labels Feb 4, 2026
@mpbagot mpbagot changed the title Move transparent_newtype to use inlude! Move transparent_newtype to use include! Feb 4, 2026
@tcharding
Copy link
Copy Markdown
Member

tcharding commented Feb 4, 2026

NOTE: While this builds correctly with cargo/rustc, vscode users will notice that rust-analyzer lights the IDE up with a whole bunch of errors due to problems resolving an include! path outside of the immediate crate.
This is (possibly) still an open problem that needs resolving for workspace-wide include! usage.

I don't personally use rust-analyzer and I really want to not care but in reality this seems like a show stopper?

FWIW I think we should put the include! call is lib.rs always. I tested it in hashes and it works. FTR I have no clue how the macro call is being resolved, might be worth documenting the calls:

include!("../../includes/newtype.rs"); // Explained in `REPO_DIR/docs/README.md`.

// Defined in `REPO_DIR/includes/newtype.rs`.
transparent_newtype! {
...
}

And writing a README (if we ever do this).

@apoelstra
Copy link
Copy Markdown
Member

apoelstra commented Feb 8, 2026

I'm using helix with rust-analyzer and it seems to work fine for me weirdly I get a "failed to load file ../../includes/newtype.rs" error but it still recognizes the transparent_newtype macro (and does not recognize a typo of it).

This seems fine to me.

At some point, if the language is going to be this hostile as to have no specialization, overboaring coherence rules, no useful syntax for doing blanket impls, and no codegen, we should just switch languages. But my feeling is that "some IDEs show spurious errors" is the least worst of all worlds.

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from b798d04 to 40fd3a0 Compare February 9, 2026 00:15
@github-actions github-actions bot added the doc label Feb 9, 2026
@mpbagot
Copy link
Copy Markdown
Contributor Author

mpbagot commented Feb 9, 2026

I've fixed up the docs CI errors, moved the uses of include! to lib.rs in each of the crates and added a short paragraph to the docs.

tcharding
tcharding previously approved these changes Feb 10, 2026
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 40fd3a0

@tcharding
Copy link
Copy Markdown
Member

Perhaps throw an SPDX licence comment on the new file.

// SPDX-License-Identifier: CC0-1.0

@tcharding
Copy link
Copy Markdown
Member

I rekon we can undraft, merge, YOLO!

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from 40fd3a0 to 56c73d9 Compare February 10, 2026 05:16
@mpbagot mpbagot marked this pull request as ready for review February 10, 2026 05:16
tcharding
tcharding previously approved these changes Feb 12, 2026
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 56c73d9

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK a03d64f

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from a03d64f to f9eddd2 Compare March 3, 2026 04:41
@tcharding
Copy link
Copy Markdown
Member

Still needs rebase mate.

@mpbagot
Copy link
Copy Markdown
Contributor Author

mpbagot commented Mar 3, 2026

Yep, I know. My local master was out of date. The macro is now causing lint errors in the unsafe parts, so I'm trying to figure that out.

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from f9eddd2 to ca6f2c5 Compare March 3, 2026 04:55
@apoelstra apoelstra closed this Mar 4, 2026
@apoelstra apoelstra reopened this Mar 4, 2026
@apoelstra
Copy link
Copy Markdown
Member

Sorry, wrong button. Looks like it needs an API update.

@mpbagot
Copy link
Copy Markdown
Contributor Author

mpbagot commented Mar 5, 2026

Looks like it needs an API update.

API update is broken on master. It's fixed in #5764 . I can rebase after to fix the CI if you'd like.

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from ca6f2c5 to baa342d Compare March 7, 2026 00:47
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK baa342d

internals::_emit_alloc! {
$(#[$($from_box_attr)*])*
#[inline]
#[allow(clippy::ptr_as_ptr)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FTR I had to look this lint up. I wrestled with it for a bit but couldn't come up with anything other than this solution.

Perhaps use this?

            #[allow(clippy::ptr_as_ptr)] // Cannot use `cast()` because size of `Self` is not know at compile time. 

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FTR I like to comment on less well known attributes to save the next guy investigating why the attribute is there or checking if it has become stale.

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK baa342d

@tcharding tcharding added the one ack PRs that have one ACK, so one more can progress them label Mar 8, 2026
@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from baa342d to c0c49f1 Compare March 9, 2026 00:46
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK c0c49f1

@apoelstra
Copy link
Copy Markdown
Member

c0c49f1 needs rebase

@apoelstra
Copy link
Copy Markdown
Member

I have gotten my local CI to like the include/ directory so when this is rebased I can test and merge it.

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch 2 times, most recently from bbb1a9b to 1839853 Compare March 29, 2026 17:20
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 1839853

@apoelstra
Copy link
Copy Markdown
Member

In ce15f30:

Tobin has complained about this formatter patch in multiple other places (including in #5918 which is closed). Should we fix that here?

@apoelstra
Copy link
Copy Markdown
Member

Also, for those new to the project -- this kind of shit is one reason we don't enforce rustfmt here.

@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from 1839853 to 88b9a60 Compare March 30, 2026 04:28
@mpbagot
Copy link
Copy Markdown
Contributor Author

mpbagot commented Mar 30, 2026

Tobin has complained about this formatter patch in multiple other places (including in #5918 which is closed). Should we fix that here?

I made a variation on it in #5919 that he ACK'ed after I added some skips. I've cherry-picked that in here in place of the plain format patch. If you'd still prefer to have it elsewhere to keep the non-automated changes separate, then I can open another PR for the formatting changes.

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 88b9a60

@tcharding
Copy link
Copy Markdown
Member

Its easy enough to review, I personally don't mind how or where it goes in.

mpbagot added 2 commits April 1, 2026 01:34
In hashes, a handful of the transparent_newtype invocations for hashes
use doc comments that are missing backticks around names or are
generally unclean. These should be normalised to suit typical style.

Adjust doc comments on sha256t, sha256d, muhash and siphash hash
newtypes.
The transparent_newtype macro from internals is one of many cross-crate
macros which we'd like to remove over time.

Copy transparent_newtype macro to include directory. Replace all uses
of internals::transparent_newtype with include! calls and direct usage
of the macro.
@mpbagot mpbagot force-pushed the feature/newtype-macro-includes branch from 88b9a60 to ac8f61f Compare March 31, 2026 14:34
@mpbagot
Copy link
Copy Markdown
Contributor Author

mpbagot commented Mar 31, 2026

Rebased because the formatting is fixed by #5927

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK ac8f61f

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK ac8f61f; successfully ran local tests

@apoelstra apoelstra merged commit dde0c21 into rust-bitcoin:master Apr 1, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate C-internals PRs modifying the internals crate C-io PRs modifying the io crate C-primitives doc one ack PRs that have one ACK, so one more can progress them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants