Only compute the DefId when a diagnostic is definitely emitted

This commit is contained in:
Oli Scherer 2025-04-10 06:42:47 +00:00
parent d35e830aad
commit 98d51fb44f

View file

@ -639,38 +639,38 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
} }
if let Some(glob_binding) = resolution.shadowed_glob { 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 if binding.res() != Res::Err
&& glob_binding.res() != Res::Err && glob_binding.res() != Res::Err
&& let NameBindingKind::Import { import: glob_import, .. } = && let NameBindingKind::Import { import: glob_import, .. } =
glob_binding.kind glob_binding.kind
&& let Some(binding_id) = binding_id
&& let Some(glob_import_id) = glob_import.id() && let Some(glob_import_id) = glob_import.id()
&& let glob_import_def_id = self.local_def_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) && self.effective_visibilities.is_exported(glob_import_def_id)
&& glob_binding.vis.is_public() && glob_binding.vis.is_public()
&& !binding.vis.is_public() && !binding.vis.is_public()
{ {
self.lint_buffer.buffer_lint( let binding_id = match binding.kind {
HIDDEN_GLOB_REEXPORTS, NameBindingKind::Res(res) => {
binding_id, Some(self.def_id_to_node_id(res.def_id().expect_local()))
binding.span, }
BuiltinLintDiag::HiddenGlobReexports { NameBindingKind::Module(module) => {
name: key.ident.name.to_string(), Some(self.def_id_to_node_id(module.def_id().expect_local()))
namespace: key.ns.descr().to_owned(), }
glob_reexport_span: glob_binding.span, NameBindingKind::Import { import, .. } => import.id(),
private_item_span: binding.span, };
}, 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,
},
);
}
} }
} }
} }