about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTimo <30553356+y21@users.noreply.github.com>2025-03-25 00:08:45 +0000
committerGitHub <noreply@github.com>2025-03-25 00:08:45 +0000
commit9c6cb5150f4c47c0673f2bc0bdd5ac1c654f0efb (patch)
treea672e97dd8d00a5536d4efc8d70c170a02dfa1ce
parentb27a2bbe26b5d4499ca71091e955e7bc7b8b1a4a (diff)
parent809c931804e5f6b338f395d13e2f31724ce1cae2 (diff)
downloadrust-9c6cb5150f4c47c0673f2bc0bdd5ac1c654f0efb.tar.gz
rust-9c6cb5150f4c47c0673f2bc0bdd5ac1c654f0efb.zip
`wildcard_imports`: lint on `pub use` if asked to (#14182)
`warn_on_all_wildcard_imports` should warn on all wildcard imports,
including the reexported ones.

Fix #13660

changelog: [`warn_on_all_wildcard_imports`]: when asked to warn on all
wildcard imports, include the reexported ones
-rw-r--r--book/src/lint_configuration.md3
-rw-r--r--clippy_config/src/conf.rs3
-rw-r--r--clippy_lints/src/wildcard_imports.rs6
-rw-r--r--tests/ui-toml/wildcard_imports/wildcard_imports.fixed2
-rw-r--r--tests/ui-toml/wildcard_imports/wildcard_imports.rs2
-rw-r--r--tests/ui-toml/wildcard_imports/wildcard_imports.stderr6
6 files changed, 14 insertions, 8 deletions
diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md
index 36f3985fc02..86bf818bb8e 100644
--- a/book/src/lint_configuration.md
+++ b/book/src/lint_configuration.md
@@ -1070,7 +1070,8 @@ The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
 
 
 ## `warn-on-all-wildcard-imports`
-Whether to allow certain wildcard imports (prelude, super in tests).
+Whether to emit warnings on all wildcard imports, including those from `prelude`, from `super` in tests,
+or for `pub use` reexports.
 
 **Default Value:** `false`
 
diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs
index eeb462dedc9..166f1ae5127 100644
--- a/clippy_config/src/conf.rs
+++ b/clippy_config/src/conf.rs
@@ -764,7 +764,8 @@ define_Conf! {
     /// The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
     #[lints(verbose_bit_mask)]
     verbose_bit_mask_threshold: u64 = 1,
-    /// Whether to allow certain wildcard imports (prelude, super in tests).
+    /// Whether to emit warnings on all wildcard imports, including those from `prelude`, from `super` in tests,
+    /// or for `pub use` reexports.
     #[lints(wildcard_imports)]
     warn_on_all_wildcard_imports: bool = false,
     /// Whether to also emit warnings for unsafe blocks with metavariable expansions in **private** macros.
diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs
index 405310512df..5b3f60ad6ab 100644
--- a/clippy_lints/src/wildcard_imports.rs
+++ b/clippy_lints/src/wildcard_imports.rs
@@ -68,6 +68,8 @@ declare_clippy_lint! {
     /// (including the standard library) provide modules named "prelude" specifically designed
     /// for wildcard import.
     ///
+    /// Wildcard imports reexported through `pub use` are also allowed.
+    ///
     /// `use super::*` is allowed in test modules. This is defined as any module with "test" in the name.
     ///
     /// These exceptions can be disabled using the `warn-on-all-wildcard-imports` configuration flag.
@@ -121,7 +123,9 @@ impl LateLintPass<'_> for WildcardImports {
         }
 
         let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id);
-        if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) {
+        if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id())
+            && !self.warn_on_all
+        {
             return;
         }
         if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind
diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.fixed b/tests/ui-toml/wildcard_imports/wildcard_imports.fixed
index af72d6be0e0..20511cbed16 100644
--- a/tests/ui-toml/wildcard_imports/wildcard_imports.fixed
+++ b/tests/ui-toml/wildcard_imports/wildcard_imports.fixed
@@ -15,7 +15,7 @@ mod my_crate {
     }
 }
 
-use utils::{BAR, print};
+pub use utils::{BAR, print};
 //~^ ERROR: usage of wildcard import
 use my_crate::utils::my_util_fn;
 //~^ ERROR: usage of wildcard import
diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.rs b/tests/ui-toml/wildcard_imports/wildcard_imports.rs
index 91009dd8835..8d05910f471 100644
--- a/tests/ui-toml/wildcard_imports/wildcard_imports.rs
+++ b/tests/ui-toml/wildcard_imports/wildcard_imports.rs
@@ -15,7 +15,7 @@ mod my_crate {
     }
 }
 
-use utils::*;
+pub use utils::*;
 //~^ ERROR: usage of wildcard import
 use my_crate::utils::*;
 //~^ ERROR: usage of wildcard import
diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.stderr b/tests/ui-toml/wildcard_imports/wildcard_imports.stderr
index 3d3be965aa4..5e624dd6c3c 100644
--- a/tests/ui-toml/wildcard_imports/wildcard_imports.stderr
+++ b/tests/ui-toml/wildcard_imports/wildcard_imports.stderr
@@ -1,8 +1,8 @@
 error: usage of wildcard import
-  --> tests/ui-toml/wildcard_imports/wildcard_imports.rs:18:5
+  --> tests/ui-toml/wildcard_imports/wildcard_imports.rs:18:9
    |
-LL | use utils::*;
-   |     ^^^^^^^^ help: try: `utils::{BAR, print}`
+LL | pub use utils::*;
+   |         ^^^^^^^^ help: try: `utils::{BAR, print}`
    |
    = note: `-D clippy::wildcard-imports` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]`