-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
What it does
Sometimes, projects may want to use names like Any inside e.g. a module like ordering. However, common names like Any may conflict with other concepts, which could be confusing. One solution, of course, is to inject (duplicate) the namespace into the name, e.g. OrderingAny. Another is to have users write ordering::Any.
However, for projects that want to do the latter, it would be nice to have a way to avoid users useing directly Any. Thus such a lint would be convenient.
Thus the lint would catch such cases, given a list of item names (or probably regexes?) to match. Wildcard imports would trigger it too.
Put another way, this lint would be similar to enum_glob_use and wildcard_imports, but for non-wildcards and particular items/names, rather than disallowing everything.
Ideally, this could be an attribute on items, so that a list does not need to be maintained globally in the configuration.
Discussed in the context of the Linux kernel at: https://lore.kernel.org/rust-for-linux/CANiq72=Oq-JHkBuTAZPVYO5omuXswgGfLXu+nAGwEdRdgkU-0w@mail.gmail.com/.
Advantage
No response
Drawbacks
No response
Example
use ordering::Any;
fn f(_: Any) {}and
use ordering::*;
fn f(_: Any) {}could be written e.g. as
fn f(_: ordering::Any) {}when Any is tagged as non-importable, e.g.
disallow-imports = [
"ordering::Any",
]or, better, e.g.
#[non_importable]
struct Any;