1 use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
3 use crate::traits::query::Fallible;
4 use crate::ty::fold::TypeFoldable;
5 use crate::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt};
7 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
8 pub struct Normalize<T> {
12 impl<'tcx, T> Normalize<T>
14 T: fmt::Debug + TypeFoldable<'tcx>,
16 pub fn new(value: T) -> Self {
21 impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
23 T: Normalizable<'tcx> + 'tcx,
25 type QueryResponse = T;
27 fn try_fast_path(_tcx: TyCtxt<'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<T> {
28 if !key.value.value.has_projections() {
37 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
38 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
39 T::type_op_method(tcx, canonicalized)
42 fn shrink_to_tcx_lifetime(
43 v: &'a CanonicalizedQueryResponse<'tcx, T>,
44 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, T>> {
45 T::shrink_to_tcx_lifetime(v)
49 pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'tcx> + Copy {
52 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
53 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>>;
55 /// Converts from the `'tcx` (lifted) form of `Self` into the `tcx`
57 fn shrink_to_tcx_lifetime(
58 v: &'a CanonicalizedQueryResponse<'tcx, Self>,
59 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>>;
62 impl Normalizable<'tcx> for Ty<'tcx> {
65 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
66 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
67 tcx.type_op_normalize_ty(canonicalized)
70 fn shrink_to_tcx_lifetime(
71 v: &'a CanonicalizedQueryResponse<'tcx, Self>,
72 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
77 impl Normalizable<'tcx> for ty::Predicate<'tcx> {
80 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
81 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
82 tcx.type_op_normalize_predicate(canonicalized)
85 fn shrink_to_tcx_lifetime(
86 v: &'a CanonicalizedQueryResponse<'tcx, Self>,
87 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
92 impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
95 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
96 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
97 tcx.type_op_normalize_poly_fn_sig(canonicalized)
100 fn shrink_to_tcx_lifetime(
101 v: &'a CanonicalizedQueryResponse<'tcx, Self>,
102 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
107 impl Normalizable<'tcx> for ty::FnSig<'tcx> {
110 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
111 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
112 tcx.type_op_normalize_fn_sig(canonicalized)
115 fn shrink_to_tcx_lifetime(
116 v: &'a CanonicalizedQueryResponse<'tcx, Self>,
117 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
122 BraceStructTypeFoldableImpl! {
123 impl<'tcx, T> TypeFoldable<'tcx> for Normalize<T> {
125 } where T: TypeFoldable<'tcx>,
128 BraceStructLiftImpl! {
129 impl<'tcx, T> Lift<'tcx> for Normalize<T> {
130 type Lifted = Normalize<T::Lifted>;
132 } where T: Lift<'tcx>,
135 impl_stable_hash_for! {
136 impl<T> for struct Normalize<T> {