Repository: rust-lang/rust
File: compiler/rustc_borrowck/src/root_cx.rs (Rust)

Code before:
            );
            input.deferred_opaque_type_errors = compute_definition_site_hidden_types(
                *def_id,
                &input.infcx,
                &input.universal_region_relations,
                &input.constraints,
                Rc::clone(&input.location_map),
                &mut self.hidden_types,
                &mut self.unconstrained_hidden_types,
                &opaque_types,
            );
            per_body_info.push((num_entries, opaque_types));
        }

        let unexpected_region_errors = detect_unconstrained_hidden_types(
            self.tcx,
            &mut self.hidden_types,
            &mut self.unconstrained_hidden_types,
        );
        for error in unexpected_region_errors {
            let (def_id, error) = error.to_error();
            let Some(result) = self.collect_region_constraints_results.get_mut(&def_id) else {
                unreachable!("the body should depend on opaques type if it has opaque use");
            };
            result.deferred_opaque_type_errors.push(error);
        }

        for (input, (opaque_types_storage_num_entries, opaque_types)) in
            self.collect_region_constraints_results.values_mut().zip(per_body_info)
        {
            if input.deferred_opaque_type_errors.is_empty() {
                input.deferred_opaque_type_errors = apply_definition_site_hidden_types(
                    &input.infcx,
                    &input.body_owned,
                    &input.universal_region_relations.universal_regions,
                    &input.region_bound_pairs,
                    &input.known_type_outlives_obligations,
                    &mut input.constraints,
                    &mut self.hidden_types,
                    &opaque_types,
                );
            }

            detect_opaque_types_added_while_handling_opaque_types(
                &input.infcx,
                opaque_types_storage_num_entries,
            )
        }
    }

    /// Computing defining uses of opaques may depend on the propagated region

Review comment (suggestion):
is there a reason you're return a list of errors instead of eagerly adding them t `deferred_opaque_type_errors` in `detect_unconstrained_hidden_types` (i guess then called `handle_unconstrained_hidden_types`)

Code after:
            let (num_entries, opaque_types) = clone_and_resolve_opaque_types(
                &input.infcx,
                &input.universal_region_relations,
                &mut input.constraints,
            );
            input.deferred_opaque_type_errors = compute_definition_site_hidden_types(
                *def_id,
                &input.infcx,
                &input.universal_region_relations,
                &input.constraints,
                Rc::clone(&input.location_map),
                &mut self.hidden_types,
                &mut self.unconstrained_hidden_type_errors,
                &opaque_types,
            );
            per_body_info.push((num_entries, opaque_types));
        }

        handle_unconstrained_hidden_type_errors(
            self.tcx,
            &mut self.hidden_types,
            &mut self.unconstrained_hidden_type_errors,
            &mut self.collect_region_constraints_results,
        );

        for (input, (opaque_types_storage_num_entries, opaque_types)) in
            self.collect_region_constraints_results.values_mut().zip(per_body_info)
        {
            if input.deferred_opaque_type_errors.is_empty() {
                input.deferred_opaque_type_errors = apply_definition_site_hidden_types(
                    &input.infcx,
                    &input.body_owned,
                    &input.universal_region_relations.universal_regions,
                    &input.region_bound_pairs,
                    &input.known_type_outlives_obligations,
                    &mut input.constraints,
                    &mut self.hidden_types,
                    &opaque_types,
                );
            }

            detect_opaque_types_added_while_handling_opaque_types(
                &input.infcx,
                opaque_types_storage_num_entries,
            )
        }
    }

    /// Computing defining uses of opaques may depend on the propagated region
    /// requirements of nested bodies, while applying defining uses may introduce
    /// additional region requirements we need to propagate.