about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/solve/infcx_ext.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-24 09:41:11 +0000
committerbors <bors@rust-lang.org>2022-12-24 09:41:11 +0000
commitd23554fae855d884761d549cd6ee6537450b0f3c (patch)
treeb44bd3e79fa5019f0e8648737e71c432bc784188 /compiler/rustc_trait_selection/src/solve/infcx_ext.rs
parent245357f61939d2b6d15f8c6b15f7026396f95871 (diff)
parente52e0d855799fe651922be4a038fe84fe9009c72 (diff)
downloadrust-d23554fae855d884761d549cd6ee6537450b0f3c.tar.gz
rust-d23554fae855d884761d549cd6ee6537450b0f3c.zip
Auto merge of #2738 - RalfJung:rustup, r=RalfJung
Rustup
Diffstat (limited to 'compiler/rustc_trait_selection/src/solve/infcx_ext.rs')
-rw-r--r--compiler/rustc_trait_selection/src/solve/infcx_ext.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/infcx_ext.rs b/compiler/rustc_trait_selection/src/solve/infcx_ext.rs
new file mode 100644
index 00000000000..436f4eea662
--- /dev/null
+++ b/compiler/rustc_trait_selection/src/solve/infcx_ext.rs
@@ -0,0 +1,55 @@
+use rustc_infer::infer::canonical::CanonicalVarValues;
+use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
+use rustc_infer::infer::InferCtxt;
+use rustc_infer::traits::query::NoSolution;
+use rustc_middle::ty::Ty;
+use rustc_span::DUMMY_SP;
+
+use crate::solve::ExternalConstraints;
+
+use super::{Certainty, QueryResult, Response};
+
+/// Methods used inside of the canonical queries of the solver.
+pub(super) trait InferCtxtExt<'tcx> {
+    fn next_ty_infer(&self) -> Ty<'tcx>;
+
+    fn make_canonical_response(
+        &self,
+        var_values: CanonicalVarValues<'tcx>,
+        certainty: Certainty,
+    ) -> QueryResult<'tcx>;
+}
+
+impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
+    fn next_ty_infer(&self) -> Ty<'tcx> {
+        self.next_ty_var(TypeVariableOrigin {
+            kind: TypeVariableOriginKind::MiscVariable,
+            span: DUMMY_SP,
+        })
+    }
+
+    fn make_canonical_response(
+        &self,
+        var_values: CanonicalVarValues<'tcx>,
+        certainty: Certainty,
+    ) -> QueryResult<'tcx> {
+        let external_constraints = take_external_constraints(self)?;
+
+        Ok(self.canonicalize_response(Response { var_values, external_constraints, certainty }))
+    }
+}
+
+#[instrument(level = "debug", skip(infcx), ret)]
+fn take_external_constraints<'tcx>(
+    infcx: &InferCtxt<'tcx>,
+) -> Result<ExternalConstraints<'tcx>, NoSolution> {
+    let region_obligations = infcx.take_registered_region_obligations();
+    let opaque_types = infcx.take_opaque_types_for_query_response();
+    Ok(ExternalConstraints {
+        // FIXME: Now that's definitely wrong :)
+        //
+        // Should also do the leak check here I think
+        regions: drop(region_obligations),
+        opaque_types,
+    })
+}