Repository: rust-lang/rust
File: compiler/rustc_resolve/src/imports.rs (Rust)

Code before:
                            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,
                                },
                            );
                        }
                    }
                }

                if let NameBindingKind::Import { import, .. } = binding.kind
                    && let Some(binding_id) = import.id()
                    && let import_def_id = self.local_def_id(binding_id)
                    && self.effective_visibilities.is_exported(import_def_id)
                    && let Res::Def(reexported_kind, reexported_def_id) = binding.res()
                    && !matches!(reexported_kind, DefKind::Ctor(..))
                    && !reexported_def_id.is_local()
                    && self.tcx.is_private_dep(reexported_def_id.krate)
                {
                    self.lint_buffer.buffer_lint(
                        EXPORTED_PRIVATE_DEPENDENCIES,
                        binding_id,
                        binding.span,
                        BuiltinLintDiag::ReexportPrivateDependency {
                            kind: binding.res().descr().to_string(),
                            name: key.ident.name.to_string(),
                            krate: self.tcx.crate_name(reexported_def_id.krate),
                        },
                    );
                }
            }
        }
    }

    fn throw_unresolved_import_error(
        &mut self,
        mut errors: Vec<(Import<'_>, UnresolvedImportError)>,
        glob_error: bool,
    ) {
        errors.retain(|(_import, err)| match err.module {

Review comment (performance):
Nit: it makes sense to put the expensive checks last (`effective_visibilities.is_exported`, then `is_private_dep`) and cheap but effective checks first (`reexported_def_id.is_local()`).

Code after:
                            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,
                                },
                            );
                        }
                    }
                }

                if let NameBindingKind::Import { import, .. } = binding.kind
                    && let Some(binding_id) = import.id()
                    && let import_def_id = self.local_def_id(binding_id)
                    && self.effective_visibilities.is_exported(import_def_id)
                    && let Res::Def(reexported_kind, reexported_def_id) = binding.res()
                    && !matches!(reexported_kind, DefKind::Ctor(..))
                    && !reexported_def_id.is_local()
                    && self.tcx.is_private_dep(reexported_def_id.krate)
                {
                    self.lint_buffer.buffer_lint(
                        EXPORTED_PRIVATE_DEPENDENCIES,
                        binding_id,
                        binding.span,
                        BuiltinLintDiag::ReexportPrivateDependency {
                            kind: binding.res().descr().to_string(),
                            name: key.ident.name.to_string(),
                            krate: self.tcx.crate_name(reexported_def_id.krate),
                        },
                    );
                }
            }
        }
    }

    fn throw_unresolved_import_error(
        &mut self,
        mut errors: Vec<(Import<'_>, UnresolvedImportError)>,
        glob_error: bool,
    ) {
        errors.retain(|(_import, err)| match err.module {
            // Skip `use` errors for `use foo::Bar;` if `foo.rs` has unrecovered parse errors.
            Some(def_id) if self.mods_with_parse_errors.contains(&def_id) => false,
            _ => true,