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

Code before:
        let mut prev_indeterminate_count = usize::MAX;
        let mut indeterminate_count = self.indeterminate_imports.len() * 3;
        while indeterminate_count < prev_indeterminate_count {
            prev_indeterminate_count = indeterminate_count;
            indeterminate_count = 0;
            for import in mem::take(&mut self.indeterminate_imports) {
                let import_indeterminate_count = self.resolve_import(import);
                indeterminate_count += import_indeterminate_count;
                match import_indeterminate_count {
                    0 => self.determined_imports.push(import),
                    _ => self.indeterminate_imports.push(import),
                }
            }
        }
    }

    pub(crate) fn finalize_imports(&mut self) {
        for module in self.arenas.local_modules().iter() {
            self.finalize_resolutions_in(*module);
        }

        for (_module_def_id, module_children) in
            self.tcx.with_stable_hashing_context(|hcx| self.module_children.to_sorted(&hcx, false))
        {
            for import in module_children {
                if !import.vis.is_public() {
                    continue;
                }

                let def::Res::<_>::Def(reexported_kind, reexported_def_id) = import.res else {
                    continue;
                };

                if let DefKind::Ctor(..) = reexported_kind {
                    continue;
                }

                if reexported_def_id.is_local() {
                    continue;
                }

                if !self.tcx.is_private_dep(reexported_def_id.krate) {
                    continue;
                }

                self.dcx()
                    .create_warn(FromPrivateDependencyInPublicInterface {
                        kind: import.res.descr(),
                        descr: import.ident.as_str(),
                        krate: self.tcx.crate_name(reexported_def_id.krate),
                    })

Review comment (suggestion):
It's better to move the lint logic to `check_hidden_glob_reexports`.

That function already has a very similar logic for iterating over bindings.
And also the effective visibility table is already populated there so you can do checks like `self.effective_visibilities.is_exported(def_id)` instead of just relying on `pub` and getting false positives.

Code after:
    // is made.

    /// Resolves all imports for the crate. This method performs the fixed-
    /// point iteration.
    pub(crate) fn resolve_imports(&mut self) {
        let mut prev_indeterminate_count = usize::MAX;
        let mut indeterminate_count = self.indeterminate_imports.len() * 3;
        while indeterminate_count < prev_indeterminate_count {
            prev_indeterminate_count = indeterminate_count;
            indeterminate_count = 0;
            for import in mem::take(&mut self.indeterminate_imports) {
                let import_indeterminate_count = self.resolve_import(import);
                indeterminate_count += import_indeterminate_count;
                match import_indeterminate_count {
                    0 => self.determined_imports.push(import),
                    _ => self.indeterminate_imports.push(import),
                }
            }
        }
    }

    pub(crate) fn finalize_imports(&mut self) {
        for module in self.arenas.local_modules().iter() {
            self.finalize_resolutions_in(*module);
        }

        let mut seen_spans = FxHashSet::default();
        let mut errors = vec![];
        let mut prev_root_id: NodeId = NodeId::ZERO;
        let determined_imports = mem::take(&mut self.determined_imports);
        let indeterminate_imports = mem::take(&mut self.indeterminate_imports);

        let mut glob_error = false;
        for (is_indeterminate, import) in determined_imports
            .iter()
            .map(|i| (false, i))
            .chain(indeterminate_imports.iter().map(|i| (true, i)))
        {
            let unresolved_import_error = self.finalize_import(*import);
            // If this import is unresolved then create a dummy import
            // resolution for it so that later resolve stages won't complain.
            self.import_dummy_binding(*import, is_indeterminate);

            let Some(err) = unresolved_import_error else { continue };

            glob_error |= import.is_glob();

            if let ImportKind::Single { source, ref bindings, .. } = import.kind
                && source.name == kw::SelfLower
                // Silence `unresolved import` error if E0429 is already emitted
                && let PendingBinding::Ready(None) = bindings.value_ns.get()