From 98d51fb44f4944b8bdad93a529d0625b9998bc93 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 10 Apr 2025 06:42:47 +0000 Subject: [PATCH] Only compute the `DefId` when a diagnostic is definitely emitted --- compiler/rustc_resolve/src/imports.rs | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 73676849ecc..3f3b455f4db 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -639,38 +639,38 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } if let Some(glob_binding) = resolution.shadowed_glob { - let binding_id = match binding.kind { - NameBindingKind::Res(res) => { - Some(self.def_id_to_node_id(res.def_id().expect_local())) - } - NameBindingKind::Module(module) => { - Some(self.def_id_to_node_id(module.def_id().expect_local())) - } - NameBindingKind::Import { import, .. } => import.id(), - }; - if binding.res() != Res::Err && glob_binding.res() != Res::Err && let NameBindingKind::Import { import: glob_import, .. } = glob_binding.kind - && let Some(binding_id) = binding_id && let Some(glob_import_id) = glob_import.id() && let glob_import_def_id = self.local_def_id(glob_import_id) && self.effective_visibilities.is_exported(glob_import_def_id) && glob_binding.vis.is_public() && !binding.vis.is_public() { - self.lint_buffer.buffer_lint( - HIDDEN_GLOB_REEXPORTS, - binding_id, - binding.span, - BuiltinLintDiag::HiddenGlobReexports { - name: key.ident.name.to_string(), - namespace: key.ns.descr().to_owned(), - glob_reexport_span: glob_binding.span, - private_item_span: binding.span, - }, - ); + let binding_id = match binding.kind { + NameBindingKind::Res(res) => { + Some(self.def_id_to_node_id(res.def_id().expect_local())) + } + NameBindingKind::Module(module) => { + Some(self.def_id_to_node_id(module.def_id().expect_local())) + } + NameBindingKind::Import { import, .. } => import.id(), + }; + if let Some(binding_id) = binding_id { + self.lint_buffer.buffer_lint( + HIDDEN_GLOB_REEXPORTS, + binding_id, + binding.span, + BuiltinLintDiag::HiddenGlobReexports { + name: key.ident.name.to_string(), + namespace: key.ns.descr().to_owned(), + glob_reexport_span: glob_binding.span, + private_item_span: binding.span, + }, + ); + } } } }