]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_trait_selection/src/solve/infcx_ext.rs
Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcm
[rust.git] / compiler / rustc_trait_selection / src / solve / infcx_ext.rs
1 use rustc_infer::infer::canonical::CanonicalVarValues;
2 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3 use rustc_infer::infer::InferCtxt;
4 use rustc_infer::traits::query::NoSolution;
5 use rustc_middle::ty::Ty;
6 use rustc_span::DUMMY_SP;
7
8 use crate::solve::ExternalConstraints;
9
10 use super::{Certainty, QueryResult, Response};
11
12 /// Methods used inside of the canonical queries of the solver.
13 pub(super) trait InferCtxtExt<'tcx> {
14     fn next_ty_infer(&self) -> Ty<'tcx>;
15
16     fn make_canonical_response(
17         &self,
18         var_values: CanonicalVarValues<'tcx>,
19         certainty: Certainty,
20     ) -> QueryResult<'tcx>;
21 }
22
23 impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
24     fn next_ty_infer(&self) -> Ty<'tcx> {
25         self.next_ty_var(TypeVariableOrigin {
26             kind: TypeVariableOriginKind::MiscVariable,
27             span: DUMMY_SP,
28         })
29     }
30
31     fn make_canonical_response(
32         &self,
33         var_values: CanonicalVarValues<'tcx>,
34         certainty: Certainty,
35     ) -> QueryResult<'tcx> {
36         let external_constraints = take_external_constraints(self)?;
37
38         Ok(self.canonicalize_response(Response { var_values, external_constraints, certainty }))
39     }
40 }
41
42 #[instrument(level = "debug", skip(infcx), ret)]
43 fn take_external_constraints<'tcx>(
44     infcx: &InferCtxt<'tcx>,
45 ) -> Result<ExternalConstraints<'tcx>, NoSolution> {
46     let region_obligations = infcx.take_registered_region_obligations();
47     let opaque_types = infcx.take_opaque_types_for_query_response();
48     Ok(ExternalConstraints {
49         // FIXME: Now that's definitely wrong :)
50         //
51         // Should also do the leak check here I think
52         regions: drop(region_obligations),
53         opaque_types,
54     })
55 }