Skip to content

Commit 954407a

Browse files
committed
wildcard_imports: lint on pub use if asked too
`warn_on_all_wildcard_imports` should warn on all wildcard imports, including the reexported ones.
1 parent d7fd1c8 commit 954407a

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

clippy_lints/src/wildcard_imports.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ impl LateLintPass<'_> for WildcardImports {
121121
}
122122

123123
let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id);
124-
if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) {
124+
if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id())
125+
&& !self.warn_on_all
126+
{
125127
return;
126128
}
127129
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind

tests/ui-toml/wildcard_imports/wildcard_imports.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod my_crate {
1515
}
1616
}
1717

18-
use utils::{BAR, print};
18+
pub use utils::{BAR, print};
1919
//~^ ERROR: usage of wildcard import
2020
use my_crate::utils::my_util_fn;
2121
//~^ ERROR: usage of wildcard import

tests/ui-toml/wildcard_imports/wildcard_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod my_crate {
1515
}
1616
}
1717

18-
use utils::*;
18+
pub use utils::*;
1919
//~^ ERROR: usage of wildcard import
2020
use my_crate::utils::*;
2121
//~^ ERROR: usage of wildcard import

tests/ui-toml/wildcard_imports/wildcard_imports.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: usage of wildcard import
2-
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:18:5
2+
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:18:9
33
|
4-
LL | use utils::*;
5-
| ^^^^^^^^ help: try: `utils::{BAR, print}`
4+
LL | pub use utils::*;
5+
| ^^^^^^^^ help: try: `utils::{BAR, print}`
66
|
77
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]`

0 commit comments

Comments
 (0)