You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the mod.rs usually containing a specific abstract traits and its accompaning Rust files containing concrete impls.
From time to time I catch myself erroneously and thoughtlessly adding a use statement for a concrete impl to one of those mod.rs files, which results in a module dependency coupling that I want to avoid at all costs.
As such I'd love to be able to add an attribute to my conrete impl modules prohibiting the use by their abstract trait (super) module.
/dolor/mod.rs:
traitDolor{ ... }
/dolor/amet.rs:
use dolor;traitAmet:Dolor{ ... }
/dolor/amet/elit.rs:
// either by relative path:#![deny(use_by(super::super,super))]// or by absolute path:#![deny(use_by(dolor, dolor::amet))]use dolor::{self, amet};structAmetImpl{ ... }implDolorforAmetImpl{ ... }implAmetforAmetImpl{ ... }
/dolor/amet/adipiscing.rs:
...// basically no #![deny(use_by(...))]
So if I was to change /dolor/mod.rs to this:
use amet::elit;use amet::adipiscing;traitDolor{ ... }
I should get a clippy error:
use amet::elit;// ERROR: prohibited use of `amet::elit`.
Now in reality things tend to be a bit more complex.
Thus it would have to be able to resolve indirect used and flag those, too.
As such changing /dolor/amet/adipiscing.rs to this…
usesuper::elit;
...
… should now produce two clippy errors in /dolor/mod.rs:
use amet::elit;// ERROR: prohibited direct use of `amet::elit`!use amet::adipiscing;// ERROR: prohibited indirect use of `amet::elit`!
This is probably possible even with vanilla clippy.
But using @llogiq's metacollect it would probably be a piece of cake even.
The text was updated successfully, but these errors were encountered:
This doesn't need metacollect since I think attributes are stored in the def map. However, this seems like a very specific use case, perhaps more suited for a separate lint crate?
One of my more ambitious projects (~20 traits, ~50 impls of said traits) aims to be fully modular, extensible and generic.
As such the project's overall module structure looks something like this:
With the
mod.rs
usually containing a specific abstract traits and its accompaning Rust files containing concrete impls.From time to time I catch myself erroneously and thoughtlessly adding a use statement for a concrete impl to one of those
mod.rs
files, which results in a module dependency coupling that I want to avoid at all costs.As such I'd love to be able to add an attribute to my conrete impl modules prohibiting the use by their abstract trait (super) module.
/dolor/mod.rs
:/dolor/amet.rs
:/dolor/amet/elit.rs
:/dolor/amet/adipiscing.rs
:So if I was to change
/dolor/mod.rs
to this:I should get a clippy error:
Now in reality things tend to be a bit more complex.
Thus it would have to be able to resolve indirect used and flag those, too.
As such changing
/dolor/amet/adipiscing.rs
to this…… should now produce two clippy errors in
/dolor/mod.rs
:This is probably possible even with vanilla clippy.
But using @llogiq's metacollect it would probably be a piece of cake even.
The text was updated successfully, but these errors were encountered: