Rollup merge of #103862 - compiler-errors:ocx-in-fully-normalize, r=spastorino

Use `ObligationCtxt` in `fully_normalize`

Simplifies the implementation a bit
This commit is contained in:
Dylan DPC 2022-11-02 22:32:05 +05:30 committed by GitHub
commit 0312935473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -390,6 +390,7 @@ pub fn normalize_param_env_or_error<'tcx>(
} }
/// Normalize a type and process all resulting obligations, returning any errors /// Normalize a type and process all resulting obligations, returning any errors
#[instrument(skip_all)]
pub fn fully_normalize<'tcx, T>( pub fn fully_normalize<'tcx, T>(
infcx: &InferCtxt<'tcx>, infcx: &InferCtxt<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
@ -399,28 +400,18 @@ pub fn fully_normalize<'tcx, T>(
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
debug!("fully_normalize_with_fulfillcx(value={:?})", value); let ocx = ObligationCtxt::new(infcx);
let selcx = &mut SelectionContext::new(infcx); debug!(?value);
let Normalized { value: normalized_value, obligations } = let normalized_value = ocx.normalize(cause, param_env, value);
project::normalize(selcx, param_env, cause, value); debug!(?normalized_value);
debug!( debug!("select_all_or_error start");
"fully_normalize: normalized_value={:?} obligations={:?}", let errors = ocx.select_all_or_error();
normalized_value, obligations
);
let mut fulfill_cx = FulfillmentContext::new();
for obligation in obligations {
fulfill_cx.register_predicate_obligation(infcx, obligation);
}
debug!("fully_normalize: select_all_or_error start");
let errors = fulfill_cx.select_all_or_error(infcx);
if !errors.is_empty() { if !errors.is_empty() {
return Err(errors); return Err(errors);
} }
debug!("fully_normalize: select_all_or_error complete"); debug!("select_all_or_error complete");
let resolved_value = infcx.resolve_vars_if_possible(normalized_value); let resolved_value = infcx.resolve_vars_if_possible(normalized_value);
debug!("fully_normalize: resolved_value={:?}", resolved_value); debug!(?resolved_value);
Ok(resolved_value) Ok(resolved_value)
} }