diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-06-27 06:47:55 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-06-27 06:49:43 -0400 |
| commit | 66c88392b4594507b8b0282d8a3de5f43922acc4 (patch) | |
| tree | 31ea09df206fce23fb45e26ece5c137e4a3943ca | |
| parent | e6c8c632b73962184e5cc33106e54de95dcec8ae (diff) | |
| download | rust-66c88392b4594507b8b0282d8a3de5f43922acc4.tar.gz rust-66c88392b4594507b8b0282d8a3de5f43922acc4.zip | |
use query boiler plate for `normalize_projection_ty` too
| -rw-r--r-- | src/librustc_traits/normalize_projection_ty.rs | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/librustc_traits/normalize_projection_ty.rs b/src/librustc_traits/normalize_projection_ty.rs index a9c4fef9f7d..473b2c8e998 100644 --- a/src/librustc_traits/normalize_projection_ty.rs +++ b/src/librustc_traits/normalize_projection_ty.rs @@ -9,13 +9,14 @@ // except according to those terms. use rustc::infer::canonical::{Canonical, QueryResult}; -use rustc::traits::{self, FulfillmentContext, ObligationCause, SelectionContext}; -use rustc::traits::query::{CanonicalProjectionGoal, NoSolution, normalize::NormalizationResult}; +use rustc::infer::InferOk; +use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution}; +use rustc::traits::{self, ObligationCause, SelectionContext}; use rustc::ty::{ParamEnvAnd, TyCtxt}; use rustc_data_structures::sync::Lrc; +use std::sync::atomic::Ordering; use syntax::ast::DUMMY_NODE_ID; use syntax_pos::DUMMY_SP; -use std::sync::atomic::Ordering; crate fn normalize_projection_ty<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, @@ -23,29 +24,34 @@ crate fn normalize_projection_ty<'tcx>( ) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, NormalizationResult<'tcx>>>>, NoSolution> { debug!("normalize_provider(goal={:#?})", goal); - tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed); - tcx.infer_ctxt().enter(|ref infcx| { - let ( - ParamEnvAnd { + tcx.sess + .perf_stats + .normalize_projection_ty + .fetch_add(1, Ordering::Relaxed); + tcx.infer_ctxt().enter_canonical_trait_query( + &goal, + |infcx, + ParamEnvAnd { + param_env, + value: goal, + }| { + let selcx = &mut SelectionContext::new(infcx); + let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID); + let mut obligations = vec![]; + let answer = traits::normalize_projection_type( + selcx, param_env, - value: goal, - }, - canonical_inference_vars, - ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &goal); - let fulfill_cx = &mut FulfillmentContext::new(); - let selcx = &mut SelectionContext::new(infcx); - let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID); - let mut obligations = vec![]; - let answer = - traits::normalize_projection_type(selcx, param_env, goal, cause, 0, &mut obligations); - fulfill_cx.register_predicate_obligations(infcx, obligations); - - // Now that we have fulfilled as much as we can, create a solution - // from what we've learned. - infcx.make_canonicalized_query_result( - canonical_inference_vars, - NormalizationResult { normalized_ty: answer }, - fulfill_cx, - ) - }) + goal, + cause, + 0, + &mut obligations, + ); + Ok(InferOk { + value: NormalizationResult { + normalized_ty: answer, + }, + obligations, + }) + }, + ) } |
