Skip to content

Commit fa73472

Browse files
committed
Only compute the DefId when a diagnostic is definitely emitted
1 parent cd4196a commit fa73472

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

compiler/rustc_resolve/src/imports.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -639,38 +639,38 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
639639
}
640640

641641
if let Some(glob_binding) = resolution.shadowed_glob {
642-
let binding_id = match binding.kind {
643-
NameBindingKind::Res(res) => {
644-
Some(self.def_id_to_node_id(res.def_id().expect_local()))
645-
}
646-
NameBindingKind::Module(module) => {
647-
Some(self.def_id_to_node_id(module.def_id().expect_local()))
648-
}
649-
NameBindingKind::Import { import, .. } => import.id(),
650-
};
651-
652642
if binding.res() != Res::Err
653643
&& glob_binding.res() != Res::Err
654644
&& let NameBindingKind::Import { import: glob_import, .. } =
655645
glob_binding.kind
656-
&& let Some(binding_id) = binding_id
657646
&& let Some(glob_import_id) = glob_import.id()
658647
&& let glob_import_def_id = self.local_def_id(glob_import_id)
659648
&& self.effective_visibilities.is_exported(glob_import_def_id)
660649
&& glob_binding.vis.is_public()
661650
&& !binding.vis.is_public()
662651
{
663-
self.lint_buffer.buffer_lint(
664-
HIDDEN_GLOB_REEXPORTS,
665-
binding_id,
666-
binding.span,
667-
BuiltinLintDiag::HiddenGlobReexports {
668-
name: key.ident.name.to_string(),
669-
namespace: key.ns.descr().to_owned(),
670-
glob_reexport_span: glob_binding.span,
671-
private_item_span: binding.span,
672-
},
673-
);
652+
let binding_id = match binding.kind {
653+
NameBindingKind::Res(res) => {
654+
Some(self.def_id_to_node_id(res.def_id().expect_local()))
655+
}
656+
NameBindingKind::Module(module) => {
657+
Some(self.def_id_to_node_id(module.def_id().expect_local()))
658+
}
659+
NameBindingKind::Import { import, .. } => import.id(),
660+
};
661+
if let Some(binding_id) = binding_id {
662+
self.lint_buffer.buffer_lint(
663+
HIDDEN_GLOB_REEXPORTS,
664+
binding_id,
665+
binding.span,
666+
BuiltinLintDiag::HiddenGlobReexports {
667+
name: key.ident.name.to_string(),
668+
namespace: key.ns.descr().to_owned(),
669+
glob_reexport_span: glob_binding.span,
670+
private_item_span: binding.span,
671+
},
672+
);
673+
}
674674
}
675675
}
676676
}

0 commit comments

Comments
 (0)