Skip to content

Commit 03ae8b0

Browse files
authored
Do not lint for wildcard_imports in external macro (#15413)
Fixes #15412 changelog: [`wildcard_imports`]: do not lint code coming from an external macro
2 parents 8396d73 + 6c7fa3b commit 03ae8b0

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

clippy_lints/src/wildcard_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
118118

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

tests/ui-toml/wildcard_imports/wildcard_imports.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
12
#![warn(clippy::wildcard_imports)]
23

34
mod prelude {
@@ -13,6 +14,10 @@ mod my_crate {
1314
pub mod utils {
1415
pub fn my_util_fn() {}
1516
}
17+
18+
pub mod utils2 {
19+
pub const SOME_CONST: u32 = 1;
20+
}
1621
}
1722

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

30+
proc_macros::external! {
31+
use my_crate::utils2::*;
32+
33+
static SOME_STATIC: u32 = SOME_CONST;
34+
}
35+
2536
fn main() {
2637
let _ = FOO;
2738
let _ = BAR;

tests/ui-toml/wildcard_imports/wildcard_imports.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@aux-build:../../ui/auxiliary/proc_macros.rs
12
#![warn(clippy::wildcard_imports)]
23

34
mod prelude {
@@ -13,6 +14,10 @@ mod my_crate {
1314
pub mod utils {
1415
pub fn my_util_fn() {}
1516
}
17+
18+
pub mod utils2 {
19+
pub const SOME_CONST: u32 = 1;
20+
}
1621
}
1722

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

30+
proc_macros::external! {
31+
use my_crate::utils2::*;
32+
33+
static SOME_STATIC: u32 = SOME_CONST;
34+
}
35+
2536
fn main() {
2637
let _ = FOO;
2738
let _ = BAR;

tests/ui-toml/wildcard_imports/wildcard_imports.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: usage of wildcard import
2-
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:18:9
2+
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:23:9
33
|
44
LL | pub use utils::*;
55
| ^^^^^^^^ help: try: `utils::{BAR, print}`
@@ -8,13 +8,13 @@ LL | pub use utils::*;
88
= help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]`
99

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

1616
error: usage of wildcard import
17-
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:22:5
17+
--> tests/ui-toml/wildcard_imports/wildcard_imports.rs:27:5
1818
|
1919
LL | use prelude::*;
2020
| ^^^^^^^^^^ help: try: `prelude::FOO`

0 commit comments

Comments
 (0)