1 use rustc_infer::infer::at::ToTrace;
2 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3 use rustc_infer::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
4 use rustc_infer::traits::query::NoSolution;
5 use rustc_infer::traits::ObligationCause;
6 use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
7 use rustc_middle::ty::{self, Ty, TypeFoldable};
8 use rustc_span::DUMMY_SP;
12 /// Methods used inside of the canonical queries of the solver.
14 /// Most notably these do not care about diagnostics information.
15 /// If you find this while looking for methods to use outside of the
16 /// solver, you may look at the implementation of these method for
18 pub(super) trait InferCtxtExt<'tcx> {
19 fn next_ty_infer(&self) -> Ty<'tcx>;
20 fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx>;
22 fn eq<T: ToTrace<'tcx>>(
24 param_env: ty::ParamEnv<'tcx>,
27 ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
29 fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
31 value: ty::Binder<'tcx, T>,
35 impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
36 fn next_ty_infer(&self) -> Ty<'tcx> {
37 self.next_ty_var(TypeVariableOrigin {
38 kind: TypeVariableOriginKind::MiscVariable,
42 fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
45 ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span: DUMMY_SP },
49 #[instrument(level = "debug", skip(self, param_env), ret)]
50 fn eq<T: ToTrace<'tcx>>(
52 param_env: ty::ParamEnv<'tcx>,
55 ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
56 self.at(&ObligationCause::dummy(), param_env)
57 .define_opaque_types(false)
59 .map(|InferOk { value: (), obligations }| {
60 obligations.into_iter().map(|o| o.into()).collect()
63 debug!(?e, "failed to equate");
68 fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
70 value: ty::Binder<'tcx, T>,
72 self.replace_bound_vars_with_fresh_vars(
74 LateBoundRegionConversionTime::HigherRankedType,