Skip to content

Commit 66c8839

Browse files
committed
use query boiler plate for normalize_projection_ty too
1 parent e6c8c63 commit 66c8839

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

src/librustc_traits/normalize_projection_ty.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,49 @@
99
// except according to those terms.
1010

1111
use rustc::infer::canonical::{Canonical, QueryResult};
12-
use rustc::traits::{self, FulfillmentContext, ObligationCause, SelectionContext};
13-
use rustc::traits::query::{CanonicalProjectionGoal, NoSolution, normalize::NormalizationResult};
12+
use rustc::infer::InferOk;
13+
use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution};
14+
use rustc::traits::{self, ObligationCause, SelectionContext};
1415
use rustc::ty::{ParamEnvAnd, TyCtxt};
1516
use rustc_data_structures::sync::Lrc;
17+
use std::sync::atomic::Ordering;
1618
use syntax::ast::DUMMY_NODE_ID;
1719
use syntax_pos::DUMMY_SP;
18-
use std::sync::atomic::Ordering;
1920

2021
crate fn normalize_projection_ty<'tcx>(
2122
tcx: TyCtxt<'_, 'tcx, 'tcx>,
2223
goal: CanonicalProjectionGoal<'tcx>,
2324
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
2425
debug!("normalize_provider(goal={:#?})", goal);
2526

26-
tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed);
27-
tcx.infer_ctxt().enter(|ref infcx| {
28-
let (
29-
ParamEnvAnd {
27+
tcx.sess
28+
.perf_stats
29+
.normalize_projection_ty
30+
.fetch_add(1, Ordering::Relaxed);
31+
tcx.infer_ctxt().enter_canonical_trait_query(
32+
&goal,
33+
|infcx,
34+
ParamEnvAnd {
35+
param_env,
36+
value: goal,
37+
}| {
38+
let selcx = &mut SelectionContext::new(infcx);
39+
let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
40+
let mut obligations = vec![];
41+
let answer = traits::normalize_projection_type(
42+
selcx,
3043
param_env,
31-
value: goal,
32-
},
33-
canonical_inference_vars,
34-
) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &goal);
35-
let fulfill_cx = &mut FulfillmentContext::new();
36-
let selcx = &mut SelectionContext::new(infcx);
37-
let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
38-
let mut obligations = vec![];
39-
let answer =
40-
traits::normalize_projection_type(selcx, param_env, goal, cause, 0, &mut obligations);
41-
fulfill_cx.register_predicate_obligations(infcx, obligations);
42-
43-
// Now that we have fulfilled as much as we can, create a solution
44-
// from what we've learned.
45-
infcx.make_canonicalized_query_result(
46-
canonical_inference_vars,
47-
NormalizationResult { normalized_ty: answer },
48-
fulfill_cx,
49-
)
50-
})
44+
goal,
45+
cause,
46+
0,
47+
&mut obligations,
48+
);
49+
Ok(InferOk {
50+
value: NormalizationResult {
51+
normalized_ty: answer,
52+
},
53+
obligations,
54+
})
55+
},
56+
)
5157
}

0 commit comments

Comments
 (0)