Repository: rust-lang/rust
File: compiler/rustc_hir_typeck/src/upvar.rs (Rust)

Code before:
                        } else {
                            // This is a closure without braces around the body.
                            // We add braces to add the `let` before the body.
                            lint.multipart_suggestion(
                                diagnostic_msg,
                                vec![
                                    (closure_body_span.shrink_to_lo(), format!("{{ {migration_string}; ")),
                                    (closure_body_span.shrink_to_hi(), " }".to_string()),
                                ],
                                Applicability::MachineApplicable
                            );
                        }
                    } else {
                        lint.span_suggestion(
                            closure_span,
                            diagnostic_msg,
                            migration_string,
                            Applicability::HasPlaceholders
                        );
                    }
                },
            );
        }
    }

    fn try_structurally_resolve_place_ty(&self, span: Span, place: &mut Place<'tcx>) {
        let cause = self.misc(span);
        let ocx = ObligationCtxt::new_with_diagnostics(&self.infcx);
        let deeply_normalize = |ty| {
            let ty = self.resolve_vars_if_possible(ty);
            match ocx.deeply_normalize(&cause, self.param_env, ty) {
                Ok(ty) => ty,
                Err(errors) => {
                    let guar = self.infcx.err_ctxt().report_fulfillment_errors(errors);
                    Ty::new_error(self.tcx, guar)
                }
            }
        };

        place.base_ty = deeply_normalize(place.base_ty);
        for proj in &mut place.projections {
            proj.ty = deeply_normalize(proj.ty);
        }
    }

    /// Combines all the reasons for 2229 migrations
    fn compute_2229_migrations_reasons(
        &self,
        auto_trait_reasons: UnordSet<&'static str>,
        drop_order: bool,
    ) -> MigrationWarningReason {

Review comment (suggestion):
`deeply_normalize` should normalize arbitrary `TypeFoldable` things. Is `Place` type foldable?

Also, change this function name :> 

Code after:
                                diagnostic_msg,
                                vec![
                                    (closure_body_span.shrink_to_lo(), format!("{{ {migration_string}; ")),
                                    (closure_body_span.shrink_to_hi(), " }".to_string()),
                                ],
                                Applicability::MachineApplicable
                            );
                        }
                    } else {
                        lint.span_suggestion(
                            closure_span,
                            diagnostic_msg,
                            migration_string,
                            Applicability::HasPlaceholders
                        );
                    }
                },
            );
        }
    }
    fn normalize_capture_place(&self, span: Span, place: Place<'tcx>) -> Place<'tcx> {
        let mut place = self.resolve_vars_if_possible(place);

        // In the new solver, types in HIR `Place`s can contain unnormalized aliases,
        // which can ICE later (e.g. when projecting fields for diagnostics).
        if self.next_trait_solver() {
            let cause = self.misc(span);
            let at = self.at(&cause, self.param_env);
            match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
                at,
                place.clone(),
                vec![],
            ) {
                Ok((normalized, goals)) => {
                    if !goals.is_empty() {
                        let mut typeck_results = self.typeck_results.borrow_mut();
                        typeck_results.coroutine_stalled_predicates.extend(
                            goals
                                .into_iter()
                                // FIXME: throwing away the param-env :(
                                .map(|goal| (goal.predicate, self.misc(span))),
                        );
                    }
                    normalized
                }
                Err(errors) => {
                    let guar = self.infcx.err_ctxt().report_fulfillment_errors(errors);
                    place.base_ty = Ty::new_error(self.tcx, guar);
                    for proj in &mut place.projections {
                        proj.ty = Ty::new_error(self.tcx, guar);
                    }