about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-01 12:15:10 +0000
committerbors <bors@rust-lang.org>2022-11-01 12:15:10 +0000
commite70cbef0c5db81079f4b5643380d6047ccd34a10 (patch)
tree6123ac4c7d8880a04e10a9e75f291b19001caa3c /compiler/rustc_borrowck/src
parentc493bae0d8efd75723460ce5c371f726efa93f15 (diff)
parent2f9794b84a4ae882edd428c1c3764eec99cdebff (diff)
downloadrust-e70cbef0c5db81079f4b5643380d6047ccd34a10.tar.gz
rust-e70cbef0c5db81079f4b5643380d6047ccd34a10.zip
Auto merge of #103590 - compiler-errors:ocx-more, r=lcnr
(almost) Always use `ObligationCtxt` when dealing with canonical queries

Hope this is a step in the right direction. cc rust-lang/types-team#50.

r? `@lcnr`
Diffstat (limited to 'compiler/rustc_borrowck/src')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs41
1 files changed, 18 insertions, 23 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
index 02071ed6b36..dac6abe37f5 100644
--- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
@@ -5,14 +5,14 @@ use rustc_infer::infer::region_constraints::Constraint;
 use rustc_infer::infer::region_constraints::RegionConstraintData;
 use rustc_infer::infer::RegionVariableOrigin;
 use rustc_infer::infer::{InferCtxt, RegionResolutionError, SubregionOrigin, TyCtxtInferExt as _};
-use rustc_infer::traits::{Normalized, ObligationCause, TraitEngine, TraitEngineExt};
+use rustc_infer::traits::ObligationCause;
 use rustc_middle::ty::error::TypeError;
 use rustc_middle::ty::RegionVid;
 use rustc_middle::ty::UniverseIndex;
 use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
 use rustc_span::Span;
 use rustc_trait_selection::traits::query::type_op;
-use rustc_trait_selection::traits::{SelectionContext, TraitEngineExt as _};
+use rustc_trait_selection::traits::ObligationCtxt;
 use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause};
 
 use std::fmt;
@@ -240,9 +240,9 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
     ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
         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)
+        let ocx = ObligationCtxt::new(infcx);
+        type_op_prove_predicate_with_cause(&ocx, key, cause);
+        try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
     }
 }
 
@@ -281,9 +281,7 @@ where
     ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
         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);
+        let ocx = ObligationCtxt::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
@@ -292,11 +290,9 @@ where
         // 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);
+        let _ = ocx.normalize(cause, param_env, value.value);
 
-        try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
+        try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
     }
 }
 
@@ -329,9 +325,9 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
     ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
         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)
+        let ocx = ObligationCtxt::new(infcx);
+        type_op_ascribe_user_type_with_span(&ocx, key, Some(cause.span)).ok()?;
+        try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
     }
 }
 
@@ -372,25 +368,24 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
     }
 }
 
-#[instrument(skip(fulfill_cx, infcx), level = "debug")]
+#[instrument(skip(ocx), level = "debug")]
 fn try_extract_error_from_fulfill_cx<'tcx>(
-    mut fulfill_cx: Box<dyn TraitEngine<'tcx> + 'tcx>,
-    infcx: &InferCtxt<'tcx>,
+    ocx: &ObligationCtxt<'_, 'tcx>,
     placeholder_region: ty::Region<'tcx>,
     error_region: Option<ty::Region<'tcx>>,
 ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
     // We generally shouldn't have errors here because the query was
     // already run, but there's no point using `delay_span_bug`
     // when we're going to emit an error here anyway.
-    let _errors = fulfill_cx.select_all_or_error(infcx);
-    let region_constraints = infcx.with_region_constraints(|r| r.clone());
+    let _errors = ocx.select_all_or_error();
+    let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone());
     try_extract_error_from_region_constraints(
-        infcx,
+        ocx.infcx,
         placeholder_region,
         error_region,
         &region_constraints,
-        |vid| infcx.region_var_origin(vid),
-        |vid| infcx.universe_of_region(infcx.tcx.mk_region(ty::ReVar(vid))),
+        |vid| ocx.infcx.region_var_origin(vid),
+        |vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_region(ty::ReVar(vid))),
     )
 }