Skip to content

Commit fa71af4

Browse files
committed
use query boilerplate for normalize
1 parent 2fd8a31 commit fa71af4

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/librustc_traits/type_op_normalize.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,56 @@
99
// except according to those terms.
1010

1111
use rustc::infer::canonical::{Canonical, QueryResult};
12-
use rustc::infer::InferCtxt;
12+
use rustc::infer::{InferCtxt, InferOk};
1313
use rustc::traits::query::type_op::normalize::Normalize;
14-
use rustc::traits::query::NoSolution;
15-
use rustc::traits::{FulfillmentContext, Normalized, ObligationCause};
14+
use rustc::traits::query::{Fallible, NoSolution};
15+
use rustc::traits::{Normalized, ObligationCause};
1616
use rustc::ty::{FnSig, Lift, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable};
1717
use rustc_data_structures::sync::Lrc;
1818
use std::fmt;
19-
use syntax::codemap::DUMMY_SP;
2019

21-
fn type_op_normalize<'gcx, 'tcx, T>(
20+
fn type_op_normalize<T>(
2221
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
23-
canonicalized: Canonical<'tcx, Normalize<'tcx, T>>,
24-
) -> Result<Lrc<Canonical<'gcx, QueryResult<'gcx, <T as Lift<'gcx>>::Lifted>>>, NoSolution>
22+
key: Normalize<'tcx, T>,
23+
) -> Fallible<InferOk<'tcx, T>>
2524
where
2625
T: fmt::Debug + TypeFoldable<'tcx> + Lift<'gcx>,
2726
{
28-
let (Normalize { param_env, value }, canonical_inference_vars) =
29-
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonicalized);
30-
let fulfill_cx = &mut FulfillmentContext::new();
27+
let Normalize { param_env, value } = key;
3128
let Normalized { value, obligations } = infcx
3229
.at(&ObligationCause::dummy(), param_env)
3330
.normalize(&value)?;
34-
fulfill_cx.register_predicate_obligations(infcx, obligations);
35-
infcx.make_canonicalized_query_result(canonical_inference_vars, value, fulfill_cx)
31+
Ok(InferOk { value, obligations }) // ugh we should merge these two structs
3632
}
3733

38-
crate fn type_op_normalize_ty<'tcx>(
34+
crate fn type_op_normalize_ty(
3935
tcx: TyCtxt<'_, 'tcx, 'tcx>,
4036
canonicalized: Canonical<'tcx, Normalize<'tcx, Ty<'tcx>>>,
4137
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, Ty<'tcx>>>>, NoSolution> {
4238
tcx.infer_ctxt()
43-
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
39+
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
4440
}
4541

46-
crate fn type_op_normalize_predicate<'tcx>(
42+
crate fn type_op_normalize_predicate(
4743
tcx: TyCtxt<'_, 'tcx, 'tcx>,
4844
canonicalized: Canonical<'tcx, Normalize<'tcx, Predicate<'tcx>>>,
4945
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, Predicate<'tcx>>>>, NoSolution> {
5046
tcx.infer_ctxt()
51-
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
47+
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
5248
}
5349

54-
crate fn type_op_normalize_fn_sig<'tcx>(
50+
crate fn type_op_normalize_fn_sig(
5551
tcx: TyCtxt<'_, 'tcx, 'tcx>,
5652
canonicalized: Canonical<'tcx, Normalize<'tcx, FnSig<'tcx>>>,
5753
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, FnSig<'tcx>>>>, NoSolution> {
5854
tcx.infer_ctxt()
59-
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
55+
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
6056
}
6157

62-
crate fn type_op_normalize_poly_fn_sig<'tcx>(
58+
crate fn type_op_normalize_poly_fn_sig(
6359
tcx: TyCtxt<'_, 'tcx, 'tcx>,
6460
canonicalized: Canonical<'tcx, Normalize<'tcx, PolyFnSig<'tcx>>>,
6561
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, PolyFnSig<'tcx>>>>, NoSolution> {
6662
tcx.infer_ctxt()
67-
.enter(|ref infcx| type_op_normalize(infcx, canonicalized))
63+
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
6864
}

0 commit comments

Comments
 (0)