-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
This is both a decision made after #7 and from using the proc-macro ways for the past week
I liked the proc-macro provided an inline way of documenting the dependencies, right in lib.rs
. However, the disadvantage/hacks are too cumbersome when actually using it:
- There is an unsettled conversation on if proc-macros should receive the content of non-inline modules (see Tracking issue for procedural macros and "hygiene 2.0" rust-lang/rust#54727 ). It's not clear what will be the future
- rust-analyzer integration is lacking. Although it might be possible for rust-analyzer to implement something along the lines of "look at the existing import style and suggestion closest style to import", that's a very complicated feature (because it sounds easy to a human), so it's not reasonable to expect that to be added. As a result, the imports added from accepting rust-analyzer's suggestion won't get analyzed by the layer stuff
- There's no actual way to completely prevent violations with just proc-macros. You have to also rely on code reviews and we know that's never reliable
Therefore, v0.3.0 will be a complete rewrite to a CLI tool:
- a
Layerfile.toml
will be used to declare the dependencies rather than inline in the code. We can do something along the lines of parsing comments, but that's too much of a hack - maybe we can try non-attribute macros in the future (since attribute macros are unstable) - Layers will be strictly enforced by running a check that split the crate into 2 parts: the layer being checked and its dependencies, then try to build the test crate. This check will done for every layer. This also means you cannot import from a transitive dependency
- Things like
pub(crate)
andimpl
will no longer work across layers in this case, but you can loosen the restriction in the config to allow some dependency to be in the same crate when checked. However this also means transitive dependency won't get caught
- Things like
- There will probably be issues with crate name in macro expansion. More details when it's released
Note: I have also considered static checks. However, because dependency can be generated by macros, that's simply not possible
Metadata
Metadata
Assignees
Labels
No labels