]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
Change InferCtxtBuilder from enter to build
[rust.git] / compiler / rustc_borrowck / src / diagnostics / bound_region_errors.rs
index fc79953c2dd311888769c056639c1123705e9b30..02071ed6b36662975346651590ec08d5e74fb17a 100644 (file)
@@ -238,20 +238,11 @@ fn nice_error(
         placeholder_region: ty::Region<'tcx>,
         error_region: Option<ty::Region<'tcx>>,
     ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
-        mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
-            cause.span,
-            &self.canonical_query,
-            |ref infcx, key, _| {
-                let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
-                type_op_prove_predicate_with_cause(infcx, &mut *fulfill_cx, key, cause);
-                try_extract_error_from_fulfill_cx(
-                    fulfill_cx,
-                    infcx,
-                    placeholder_region,
-                    error_region,
-                )
-            },
-        )
+        let (ref infcx, key, _) =
+            mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
+        let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
+        type_op_prove_predicate_with_cause(infcx, &mut *fulfill_cx, key, cause);
+        try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
     }
 }
 
@@ -288,37 +279,24 @@ fn nice_error(
         placeholder_region: ty::Region<'tcx>,
         error_region: Option<ty::Region<'tcx>>,
     ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
-        mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
-            cause.span,
-            &self.canonical_query,
-            |ref infcx, key, _| {
-                let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
-
-                let mut selcx = SelectionContext::new(infcx);
-
-                // FIXME(lqd): Unify and de-duplicate the following with the actual
-                // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
-                // `ObligationCause`. The normalization results are currently different between
-                // `AtExt::normalize` used in the query and `normalize` called below: the former fails
-                // to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
-                // after #85499 lands to see if its fixes have erased this difference.
-                let (param_env, value) = key.into_parts();
-                let Normalized { value: _, obligations } = rustc_trait_selection::traits::normalize(
-                    &mut selcx,
-                    param_env,
-                    cause,
-                    value.value,
-                );
-                fulfill_cx.register_predicate_obligations(infcx, obligations);
-
-                try_extract_error_from_fulfill_cx(
-                    fulfill_cx,
-                    infcx,
-                    placeholder_region,
-                    error_region,
-                )
-            },
-        )
+        let (ref infcx, key, _) =
+            mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
+        let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
+
+        let mut selcx = SelectionContext::new(infcx);
+
+        // FIXME(lqd): Unify and de-duplicate the following with the actual
+        // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
+        // `ObligationCause`. The normalization results are currently different between
+        // `AtExt::normalize` used in the query and `normalize` called below: the former fails
+        // to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
+        // after #85499 lands to see if its fixes have erased this difference.
+        let (param_env, value) = key.into_parts();
+        let Normalized { value: _, obligations } =
+            rustc_trait_selection::traits::normalize(&mut selcx, param_env, cause, value.value);
+        fulfill_cx.register_predicate_obligations(infcx, obligations);
+
+        try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
     }
 }
 
@@ -349,21 +327,11 @@ fn nice_error(
         placeholder_region: ty::Region<'tcx>,
         error_region: Option<ty::Region<'tcx>>,
     ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
-        mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
-            cause.span,
-            &self.canonical_query,
-            |ref infcx, key, _| {
-                let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
-                type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(cause.span))
-                    .ok()?;
-                try_extract_error_from_fulfill_cx(
-                    fulfill_cx,
-                    infcx,
-                    placeholder_region,
-                    error_region,
-                )
-            },
-        )
+        let (ref infcx, key, _) =
+            mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
+        let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
+        type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(cause.span)).ok()?;
+        try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
     }
 }