From 272562879655ab912eb0f1225d98c1824cdface8 Mon Sep 17 00:00:00 2001 From: Site Tester Date: Thu, 4 Sep 2025 09:48:25 +0300 Subject: [PATCH 1/4] Fix false positive in hidden_glob_reexports lint Fixes #146164 The lint was incorrectly warning when importing the same item that's already available through a glob re-export. This adds a check to only warn when the explicit import and glob import resolve to different items. --- compiler/rustc_resolve/src/imports.rs | 1 + tests/ui/lint/issue-146164.rs | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/ui/lint/issue-146164.rs diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index d7fc028287ff5..a9e3d33e9802a 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -677,6 +677,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { { if binding.res() != Res::Err && glob_binding.res() != Res::Err + && binding.res() != glob_binding.res() // Only warn if they're different items && let NameBindingKind::Import { import: glob_import, .. } = glob_binding.kind && let Some(glob_import_id) = glob_import.id() diff --git a/tests/ui/lint/issue-146164.rs b/tests/ui/lint/issue-146164.rs new file mode 100644 index 0000000000000..43875ced05ae8 --- /dev/null +++ b/tests/ui/lint/issue-146164.rs @@ -0,0 +1,9 @@ +// Test that hidden_glob_reexports lint doesn't warn when importing the same item +// that's already available through a glob re-export + +pub use std::option::*; +use std::option::Option; // Should not warn - same item as glob import + +fn main() { + let _x: Option = Some(42); +} From 8fdbc5ac491f1b97e7d6aac5dc57d69df575fb4b Mon Sep 17 00:00:00 2001 From: Site Tester Date: Thu, 4 Sep 2025 16:41:58 +0300 Subject: [PATCH 2/4] Add //@ check-pass, as now code should compile successfully without any warnings or errors --- tests/ui/lint/issue-146164.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/lint/issue-146164.rs b/tests/ui/lint/issue-146164.rs index 43875ced05ae8..5d33e57e5724f 100644 --- a/tests/ui/lint/issue-146164.rs +++ b/tests/ui/lint/issue-146164.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test that hidden_glob_reexports lint doesn't warn when importing the same item // that's already available through a glob re-export From e802928376da0a8f1760c9510660df3c5fe046bb Mon Sep 17 00:00:00 2001 From: Site Tester Date: Sat, 6 Sep 2025 12:33:47 +0300 Subject: [PATCH 3/4] Remove redundant comment --- tests/ui/lint/issue-146164.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/lint/issue-146164.rs b/tests/ui/lint/issue-146164.rs index 5d33e57e5724f..fb20f6700b76f 100644 --- a/tests/ui/lint/issue-146164.rs +++ b/tests/ui/lint/issue-146164.rs @@ -3,7 +3,7 @@ // that's already available through a glob re-export pub use std::option::*; -use std::option::Option; // Should not warn - same item as glob import +use std::option::Option; fn main() { let _x: Option = Some(42); From e9af07596202cb83f960f91f6b58da591a339969 Mon Sep 17 00:00:00 2001 From: Site Tester Date: Sat, 6 Sep 2025 12:43:15 +0300 Subject: [PATCH 4/4] Fix false positive in hidden_glob_reexports lint The lint was incorrectly warning when importing the same item that's already available through a glob re-export. This adds a check to only warn when the explicit import and glob import resolve to different items. --- .../{issue-146164.rs => hidden-glob-reexports-issue-146164.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/ui/lint/{issue-146164.rs => hidden-glob-reexports-issue-146164.rs} (100%) diff --git a/tests/ui/lint/issue-146164.rs b/tests/ui/lint/hidden-glob-reexports-issue-146164.rs similarity index 100% rename from tests/ui/lint/issue-146164.rs rename to tests/ui/lint/hidden-glob-reexports-issue-146164.rs