Wildcard use …::* import
ID |
rust.maintainability.avoid_star_import |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Readability |
Language |
Rust |
Description
Reports a glob import (use path::*;) that pulls every public item of a module into the current scope. Preludes, super::* and glob imports inside a mod tests block are not reported, since those are the idiomatic uses of the form.
Rationale
A glob import hides where a name comes from, so a reader has to search the whole dependency tree to resolve an identifier. It also makes the code fragile: adding a public item upstream can shadow a local name or introduce an ambiguity that breaks the build in a file that was never edited.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Wildcard `use ...::*` import
use std::collections::*;