Add lint disallowed_modules#17189
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dswij (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
d120c67 to
d77d2bf
Compare
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
d77d2bf to
484a08b
Compare
This comment has been minimized.
This comment has been minimized.
|
Reminder, once the PR becomes ready for a review, use |
|
Reexports, such as std::sync::Arc should now be caught properly. While adding more tests, i realized a limitation of my current approach though: When using reexported items that are themselves reexported in the banned module (or in other words not defined in a banned module), those items are not flagged. I documented this as a limitation for now, as I am not sure if/how this should be fixed. mod inner {
// allow import via this module
#![allow(clippy::disallowed_modules)]
pub use std::sync::{Mutex, Weak};
}
// Weak does not get flagged because it is defined in alloc::sync, which is not banned, not
// std::sync and its path is inner::Weak, which is also not banned, not std::sync::Weak.
// Note that importing Mutex still fails, since it is defined in std::sync, which is banned.
use inner::{Mutex as StdMutex, Weak as InnerWeak}; |
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
dd5afb9 to
d6ada34
Compare
This comment has been minimized.
This comment has been minimized.
|
r? clippy |
This comment has been minimized.
This comment has been minimized.
d6ada34 to
e8d9d35
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
After some consideration, I realized that checking only paths, rather than checking the definition modules of items, is a better approach here, because it more accurately captures the aim of the lint, allows for easier usage to lint things like internal reexport shims and can be implemented much more simply. This means that my previous comment does not apply anymore, as we do not care about definition modules. Currently the lint emits at most one diagnostic per checked path, with only the outermost disallowed module in a path being reported. |
Implement new lint
disallowed_modules, which flags the usage of banned modules. Based on lintdisallowed_types.Closes #9489