From fa71af419207fbd0169f1e2d36abcfaf3bc4fab2 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 27 Jun 2018 06:48:43 -0400 Subject: [PATCH] use query boilerplate for `normalize` --- src/librustc_traits/type_op_normalize.rs | 36 +++++++++++------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/librustc_traits/type_op_normalize.rs b/src/librustc_traits/type_op_normalize.rs index edfe627b15a3..78e8a0ff3e69 100644 --- a/src/librustc_traits/type_op_normalize.rs +++ b/src/librustc_traits/type_op_normalize.rs @@ -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( infcx: &InferCtxt<'_, 'gcx, 'tcx>, - canonicalized: Canonical<'tcx, Normalize<'tcx, T>>, -) -> Result>::Lifted>>>, NoSolution> + key: Normalize<'tcx, T>, +) -> Fallible> 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>>>, 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>>>, 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>>>, 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>>>, NoSolution> { tcx.infer_ctxt() - .enter(|ref infcx| type_op_normalize(infcx, canonicalized)) + .enter_canonical_trait_query(&canonicalized, type_op_normalize) }