# Pre-expanding proc macros

**URL:** <https://internals.rust-lang.org/t/pre-expanding-proc-macros/17550>\
**Category:** tools and infrastructure\
**Created:** [October 12, 2022, 8:03pm UTC](https://internals.rust-lang.org/t/pre-expanding-proc-macros/17550 "2022-10-12T20:03:35Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![crlf0710](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/crlf0710/32/1987_2.png) [@crlf0710](https://internals.rust-lang.org/u/crlf0710)\
**Post date:** [October 20, 2022, 11:22am UTC](https://internals.rust-lang.org/t/pre-expanding-proc-macros/17550/14 "2022-10-20T11:22:04Z")

</div>

[Just posted another topic on this today...](https://internals.rust-lang.org/t/idea-pre-expanded-crates-and-expansion-dependencies/17595) Sorry i didn't found this topic because of the title!

I think the major point is the pre-expansion of the usage crate, and whether the proc macro crate itself is pre-compiled is less important.

pasting the major points from that post:

> I'm thinking maybe it's possible to add a new kind of dependency in Cargo.toml, maybe call it [expansion-dependencies], that acts just as normal dependencies. But instead, before uploading to [crates.io](http://crates.io), the proc macros defined in these crates got expanded and inlining the expansion results into the original source code. Only the expanded source code is uploaded to [crates.io](http://crates.io), and the dependency got automatically removed.

> [@Idea: Pre-expanded crates and \`expansion-dependencies\`](https://internals.rust-lang.org/t/idea-pre-expanded-crates-and-expansion-dependencies/17595/2):
>
> It’s very common for proc-macros to rely on an exact version of their runtime crate by using non-public semver exempt details from them. Pre-expanding would then extend this exact version requirement to the published crate, likely causing many unresolveable dependency trees.

> a proc macro crate can declare itself as able to be pre-expanded or not. For crates like `thiserror` and `displaydoc` , i think they're perfectly fittable for such pre-expansion.

---

_[View the full topic](https://internals.rust-lang.org/t/pre-expanding-proc-macros/17550)._
