Skip to content

Do not lint for wildcard_imports in external macro #15413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/wildcard_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);

impl LateLintPass<'_> for WildcardImports {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if cx.sess().is_test_crate() {
if cx.sess().is_test_crate() || item.span.in_external_macro(cx.sess().source_map()) {
return;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/ui-toml/wildcard_imports/wildcard_imports.fixed
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
#![warn(clippy::wildcard_imports)]

mod prelude {
Expand All @@ -13,6 +14,10 @@ mod my_crate {
pub mod utils {
pub fn my_util_fn() {}
}

pub mod utils2 {
pub const SOME_CONST: u32 = 1;
}
}

pub use utils::{BAR, print};
Expand All @@ -22,6 +27,12 @@ use my_crate::utils::my_util_fn;
use prelude::FOO;
//~^ ERROR: usage of wildcard import

proc_macros::external! {
use my_crate::utils2::*;

static SOME_STATIC: u32 = SOME_CONST;
}

fn main() {
let _ = FOO;
let _ = BAR;
Expand Down
11 changes: 11 additions & 0 deletions tests/ui-toml/wildcard_imports/wildcard_imports.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
#![warn(clippy::wildcard_imports)]

mod prelude {
Expand All @@ -13,6 +14,10 @@ mod my_crate {
pub mod utils {
pub fn my_util_fn() {}
}

pub mod utils2 {
pub const SOME_CONST: u32 = 1;
}
}

pub use utils::*;
Expand All @@ -22,6 +27,12 @@ use my_crate::utils::*;
use prelude::*;
//~^ ERROR: usage of wildcard import

proc_macros::external! {
use my_crate::utils2::*;

static SOME_STATIC: u32 = SOME_CONST;
}

fn main() {
let _ = FOO;
let _ = BAR;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui-toml/wildcard_imports/wildcard_imports.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: usage of wildcard import
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:18:9
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:23:9
|
LL | pub use utils::*;
| ^^^^^^^^ help: try: `utils::{BAR, print}`
Expand All @@ -8,13 +8,13 @@ LL | pub use utils::*;
= help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]`

error: usage of wildcard import
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:20:5
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:25:5
|
LL | use my_crate::utils::*;
| ^^^^^^^^^^^^^^^^^^ help: try: `my_crate::utils::my_util_fn`

error: usage of wildcard import
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:22:5
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:27:5
|
LL | use prelude::*;
| ^^^^^^^^^^ help: try: `prelude::FOO`
Expand Down
Loading