use query boilerplate for normalize
This commit is contained in:
parent
2fd8a312d9
commit
fa71af4192
1 changed files with 16 additions and 20 deletions
|
|
@ -9,60 +9,56 @@
|
|||
// except according to those terms.
|
||||
|
||||
use rustc::infer::canonical::{Canonical, QueryResult};
|
||||
use rustc::infer::InferCtxt;
|
||||
use rustc::infer::{InferCtxt, InferOk};
|
||||
use rustc::traits::query::type_op::normalize::Normalize;
|
||||
use rustc::traits::query::NoSolution;
|
||||
use rustc::traits::{FulfillmentContext, Normalized, ObligationCause};
|
||||
use rustc::traits::query::{Fallible, NoSolution};
|
||||
use rustc::traits::{Normalized, ObligationCause};
|
||||
use rustc::ty::{FnSig, Lift, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use std::fmt;
|
||||
use syntax::codemap::DUMMY_SP;
|
||||
|
||||
fn type_op_normalize<'gcx, 'tcx, T>(
|
||||
fn type_op_normalize<T>(
|
||||
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
||||
canonicalized: Canonical<'tcx, Normalize<'tcx, T>>,
|
||||
) -> Result<Lrc<Canonical<'gcx, QueryResult<'gcx, <T as Lift<'gcx>>::Lifted>>>, NoSolution>
|
||||
key: Normalize<'tcx, T>,
|
||||
) -> Fallible<InferOk<'tcx, T>>
|
||||
where
|
||||
T: fmt::Debug + TypeFoldable<'tcx> + Lift<'gcx>,
|
||||
{
|
||||
let (Normalize { param_env, value }, canonical_inference_vars) =
|
||||
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonicalized);
|
||||
let fulfill_cx = &mut FulfillmentContext::new();
|
||||
let Normalize { param_env, value } = key;
|
||||
let Normalized { value, obligations } = infcx
|
||||
.at(&ObligationCause::dummy(), param_env)
|
||||
.normalize(&value)?;
|
||||
fulfill_cx.register_predicate_obligations(infcx, obligations);
|
||||
infcx.make_canonicalized_query_result(canonical_inference_vars, value, fulfill_cx)
|
||||
Ok(InferOk { value, obligations }) // ugh we should merge these two structs
|
||||
}
|
||||
|
||||
crate fn type_op_normalize_ty<'tcx>(
|
||||
crate fn type_op_normalize_ty(
|
||||
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||
canonicalized: Canonical<'tcx, Normalize<'tcx, Ty<'tcx>>>,
|
||||
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, Ty<'tcx>>>>, NoSolution> {
|
||||
tcx.infer_ctxt()
|
||||
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
|
||||
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
|
||||
}
|
||||
|
||||
crate fn type_op_normalize_predicate<'tcx>(
|
||||
crate fn type_op_normalize_predicate(
|
||||
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||
canonicalized: Canonical<'tcx, Normalize<'tcx, Predicate<'tcx>>>,
|
||||
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, Predicate<'tcx>>>>, NoSolution> {
|
||||
tcx.infer_ctxt()
|
||||
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
|
||||
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
|
||||
}
|
||||
|
||||
crate fn type_op_normalize_fn_sig<'tcx>(
|
||||
crate fn type_op_normalize_fn_sig(
|
||||
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||
canonicalized: Canonical<'tcx, Normalize<'tcx, FnSig<'tcx>>>,
|
||||
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, FnSig<'tcx>>>>, NoSolution> {
|
||||
tcx.infer_ctxt()
|
||||
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
|
||||
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
|
||||
}
|
||||
|
||||
crate fn type_op_normalize_poly_fn_sig<'tcx>(
|
||||
crate fn type_op_normalize_poly_fn_sig(
|
||||
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||
canonicalized: Canonical<'tcx, Normalize<'tcx, PolyFnSig<'tcx>>>,
|
||||
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, PolyFnSig<'tcx>>>>, NoSolution> {
|
||||
tcx.infer_ctxt()
|
||||
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
|
||||
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue